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 * @since 2.1.0 034 */ 035public enum GrammaticalCase implements LanguageForm { 036 /** 037 * Citation or subject form. 038 */ 039 NOMINATIVE, 040 /** 041 * Direct object form. 042 */ 043 ACCUSATIVE, 044 /** 045 * Possessive, source, or partitive-adjacent form. 046 */ 047 GENITIVE, 048 /** 049 * Indirect object or recipient form. 050 */ 051 DATIVE, 052 /** 053 * Instrument or accompaniment form. 054 */ 055 INSTRUMENTAL, 056 /** 057 * Location or place form. 058 */ 059 LOCATIVE, 060 /** 061 * Preposition-governed form used in languages such as Russian. 062 */ 063 PREPOSITIONAL, 064 /** 065 * Direct address form. 066 */ 067 VOCATIVE, 068 /** 069 * Source, motion-away-from, or separation form. 070 */ 071 ABLATIVE; 072 073 @NonNull 074 private static final Map<@NonNull String, @NonNull GrammaticalCase> GRAMMATICAL_CASES_BY_NAME; 075 076 static { 077 GRAMMATICAL_CASES_BY_NAME = Collections.unmodifiableMap(Arrays.stream( 078 GrammaticalCase.values()).collect(Collectors.toMap(grammaticalCase -> grammaticalCase.name(), grammaticalCase -> grammaticalCase))); 079 } 080 081 /** 082 * Gets the mapping of grammatical case names to grammatical case values. 083 * 084 * @return the mapping of grammatical case names to grammatical case values, not null 085 */ 086 @NonNull 087 static Map<@NonNull String, @NonNull GrammaticalCase> getGrammaticalCasesByName() { 088 return GRAMMATICAL_CASES_BY_NAME; 089 } 090}