Java String Pluralize pluralize(final int count, final String singular, final String plural)

Here you can find the source of pluralize(final int count, final String singular, final String plural)

Description

Returns the plural word, unless count is 1 or -1.

License

LGPL

Parameter

Parameter Description
count The magnitude.
singular The singular.
plural The plural.

Return

(count == 1 || count == -1) ? singular : plural

Declaration

public static final String pluralize(final int count, final String singular, final String plural) 

Method Source Code

//package com.java2s;
/**/*from  w w w.  j  a  v  a  2  s . c  o  m*/
 * Copyright (C) 2013, University of Manchester and University of Southampton
 *
 * Licensed under the GNU Lesser General Public License v2.1
 * See the "LICENSE" file that is distributed with the source code for license terms. 
 */

public class Main {
    /**
     * Returns the <code>plural</code> word, unless <code>count</code> is 1 or -1. 
     * In which case, the <code>singular</code> word is returned. 
     * 
     * @param count  The magnitude.
     * @param singular  The singular. 
     * @param plural  The plural.  
     * @return  <code>(count == 1 || count == -1) ? singular : plural</code>
     */
    public static final String pluralize(final int count, final String singular, final String plural) {
        switch (count) {
        case -1:
        case 1:
            return String.format(singular, count);
        default:
            return String.format(plural, count);
        }
    }
}

Related

  1. pluralise(String name)
  2. pluralise(String str)
  3. pluralise(String string, double size)
  4. pluraliseInc(int num, String word)
  5. pluraliseNoun(String noun, long count, boolean forceAppendingSByDefault)
  6. pluralize(final String s)
  7. pluralize(final String typeName)
  8. pluralize(int count, final String singular, final String plural)
  9. pluralize(int count, String single)