Java String Pluralize plural(String singular)

Here you can find the source of plural(String singular)

Description

plural

License

Open Source License

Declaration

public static String plural(String singular) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Oobium, Inc./*from w ww . j  av  a2  s.c  o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Jeremy Dowdall <jeremy@oobium.com> - initial API and implementation
 ******************************************************************************/

public class Main {
    public static String plural(String singular) {
        if (singular == null || singular.length() == 0) {
            return singular;
        }
        if (singular.equalsIgnoreCase("person")) {
            return singular.charAt(0) + "eople";
        } else if (singular.equalsIgnoreCase("child")) {
            return singular.charAt(0) + "hildren";
        } else if (singular.equalsIgnoreCase("alumnus")) {
            return singular.charAt(0) + "lumni";
        } else if ('y' == singular.charAt(singular.length() - 1)) {
            if (singular.length() > 1) {
                switch (singular.charAt(singular.length() - 2)) {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u':
                    break;
                default:
                    return singular.substring(0, singular.length() - 1) + "ies";
                }
            }
        } else if ('s' == singular.charAt(singular.length() - 1)) {
            return singular + "es";
        } else if (singular.endsWith("ch")) {
            return singular + "es";
        }
        return singular + "s";
    }
}

Related

  1. plural(int nb)
  2. plural(int number, String form1, String form2, String form3)
  3. plural(int size, String name)
  4. plural(String arg)
  5. plural(String objectName)
  6. plural(String str, String suffix, int count)
  7. plural(String strSingle, String strPlural, int amount)
  8. plural(String txt)
  9. plural(String type)