private void parsePlurals ( JsonObject root , String type , Map < String , PluralData > map ) { JsonObject node = resolve ( root , "supplemental" , type ) ; for ( Map . Entry < String , JsonElement > entry : node . entrySet ( ) ) { String language = entry . getKey ( ) ; PluralData data = new PluralData ( ) ; for ( Map . Entry < String , JsonElement > ruleNode : entry . getValue ( ) . getAsJsonObject ( ) . entrySet ( ) ) { String category = ruleNode . getKey ( ) . replaceFirst ( "^pluralRule-count-" , "" ) ; String value = ruleNode . getValue ( ) . getAsString ( ) ; Maybe < Pair < Node < PluralType > , CharSequence > > result = PluralRuleGrammar . parse ( value ) ; if ( result . isNothing ( ) ) { throw new IllegalArgumentException ( format ( "failed to parse rule: \"%s\"" , StringEscapeUtils . escapeJava ( value ) ) ) ; } Struct < PluralType > rule = result . get ( ) . _1 . asStruct ( ) ; Node < PluralType > conditionNode = findChild ( rule , PluralType . OR_CONDITION ) ; Node < PluralType > sampleNode = findChild ( rule , PluralType . SAMPLE ) ; String sample = sampleNode == null ? "" : ( String ) sampleNode . asAtom ( ) . value ( ) ; data . add ( category , new PluralData . Rule ( value , conditionNode , sample ) ) ; } map . put ( language , data ) ; } }
Parse pluralization rules . These rules indicate which pluralization category is in effect based on the value of the plural operands which are computed from an integer or decimal value .