Java String Pluralize pluralForm(final String string, final int number)

Here you can find the source of pluralForm(final String string, final int number)

Description

Return a default plural form string.

License

Apache License

Parameter

Parameter Description
string string to append, e.g. <code>"item"</code>
number number of items

Return

if number equals 1, returns the original string, otherwise returns string + "s"

Declaration

public static String pluralForm(final String string, final int number) 

Method Source Code

//package com.java2s;
/**/*from w w  w. j  a  v  a 2s. c om*/
 * Copyright (C) [2013] [The FURTHeR Project]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Return a default plural form string. Example: prints <code>item</code> or
     * <code>items</code> depending on the number of items in question.
     * 
     * @param string
     *            string to append, e.g. <code>"item"</code>
     * @param number
     *            number of items
     * @return if number equals <code>1</code>, returns the original string, otherwise
     *         returns <code>string + "s"</code>
     */
    public static String pluralForm(final String string, final int number) {
        return (number == 1) ? string : (string + "s");
    }

    /**
     * Return a default plural form string. Example: prints <code>item</code> or
     * <code>items</code> depending on the number of items in question.
     * 
     * @param string
     *            string to append, e.g. <code>"item"</code>
     * @param number
     *            number of items
     * @return if number equals <code>1</code>, returns the original string, otherwise
     *         returns <code>string + "s"</code>
     */
    public static String pluralForm(final String string, final long number) {
        return (number == 1) ? string : (string + "s");
    }

    /**
     * Return a flexible plural form string. Example: prints <code>status</code> or
     * <code>stati</code> depending on the number of status objects in question.
     * 
     * @param singleForm
     *            single form of the object in question
     * @param plural
     *            plural form of the object in question
     * @param number
     *            number of items
     * @return if number equals <code>1</code>, returns the single form, otherwise returns
     *         the plural form
     */
    public static String pluralForm(final String singleForm, final String pluralForm, final int number) {
        return (number == 1) ? singleForm : pluralForm;
    }
}

Related

  1. plural(String txt)
  2. plural(String type)
  3. plural(String word)
  4. plural(String word, Number cardinality)
  5. plural(StringBuffer buffer, int i, String s1, String s2)
  6. pluralify(String term, int value)
  7. pluralise(int count, String singular, String plural)
  8. pluralise(int num, String word)
  9. pluralise(String name)