Gender.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */

package org.ctan.site.domain;

import lombok.Getter;

/**
 * The class <code>Gender</code> contains the enumeration for the gender values.
 */
public enum Gender {

    /**
     * The indicator for a woman.
     */
    F("f"),
    /**
     * The indicator for a man.
     */
    M("m"),
    /**
     * The indicator for a group.
     */
    G("g"),
    /**
     * The indicator for a group.
     */
    X("x");

    /**
     * The method <code>of</code> provides means to translate a single letter
     * into a gender value.
     *
     * @param s the value
     * @return the gender
     * @throws IllegalArgumentException in case of another string value
     */
    public static Gender of(String s) {

        return switch (s) {
            case null -> Gender.X;
            case "f", "F" -> Gender.F;
            case "m", "M" -> Gender.M;
            case "g", "G" -> Gender.G;
            case "x", "X" -> Gender.X;
            default -> throw new IllegalArgumentException("not a Gender: " + s);
        };
    }

    /**
     * The field <code>value</code> contains the single letter representation
     * for a gender.
     */
    @Getter
    private String value;

    /**
     * This is the constructor for <code>Gender</code>.
     *
     * @param value the value
     */
    private Gender(String value) {

        this.value = value;
    }

}