Java String Singularize singularize(final String buffer)

Here you can find the source of singularize(final String buffer)

Description

singularize

License

Open Source License

Parameter

Parameter Description
buffer a parameter

Declaration

public static String singularize(final String buffer) 

Method Source Code

//package com.java2s;
/*//from   w w w.  java 2 s . co m
 * Fast Code Plugin for Eclipse
 *
 * Copyright (C) 2008  Gautam Dev
 *
 * This library 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 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
 *
 * Plugin Home Page: http://fast-code.sourceforge.net/
 */

public class Main {
    /**
     *
     * @param buffer
     * @return
     */
    public static String singularize(final String buffer) {
        String singular = null;
        if (buffer == null) {
            return singular;
        }
        final int length = buffer.length();
        if (buffer.endsWith("ies")) {
            singular = buffer.substring(0, length - 3);
        } else if (buffer.endsWith("es")) {
            singular = buffer.substring(0, length - 2);
        } else if (buffer.endsWith("s")) {
            singular = buffer.substring(0, length - 1);
        }
        return singular;
    }
}

Related

  1. singular(String plural)
  2. singularise(String name)
  3. singularize(String value)
  4. singularOrPlural(int testValue, String singular, String plural)
  5. singularPlural(int n, String singular, String plural)
  6. SingularToPlural(String noun)