public static Label . Builder addLabel ( final Label . Builder labelBuilder , final String languageCode , final String label ) { for ( int i = 0 ; i < labelBuilder . getEntryCount ( ) ; i ++ ) { // found labels for the entry key if ( labelBuilder . getEntry ( i ) . getKey ( ) . equals ( languageCode ) ) { // check if the new value is not already contained for ( String value : labelBuilder . getEntryBuilder ( i ) . getValueList ( ) ) { if ( value . equalsIgnoreCase ( label ) ) { // return because label is already in there return labelBuilder ; } } // add new label labelBuilder . getEntryBuilder ( i ) . addValue ( label ) ; return labelBuilder ; } } // language code not present yet labelBuilder . addEntryBuilder ( ) . setKey ( languageCode ) . addValue ( label ) ; return labelBuilder ; }
Add a label to a labelBuilder by languageCode . If the label is already contained for the language code nothing will be done . If the languageCode already exists and the label is not contained it will be added to the end of the label list by this language code . If no entry for the languageCode exists a new entry will be added and the label added as its first value .