Java String Shorten shortenLabel(String key)

Here you can find the source of shortenLabel(String key)

Description

Replace pre-determined keywords in a string, with shorter ones.

License

Apache License

Parameter

Parameter Description
key the string to shorten.

Return

the string with its keywords replaced.

Declaration

public static String shortenLabel(String key) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .j  av  a2s . c o  m*/
 * JPPF.
 * Copyright (C) 2005-2010 JPPF Team.
 * http://www.jppf.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Keywords to look for and replace in the legend items of the charts.
     */
    private static final String[] KEYWORDS = new String[] { "Execution",
            "Maximum", "Minimum", "Average", "Cumulated" };
    /**
     * The the replacements words for the keywords in the legend items. Used to shorten the legend labels.
     */
    private static final String[] REPLACEMENTS = new String[] { "Exec",
            "Max", "Min", "Avg", "Cumul" };

    /**
     * Replace pre-determined keywords in a string, with shorter ones.
     * @param key the string to shorten.
     * @return the string with its keywords replaced.
     */
    public static String shortenLabel(String key) {
        for (int i = 0; i < KEYWORDS.length; i++) {
            if (key.indexOf(KEYWORDS[i]) >= 0)
                key = key.replace(KEYWORDS[i], REPLACEMENTS[i]);
        }
        return key;
    }
}

Related

  1. shortenDerivedIdentifier(final String derivdedIdentifier)
  2. shortenFileName(String name)
  3. shortenFileName(String text, String filename)
  4. shortenGeneratedIdentifier(final String name)
  5. shortenHash(String s)
  6. shortenMiddle(String msg, int maxLen)
  7. shortenName(final String fullName)
  8. shortenName(final String name, final int toBeAdded)
  9. shortenName(String name)