All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.force.i18n.LanguagePluralRules Maven / Gradle / Ivy

There is a newer version: 1.2.30
Show newest version
/*
 * Copyright (c) 2017, salesforce.com, inc.
 * All rights reserved.
 * Licensed under the BSD 3-Clause license.
 * For full license text, see LICENSE.txt file in the repo root  or https://opensource.org/licenses/BSD-3-Clause
 */
package com.force.i18n;

import java.util.Set;

/**
 * Provides an abstraction for the plural rules for a human language.  The default implementation
 * uses the optional dependency ICU4J, but that is not required and can be overridden in the
 * LanguageProviderFactory.  This will allow new languages to customize support
 *
 * @author stamm
 * @since 0.6.0
 */
public interface LanguagePluralRules {
	/**
	 * @return the human language associated with these rules
	 */
	HumanLanguage getHumanLanguage();

	/**
	 * @param value the number to check.  If null, the value {@code 0} will be used
	 * @return the PluralCategory to use for the given number as a cardinal number
	 */
	default PluralCategory getPluralCategory(Number value) {
		return getPluralCategory(value, NumberType.CARDINAL);
	}

	/**
	 * @param value  the number to test
	 * @param numberType Cardinal or Ordinal number
	 * @return the plural category for the number
	 */
	PluralCategory getPluralCategory(Number value, NumberType numberType);

	/**
	 * @return the set of categories for cardinal numbers
	 */
	default Set getSupportedCategories() {
		return getSupportedCategories(NumberType.CARDINAL);
	}

	/**
	 * @param numberType the number of type to look for, cardinal or ordinal
	 * @return the set of categories for the given number type.
	 */
	Set getSupportedCategories(NumberType numberType);

	/**
	 * Linguistic type of number, whether used for counting or ordering (i.e. 1 item vs 2 items
	 * for cardinal or 1st or 2nd for ordinal)
	 */
	enum NumberType {
		CARDINAL,
		ORDINAL
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy