Continents.java

/*
 * Copyright © 2012-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.mirrors;

import java.util.Locale;
import java.util.ResourceBundle;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * This domain class represents a continent.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
@Entity
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Continents {

    /**
     * The field <code>bundleDe</code> contains the translation to German.
     */
    static ResourceBundle bundleDe =
        ResourceBundle.getBundle("org.ctan.site.domain.mirrors.Continents",
            Locale.GERMAN);

    /**
     * The field <code>id</code> contains the id.
     */
    @Id
    @GeneratedValue
    private Long id;

    /**
     * The field <code>name</code> contains the name of the continent in
     * English.
     */
    @Column(length = 255, nullable = false)
    private String name;

    /**
     * The method <code>toString</code> provides means to get a localised String
     * representation.
     *
     * @param locale the 2-letter language code
     * @return the name
     */
    public String getName(String locale) {

        if ("de".equals(locale)) {
            return bundleDe.getString(Long.toString(id));
        }
        return name;
    }

    /**
     * {@inheritDoc}
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {

        return name;
    }
}