Here you can find the source of substractPrefixPostfix(Object obj, String prefix, String suffix)
public static String substractPrefixPostfix(Object obj, String prefix, String suffix)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 Formal Mind GmbH and University of Dusseldorf. * /*from w ww. jav a 2 s .c om*/ * 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: * Michael Jastram - initial API and implementation ******************************************************************************/ public class Main { /** * This class reflectively looks for the given postfix and removes it from * the classname of the given object. Should the result contain camel case, * then spaces will be inserted. * <p> * * If obj is itself a {@link Class}, its simple name is used directly. * * If the postfix does not match, the simple class name is returned. * <p> * * If obj is null, the empty string is returned. * <p> * * The idea is that in some places, it is convenient to extract information * directly from the CamelCased classname, e.g. SpecRelationTypeItemProvider * => "Spec Relation Type". */ public static String substractPrefixPostfix(Object obj, String prefix, String suffix) { if (obj == null) { return ""; } String className = obj instanceof Class ? ((Class<?>) obj) .getSimpleName() : obj.getClass().getSimpleName(); if (!className.startsWith(suffix) && !className.endsWith(suffix)) { return className; } String name = className.substring(prefix.length(), className.length() - suffix.length()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (i != 0 && Character.isUpperCase(c)) { sb.append(' '); } sb.append(c); } return sb.toString(); } }