Here you can find the source of pluralForm(final String string, final int number)
Parameter | Description |
---|---|
string | string to append, e.g. <code>"item"</code> |
number | number of items |
1
, returns the original string, otherwise returns string + "s"
public static String pluralForm(final String string, final int number)
//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; } }