Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2014 Basis Technology Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//CHECKSTYLE:OFF
/*
* DO NOT EDIT THIS FILE /home/kt/git/rosette-common-java-api/target/checkout/api/target/generated-sources/com/basistech/util/LanguageCode.java
* It has been AutoGen-ed Wed Sep 4 14:12:02 2024
* and the template file /home/kt/git/rosette-common-java-api/target/checkout/api/src/main/templates/LanguageCode.java.tpl
*/
package com.basistech.util;
import java.util.Map;
import java.util.HashMap;
/**
Enumeration for a set of ISO 639-based language codes used in Basis products.
LanguageCodes are based on the Feb 10, 2009 version of ISO 639-3. A LanguageCode is either
standard, meaning that it is based on an ISO 639-3 language code, or nonstandard, meaning that it is a Basis extension.
The nonstandard LanguageCodes are:
{@link #UNKNOWN UNKNOWN}
{@link #SIMPLIFIED_CHINESE SIMPLIFIED_CHINESE}
{@link #TRADITIONAL_CHINESE TRADITIONAL_CHINESE}
{@link #ENGLISH_UPPERCASE ENGLISH_UPPERCASE}
{@link #NORTH_KOREAN NORTH_KOREAN}
{@link #SOUTH_KOREAN SOUTH_KOREAN}
LanguageCodes have the following attributes.
{@linkplain #languageName() Name}:
An ASCII, English name for the language. For standard LanguageCodes, it is based on the ISO 639-3
reference name field; in some cases it is a simplified version of the field. No two LanguageCodes have the
same value of this attribute.
{@linkplain #ISO639_3() ISO 639-3 code}:
For standard LanguageCodes, it is a three-letter ISO 639-3 code. For nonstandard
LanguageCodes, it is a three-letter code different from any ISO 639-3 code. No two
LanguageCodes have the same value of this attribute.
{@linkplain #ISO639_2B() ISO 639-2B code}:
For standard LanguageCodes, it is a three-letter ISO 639-2B code. For nonstandard
LanguageCodes, it is a three-letter code different from any ISO 639-2B code. No two
LanguageCodes have the same value of this attribute. ISO 639-2B codes are the same as
ISO 639-3 codes in most cases; however there are 16 LanguageCodes where they differ:
{@link #ALBANIAN ALBANIAN}
{@link #ARMENIAN ARMENIAN}
{@link #BURMESE BURMESE}
{@link #CHINESE CHINESE}
{@link #CZECH CZECH}
{@link #DUTCH DUTCH}
{@link #FRENCH FRENCH}
{@link #GEORGIAN GEORGIAN}
{@link #GERMAN GERMAN}
{@link #GREEK GREEK}
{@link #ICELANDIC ICELANDIC}
{@link #MACEDONIAN MACEDONIAN}
{@link #MALAY MALAY}
{@link #PERSIAN PERSIAN}
{@link #ROMANIAN ROMANIAN}
{@link #SLOVAK SLOVAK}
{@linkplain #ISO639_1() ISO 639-1 code}:
In the ISO 639-3 specification, all languages have a three-letter code, and some languages also have a two-letter ISO
639-1 code.
For standard LanguageCodes, this attribute is either a two-letter ISO 639-1 code, or {@link
#UNCODED_ISO639_1 UNCODED_ISO639_1} ("zz"), with the exception of {@link #STANDARD_MALAY STANDARD_MALAY},
which uses a nonstandard five-character code. For nonstandard LanguageCodes, this attribute is
either "xx" for {@link #UNKNOWN UNKNOWN}, or a five-letter code of the form ab_cde. Except
for {@link #UNCODED_ISO639_1 UNCODED_ISO639_1}, no two LanguageCodes have the same value of this attribute.
{@linkplain #getDefaultScript() Default script}:
For languages predominantly written in only one script, this attribute is that script. For other languages, it is
{@link ISO15924#Zyyy}. This mapping from languages to scripts is provided by Basis; it does not directly correspond to
any ISO data.
{@linkplain #languageID() Numeric ID}:
A unique integer for each LanguageCode. It is not necessarily the same value as the position of the
LanguageCode in the result of {@link #values() values()}.
*/
ZULU (74, "zul", "zul", "zu", "Zulu", ISO15924.Latn),
;
private int id;
private String iso3;
private String iso2b;
private String iso1;
private String name;
private ISO15924 defaultScript;
LanguageCode(int id, String iso3, String iso2b, String iso1, String name, ISO15924 defaultScript ) {
this.id = id;
this.iso3 = iso3;
this.iso2b = iso2b;
this.iso1 = iso1;
this.name = name;
this.defaultScript = defaultScript;
}
/**
* Returns the numeric ID attribute.
* @return the numeric ID attribute.
*/
public int languageID() {
return id;
}
/**
* Returns the ISO639-1 code attribute.
* @return the ISO639-1 code attribute.
*/
public String ISO639_1() {
return iso1;
}
/**
* Returns the ISO639-2b code attribute.
* @return the ISO639-2b code attribute.
*/
public String ISO639_2B() {
return iso2b;
}
/**
* Returns the ISO639-3 code attribute.
* @return the ISO639-3 code attribute.
*/
public String ISO639_3() {
return iso3;
}
/**
* Returns the default script attribute.
* @return the default script attribute.
*/
public ISO15924 getDefaultScript() {
return defaultScript;
}
/**
* Returns the name attribute.
* @return the name attribute.
*/
public String languageName() {
return name;
}
// "NativeCode" is a convention in com.basistech.jnigen.BeanJNIGenerator.ClassInfo.MethodIDInitialization.
/**
* Get the numeric ID for this language.
* @return the numeric ID for this language.
*/
int getNativeCode() {
return id;
}
static LanguageCode lookupByNativeCode(int nativeCode) {
if (nativeCode < 0 || values().length <= nativeCode)
throw new IllegalArgumentException("Invalid Language ID native code " + nativeCode);
else
return values()[id_index[nativeCode]];
}
/**
* Returns whether there is a LanguageCode with ID languageID.
* @param languageID the numeric ID of a LanguageCode.
* @return whether there is a LanguageCode with ID languageID.
*/
// This gives callers a way to check lookup validity if they're working with attribute values from a messy or
// dangerous source such as a file. It wouldn't be so bad to force callers to just probe for the exception, but
// this way is a little cleaner. Providing this function also makes the API more parallel to the C++ API, where
// the analagous probe would have been harder for callers to do without being careful.
//
// We could even provide these and the lookup functions as Maps, but that's a little more functionality than I think
// callers need, and we'd have to do more work to implement Map for the nice fast array lookup that we use for the
// lookup by ID. Not that I know it's performance-sensitive, but the speed is nice to have.
//
public static boolean LanguageIDIsValid(int languageID) {
try {
lookupByLanguageID(languageID);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
/**
* Returns the LanguageCode with ID languageID.
* @param languageID the numeric ID of a LanguageCode.
* @return the LanguageCode with ID languageID.
* @throws IllegalArgumentException if there is no such LanguageCode.
*/
public static LanguageCode lookupByLanguageID(int languageID) {
return lookupByNativeCode(languageID);
}
/**
* Returns whether there is a LanguageCode with ISO code attribute iso639.
* @param iso639 An ISO code attribute of a LanguageCode: either its ISO 639-3 code attribute, its
* ISO 639-2B code attribute, or its ISO 639-1 code attribute. The comparison is case-sensitive. Returns
* false for {@link #UNCODED_ISO639_1 UNCODED_ISO639_1}.
* @return whether there is a LanguageCode with ISO code attribute iso639.
*/
// See LanguageIDIsValid for notes.
public static boolean ISO639IsValid(String iso639) {
try {
lookupByISO639(iso639);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
/**
* Returns the LanguageCode with ISO code attribute iso639.
* @param iso639 An ISO code attribute of a LanguageCode: either its ISO 639-3 code attribute, its
* ISO 639-2B attribute, or its ISO 639-1 code attribute (but not {@link #UNCODED_ISO639_1 UNCODED_ISO639_1},
* because that value does not uniquely identify a language code.) The comparison is case-sensitive.
* @return the LanguageCode with ISO code attribute iso639.
* @throws IllegalArgumentException if there is no such LanguageCode, or if iso639 equals
* {@link #UNCODED_ISO639_1 UNCODED_ISO639_1}.
*/
public static LanguageCode lookupByISO639(String iso639){
int size = iso639.length();
LanguageCode result = null;
if (size == ISO639_1_CODE_LENGTH || size == ISO639_1_BASIS_CODE_LENGTH)
result = iso639_1_index.get(iso639);
else
result = iso639_3_index.get(iso639);
if (result == null) {
result = iso639_2b_index.get(iso639);
if (result == null) {
throw new IllegalArgumentException("Invalid ISO639 " + iso639);
}
}
return result;
}
/**
* If the given LanguageCode is non-standard, returns the ISO 639-3 standard LanguageCode that best encapsulates it.
* This does not apply to {@link #UNKNOWN UNKNOWN}. If the given LanguageCode is already standard, it is returned as it is.
* @param lc A LanguageCode.
* @return the standard LanguageCode that encapsulates lc if it is non-standard. Otherwise returns lc.
*/
public static LanguageCode normalizeNonStandard(LanguageCode lc) {
switch(lc) {
case SIMPLIFIED_CHINESE:
case TRADITIONAL_CHINESE:
return LanguageCode.CHINESE;
case ENGLISH_UPPERCASE:
return LanguageCode.ENGLISH;
default:
return lc;
}
}
/** The string "zz", used as the ISO 639-1 attribute for languages present in the ISO 639-3
* specification, but for which the ISO 639-1 specification does not define a code.
*/
public static final String UNCODED_ISO639_1 = "zz";
private static final int ISO639_1_CODE_LENGTH = 2;
private static final int ISO639_1_BASIS_CODE_LENGTH = 5; // 2 + underscore + 2-char-suffix
// Indexes to look up elements by their attributes.
//
// In C++ the string lookups are implemented with code-generated static const sorted lists of strings that are
// binary searched. We could do that here, but this implementation was faster to program. Furthermore, static
// initialization is more predictable in Java (called once each time the class is loaded), so the compile-time setup
// that we do in C++ is not needed for that purpose. I'm not even certain that hash tables are needed (the previous
// version used linear search), but I'm making this sub-linear because the C++ version is sub-linear.
private static Map iso639_1_index;
private static Map iso639_3_index;
private static Map iso639_2b_index;
private static int[] id_index; // id_index[id] = position of language code #id in values()
private static final float HASHMAP_DEFAULT_LOAD_FACTOR = 0.75f;
//
// Initialization
//
static
{
// Initialize the attribute indexes.
int indexCapacity = (int) (values().length / HASHMAP_DEFAULT_LOAD_FACTOR);
iso639_1_index = new HashMap(indexCapacity);
iso639_3_index = new HashMap(indexCapacity);
iso639_2b_index = new HashMap(indexCapacity);
id_index = new int[values().length];
LanguageCode[] values = values();
for (int valuesIdx = 0; valuesIdx < values.length; valuesIdx++)
{
LanguageCode code = values[valuesIdx];
if (! code.ISO639_1().equals(UNCODED_ISO639_1))
iso639_1_index.put(code.ISO639_1(), code);
iso639_3_index.put(code.ISO639_3(), code);
iso639_2b_index.put(code.ISO639_2B(), code);
id_index[code.languageID()] = valuesIdx;
}
}
}