* <p>
* Examples:
* </p>
- *
+ *
* <pre>
* "one: n is 1; few: n in 2..4"
* </pre>
* between 2 and 4 inclusive - and be an integer - for this condition to pass. All other numbers are assigned the
* keyword "other" by the default rule.
* </p>
- *
+ *
* <pre>
* "zero: n is 0; one: n is 1; zero: n mod 100 in 1..19"
* </pre>
* keyword whose condition passes is the one returned. Also notes that a modulus is applied to n in the last rule. Thus
* its condition holds for 119, 219, 319...
* </p>
- *
+ *
* <pre>
* "one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14"
* </pre>
* includes all values. Using 'within' with a range_list consisting entirely of values is the same as using 'in' (it's
* not an error).
* </p>
- *
+ *
* @stable ICU 3.8
*/
public class PluralRules implements Serializable {
/**
* Provides a factory for returning plural rules
- *
+ *
* @internal
* @deprecated This API is ICU internal only.
*/
/**
* Provides access to the predefined <code>PluralRules</code> for a given locale and the plural type.
- *
+ *
* <p>
* ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>. For these predefined
* rules, see CLDR page at http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
- *
+ *
* @param locale
* The locale for which a <code>PluralRules</code> object is returned.
* @param type
/**
* Returns the locales for which there is plurals data.
- *
+ *
* @internal
* @deprecated This API is ICU internal only.
*/
* All locales with the same functionally equivalent locale have plural rules that behave the same. This is not
* exaustive; there may be other locales whose plural rules behave the same that do not have the same equivalent
* locale.
- *
+ *
* @param locale
* the locale to check
* @param isAvailable
private static final Constraint NO_CONSTRAINT = new Constraint() {
private static final long serialVersionUID = 9163464945387899416L;
+ @Override
public boolean isFulfilled(FixedDecimal n) {
return true;
}
+ @Override
public boolean isLimited(SampleType sampleType) {
return false;
}
+ @Override
public String toString() {
return "";
}
};
/**
- *
+ *
*/
private static final Rule DEFAULT_RULE = new Rule("other", NO_CONSTRAINT, null, null);
source = isNegative ? -n : n;
visibleDecimalDigitCount = v;
decimalDigits = f;
- integerValue = n > MAX
- ? MAX
+ integerValue = n > MAX
+ ? MAX
: (long)n;
hasIntegerValue = source == integerValue;
// check values. TODO make into unit test.
- //
+ //
// long visiblePower = (int) Math.pow(10, v);
// if (fractionalDigits > visiblePower) {
// throw new IllegalArgumentException();
* Returns 0 for infinities and nans.
* @internal
* @deprecated This API is ICU internal only.
- *
+ *
*/
@Deprecated
public static int decimals(double n) {
if (buf.charAt(i) != '0') {
break;
}
- --numFractionDigits;
+ --numFractionDigits;
}
return numFractionDigits;
}
* @internal
* @deprecated This API is ICU internal only.
*/
+ @Override
@Deprecated
public int compareTo(FixedDecimal other) {
if (integerValue != other.integerValue) {
}
String[] rangeParts = TILDE_SEPARATED.split(range);
switch (rangeParts.length) {
- case 1:
+ case 1:
FixedDecimal sample = new FixedDecimal(rangeParts[0]);
checkDecimal(sampleType2, sample);
samples2.add(new FixedDecimalRange(sample, sample));
private static void checkDecimal(SampleType sampleType2, FixedDecimal sample) {
if ((sampleType2 == SampleType.INTEGER) != (sample.getVisibleDecimalDigitCount() == 0)) {
- throw new IllegalArgumentException("Ill-formed number range: " + sample);
+ throw new IllegalArgumentException("Ill-formed number range: " + sample);
}
}
if (!t.equals(",")) { // adjacent number: 1 2
// no separator, fail
throw unexpected(t, condition);
- }
+ }
}
} else if (!t.equals(",")) { // adjacent number: 1 2
// no separator, fail
FixedDecimalSamples integerSamples = null, decimalSamples = null;
switch (constraintOrSamples.length) {
case 1: break;
- case 2:
+ case 2:
integerSamples = FixedDecimalSamples.parse(constraintOrSamples[1]);
if (integerSamples.sampleType == SampleType.DECIMAL) {
decimalSamples = integerSamples;
throw new IllegalArgumentException("Must have @integer then @decimal in " + description);
}
break;
- default:
+ default:
throw new IllegalArgumentException("Too many samples in " + description);
}
if (sampleFailure) {
throws ParseException {
RuleList result = new RuleList();
// remove trailing ;
- if (description.endsWith(";")) {
+ if (description.endsWith(";")) {
description = description.substring(0,description.length()-1);
}
String[] rules = SEMI_SEPARATED.split(description);
this.operand = operand;
}
+ @Override
public boolean isFulfilled(FixedDecimal number) {
double n = number.get(operand);
if ((integersOnly && (n - (long)n) != 0.0
return inRange == test;
}
+ @Override
public boolean isLimited(SampleType sampleType) {
boolean valueIsZero = lowerBound == upperBound && lowerBound == 0d;
- boolean hasDecimals =
+ boolean hasDecimals =
(operand == Operand.v || operand == Operand.w || operand == Operand.f || operand == Operand.t)
&& inRange != valueIsZero; // either NOT f = zero or f = non-zero
switch (sampleType) {
- case INTEGER:
+ case INTEGER:
return hasDecimals // will be empty
|| (operand == Operand.n || operand == Operand.i || operand == Operand.j)
- && mod == 0
+ && mod == 0
&& inRange;
case DECIMAL:
return (!hasDecimals || operand == Operand.n || operand == Operand.j)
&& (integersOnly || lowerBound == upperBound)
- && mod == 0
+ && mod == 0
&& inRange;
}
return false;
}
+ @Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(operand);
result.append(
!isList ? (inRange ? " = " : " != ")
: integersOnly ? (inRange ? " = " : " != ")
- : (inRange ? " within " : " not within ")
+ : (inRange ? " within " : " not within ")
);
if (range_list != null) {
for (int i = 0; i < range_list.length; i += 2) {
super(a, b);
}
+ @Override
public boolean isFulfilled(FixedDecimal n) {
- return a.isFulfilled(n)
+ return a.isFulfilled(n)
&& b.isFulfilled(n);
}
+ @Override
public boolean isLimited(SampleType sampleType) {
// we ignore the case where both a and b are unlimited but no values
// satisfy both-- we still consider this 'unlimited'
- return a.isLimited(sampleType)
+ return a.isLimited(sampleType)
|| b.isLimited(sampleType);
}
+ @Override
public String toString() {
return a.toString() + " and " + b.toString();
}
super(a, b);
}
+ @Override
public boolean isFulfilled(FixedDecimal n) {
- return a.isFulfilled(n)
+ return a.isFulfilled(n)
|| b.isFulfilled(n);
}
+ @Override
public boolean isLimited(SampleType sampleType) {
- return a.isLimited(sampleType)
+ return a.isLimited(sampleType)
&& b.isLimited(sampleType);
}
+ @Override
public String toString() {
return a.toString() + " or " + b.toString();
}
* Provides 'and' and 'or' to combine constraints. Immutable.
*/
private static class Rule implements Serializable {
+ // TODO - Findbugs: Class com.ibm.icu.text.PluralRules$Rule defines non-transient
+ // non-serializable instance field integerSamples. See ticket#10494.
private static final long serialVersionUID = 1;
private final String keyword;
private final Constraint constraint;
return constraint.isLimited(sampleType);
}
+ @Override
public String toString() {
- return keyword + ": " + constraint.toString()
+ return keyword + ": " + constraint.toString()
+ (integerSamples == null ? "" : " " + integerSamples.toString())
+ (decimalSamples == null ? "" : " " + decimalSamples.toString());
}
return result;
}
+ @Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (Rule rule : rules) {
* @param type the type of samples requested, INTEGER or DECIMAL
* @return the values that trigger this keyword, or null. The returned collection
* is immutable. It will be empty if the keyword is not defined.
- *
+ *
* @internal
* @deprecated This API is ICU internal only.
*/
* {@inheritDoc}
* @stable ICU 3.8
*/
+ @Override
public String toString() {
return rules.toString();
}
* {@inheritDoc}
* @stable ICU 3.8
*/
+ @Override
public boolean equals(Object rhs) {
return rhs instanceof PluralRules && equals((PluralRules)rhs);
}
/**
* Status of the keyword for the rules, given a set of explicit values.
- *
+ *
* @draft ICU 50
* @provisional This API might change or be removed in a future release.
*/
public enum KeywordStatus {
/**
* The keyword is not valid for the rules.
- *
+ *
* @draft ICU 50
* @provisional This API might change or be removed in a future release.
*/
INVALID,
/**
* The keyword is valid, but unused (it is covered by the explicit values, OR has no values for the given {@link SampleType}).
- *
+ *
* @draft ICU 50
* @provisional This API might change or be removed in a future release.
*/
SUPPRESSED,
/**
* The keyword is valid, used, and has a single possible value (before considering explicit values).
- *
+ *
* @draft ICU 50
* @provisional This API might change or be removed in a future release.
*/
UNIQUE,
/**
* The keyword is valid, used, not unique, and has a finite set of values.
- *
+ *
* @draft ICU 50
* @provisional This API might change or be removed in a future release.
*/
BOUNDED,
/**
* The keyword is valid but not bounded; there indefinitely many matching values.
- *
+ *
* @draft ICU 50
* @provisional This API might change or be removed in a future release.
*/
/**
* Find the status for the keyword, given a certain set of explicit values.
- *
+ *
* @param keyword
* the particular keyword (call rules.getKeywords() to get the valid ones)
* @param offset
}
/**
* Find the status for the keyword, given a certain set of explicit values.
- *
+ *
* @param keyword
* the particular keyword (call rules.getKeywords() to get the valid ones)
* @param offset
// Concatenates 're' with '\u0301sum\u00e9 is HERE' and places the result at
// position 3 of string 'My resume is here'.
- int len = Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
+ Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
destination, 3, 17, mode, 0);
if(!String.valueOf(destination).equals(expect)) {
errln("error in Normalizer.concatenate(), cases2[] failed"
// Error case when result of concatenation won't fit into destination array.
try {
- len = Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
+ Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
destination, 3, 16, mode, 0);
} catch (IndexOutOfBoundsException e) {
assertTrue("Normalizer.concatenate() failed", e.getMessage().equals("14"));
return;
- }
+ }
fail("Normalizer.concatenate() tested for failure but passed");
}
private int ref_norm_compare(String s1, String s2, int options) {
String t1, t2,r1,r2;
- int normOptions=(int)(options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT);
+ int normOptions=options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT;
if((options&Normalizer.COMPARE_IGNORE_CASE)!=0) {
// NFD(toCasefold(NFD(X))) = NFD(toCasefold(NFD(Y)))
// test wrapper for Normalizer::compare, sets UNORM_INPUT_IS_FCD appropriately
private int norm_compare(String s1, String s2, int options) {
- int normOptions=(int)(options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT);
+ int normOptions=options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT;
if( Normalizer.YES==Normalizer.quickCheck(s1,Normalizer.FCD,normOptions) &&
Normalizer.YES==Normalizer.quickCheck(s2,Normalizer.FCD,normOptions)) {
};
StringBuilder s, pattern;
- // build NF*Skippable sets from runtime data
+ // build NF*Skippable sets from runtime data
skipSets[D].applyPattern("[:NFD_Inert:]");
skipSets[C].applyPattern("[:NFC_Inert:]");
skipSets[KD].applyPattern("[:NFKD_Inert:]");
public class TestNormalizer2 extends Normalizer2 {
public TestNormalizer2() {}
+ @Override
public StringBuilder normalize(CharSequence src, StringBuilder dest) { return null; }
+ @Override
public Appendable normalize(CharSequence src, Appendable dest) { return null; }
+ @Override
public StringBuilder normalizeSecondAndAppend(
StringBuilder first, CharSequence second) { return null; }
+ @Override
public StringBuilder append(StringBuilder first, CharSequence second) { return null; }
+ @Override
public String getDecomposition(int c) { return null; }
+ @Override
public boolean isNormalized(CharSequence s) { return false; }
+ @Override
public Normalizer.QuickCheckResult quickCheck(CharSequence s) { return null; }
+ @Override
public int spanQuickCheckYes(CharSequence s) { return 0; }
+ @Override
public boolean hasBoundaryBefore(int c) { return false; }
+ @Override
public boolean hasBoundaryAfter(int c) { return false; }
+ @Override
public boolean isInert(int c) { return false; }
}