001/*
002 * Copyright 2017 Product Mog 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 javax.annotation.Nonnull;
020import java.util.Arrays;
021import java.util.Collections;
022import java.util.Map;
023import java.util.stream.Collectors;
024
025/**
026 * Language gender forms.
027 *
028 * @author <a href="https://revetkn.com">Mark Allen</a>
029 */
030public enum Gender implements LanguageForm {
031  /**
032   * Masculine gender.
033   */
034  MASCULINE,
035  /**
036   * Feminine gender.
037   */
038  FEMININE,
039  /**
040   * Neutral/unspecified gender.
041   */
042  NEUTER;
043
044  @Nonnull
045  private static final Map<String, Gender> GENDERS_BY_NAME;
046
047  static {
048    GENDERS_BY_NAME = Collections.unmodifiableMap(Arrays.stream(
049        Gender.values()).collect(Collectors.toMap(gender -> gender.name(), gender -> gender)));
050  }
051
052  /**
053   * Gets the mapping of gender names to gender values.
054   *
055   * @return the mapping of gender names to gender values, not null
056   */
057  @Nonnull
058  static Map<String, Gender> getGendersByName() {
059    return GENDERS_BY_NAME;
060  }
061}