001/*
002 * Copyright 2017-2022 Product Mog LLC, 2022-2026 Revetware LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.lokalized;
018
019import org.jspecify.annotations.NonNull;
020
021import java.util.Arrays;
022import java.util.Collections;
023import java.util.Map;
024import java.util.stream.Collectors;
025
026/**
027 * Grammatical case forms.
028 * <p>
029 * This enum intentionally models a high-coverage set of cases that appear across many language families.
030 * Languages with more specialized case inventories can map to the closest matching value.
031 *
032 * @author <a href="https://revetkn.com">Mark Allen</a>
033 */
034public enum GrammaticalCase implements LanguageForm {
035  /**
036   * Citation or subject form.
037   */
038  NOMINATIVE,
039  /**
040   * Direct object form.
041   */
042  ACCUSATIVE,
043  /**
044   * Possessive, source, or partitive-adjacent form.
045   */
046  GENITIVE,
047  /**
048   * Indirect object or recipient form.
049   */
050  DATIVE,
051  /**
052   * Instrument or accompaniment form.
053   */
054  INSTRUMENTAL,
055  /**
056   * Location or place form.
057   */
058  LOCATIVE,
059  /**
060   * Preposition-governed form used in languages such as Russian.
061   */
062  PREPOSITIONAL,
063  /**
064   * Direct address form.
065   */
066  VOCATIVE,
067  /**
068   * Source, motion-away-from, or separation form.
069   */
070  ABLATIVE;
071
072  @NonNull
073  private static final Map<@NonNull String, @NonNull GrammaticalCase> GRAMMATICAL_CASES_BY_NAME;
074
075  static {
076    GRAMMATICAL_CASES_BY_NAME = Collections.unmodifiableMap(Arrays.stream(
077        GrammaticalCase.values()).collect(Collectors.toMap(grammaticalCase -> grammaticalCase.name(), grammaticalCase -> grammaticalCase)));
078  }
079
080  /**
081   * Gets the mapping of grammatical case names to grammatical case values.
082   *
083   * @return the mapping of grammatical case names to grammatical case values, not null
084   */
085  @NonNull
086  static Map<@NonNull String, @NonNull GrammaticalCase> getGrammaticalCasesByName() {
087    return GRAMMATICAL_CASES_BY_NAME;
088  }
089}