Java String Plural toPlural(String name)

Here you can find the source of toPlural(String name)

Description

to Plural

License

Open Source License

Declaration

public static String toPlural(String name) 

Method Source Code

//package com.java2s;
/*/*from ww w  . j  a  v  a2s . c o m*/
 * This file is part of the Gwt-Generator project and was written by Henri Darmet for Objet Direct
 * <http://wwww.objetdirect.com>
 * 
 * Copyright ? 2009 Objet Direct
 * 
 * Gwt-Generator is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * Gwt-Generator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with Gwt-Generator. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String toPlural(String name) {
        if (name.endsWith("y")) {
            if (name.length() > 1)
                return name.substring(0, name.length() - 1) + "ies";
            else
                return "ys";
        } else if (name.endsWith("x")) {
            if (name.length() > 1)
                return name + "es";
            else
                return "xs";
        } else if (!name.endsWith("s"))
            return name + "s";
        else
            return name;
    }
}

Related

  1. toPlural(String _str)
  2. toPlural(String candidate)
  3. toPlural(String name)
  4. toPluralForm(String propertyName)