Java String Shorten shortenName(final String fullName)

Here you can find the source of shortenName(final String fullName)

Description

shorten Name

License

Open Source License

Declaration

static protected String shortenName(final String fullName) 

Method Source Code

//package com.java2s;

public class Main {
    static protected String shortenName(final String fullName) {
        String result;//from w  w  w  . jav a  2 s. co m

        if (fullName.isEmpty()) {
            result = "";
        } else {
            result = removePrefix(fullName);
            result = cleanSuffix(result);
        }

        return result;
    }

    static public String removePrefix(final String name) {
        String result = name;

        if (name.contains("#")) {
            result = name.replaceAll(".*#", "");
        }

        return result;
    }

    static public String cleanSuffix(final String name) {
        String result = name;

        if (name.endsWith("/")) {
            result = result.substring(0, result.length() - 1);
        }

        final int lastPos = result.lastIndexOf("/", result.length());

        if (lastPos != -1) {
            result = result.substring(lastPos + 1, result.length());
        }

        return result;
    }
}

Related

  1. shortenFileName(String text, String filename)
  2. shortenGeneratedIdentifier(final String name)
  3. shortenHash(String s)
  4. shortenLabel(String key)
  5. shortenMiddle(String msg, int maxLen)
  6. shortenName(final String name, final int toBeAdded)
  7. shortenName(String name)
  8. shortenOperationName(String operation)
  9. shortenPackageName(String name, boolean remove)