Java String Plural toPluralForm(String propertyName)

Here you can find the source of toPluralForm(String propertyName)

Description

to Plural Form

License

Apache License

Declaration

public static String toPluralForm(String propertyName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String toPluralForm(String propertyName) {
        String endString;/*from  ww  w. j  a  v a2  s  .c o m*/
        if (propertyName.endsWith("Parson") || propertyName.endsWith("parson")) {
            propertyName = propertyName.replace("Parson", "");
            propertyName = propertyName.replace("parson", "");
            if ("".equals(propertyName)) {
                endString = "people";
            } else {
                endString = "People";
            }
        } else if (propertyName.endsWith("ch") || propertyName.endsWith("th") || propertyName.endsWith("s")) {
            endString = "es";
        } else if (propertyName.endsWith("y") && propertyName.length() > 1) {
            String s = propertyName.substring(propertyName.length() - 1, propertyName.length());
            if ("a".equals(s) || "i".equals(s) || "u".equals(s) || "e".equals(s) || "o".equals(s)) {
                endString = "s";
            } else {
                propertyName = propertyName.substring(0, propertyName.length() - 1);
                endString = "ies";
            }

        } else {
            endString = "s";
        }

        return propertyName + endString;
    }
}

Related

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