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

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

Description

Returns the singular or plural form of a string, based on the count.

License

Creative Commons License

Parameter

Parameter Description
count Number of elements.
singular Singular form.
plural Plural form, or null if plural is singular + 's'

Return

Correct form.

Declaration

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

Method Source Code

//package com.java2s;
/*****************************************************************************
 **// w  ww  .  j a v  a 2 s. com
 ** @author Lee Neuse (coder@humbleprogrammer.net)
 ** @since 1.0
 **
 **   ---------------------------- [License] ----------------------------------
 **   This work is licensed under the Creative Commons Attribution-NonCommercial-
 **   ShareAlike 3.0 Unported License. To view a copy of this license, visit
 **            http://creativecommons.org/licenses/by-nc-sa/3.0/
 **   or send a letter to Creative Commons, 444 Castro Street Suite 900, Mountain
 **   View, California, 94041, USA.
 **   --------------------- [Disclaimer of Warranty] --------------------------
 **   There is no warranty for the program, to the extent permitted by applicable
 **   law.  Except when otherwise stated in writing the copyright holders and/or
 **   other parties provide the program "as is" without warranty of any kind,
 **   either expressed or implied, including, but not limited to, the implied
 **   warranties of merchantability and fitness for a particular purpose.  The
 **   entire risk as to the quality and performance of the program is with you.
 **   Should the program prove defective, you assume the cost of all necessary
 **   servicing, repair or correction.
 **   -------------------- [Limitation of Liability] --------------------------
 **   In no event unless required by applicable law or agreed to in writing will
 **   any copyright holder, or any other party who modifies and/or conveys the
 **   program as permitted above, be liable to you for damages, including any
 **   general, special, incidental or consequential damages arising out of the
 **   use or inability to use the program (including but not limited to loss of
 **   data or data being rendered inaccurate or losses sustained by you or third
 **   parties or a failure of the program to operate with any other programs),
 **   even if such holder or other party has been advised of the possibility of
 **   such damages.
 **
 ******************************************************************************/

public class Main {
    /**
     * Returns the singular or plural form of a string, based on the count.
     *
     * @param count
     *    Number of elements.
     * @param singular
     *    Singular form.
     * @param plural
     *    Plural form, or null if plural is singular + 's'
     *
     * @return Correct form.
     */
    public static String pluralize(int count, final String singular, final String plural) {
        if (count == 1)
            return singular;
        //   -----------------------------------------------------------------
        return (plural != null) ? plural : singular + 's';
    }
}

Related

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