Example usage for org.apache.commons.lang StringUtils removeEnd

List of usage examples for org.apache.commons.lang StringUtils removeEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils removeEnd.

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:org.eclipse.wb.internal.core.model.property.category.PropertyCategory.java

/**
 * Parses {@link PropertyCategory} from strings. Supported strings are:
 * //from w  ww  . j a v a2  s .co  m
 * <ul>
 * <li><b>normal</b></li>
 * <li><b>preferred</b></li>
 * <li><b>advanced</b></li>
 * <li><b>advanced-really</b></li>
 * <li><b>hidden</b></li>
 * <li><b>system(number)</b></li>
 * </ul>
 * 
 * @param defaultCategory
 *          the {@link PropertyCategory} to use if given string can not be parsed, or
 *          <code>null</code> if exception should be thrown.
 * 
 * @return the parsed {@link PropertyCategory}.
 */
public static PropertyCategory get(String text, PropertyCategory defaultCategory) {
    // simple
    if (StringUtils.equals(text, "normal")) {
        return NORMAL;
    }
    if (StringUtils.equals(text, "preferred")) {
        return PREFERRED;
    }
    if (StringUtils.equals(text, "advanced")) {
        return ADVANCED;
    }
    if (StringUtils.equals(text, "advanced-really")) {
        return ADVANCED_REALLY;
    }
    if (StringUtils.equals(text, "hidden")) {
        return HIDDEN;
    }
    // system
    if (StringUtils.startsWith(text, "system(")) {
        String systemText = text;
        systemText = StringUtils.removeStart(systemText, "system(");
        systemText = StringUtils.removeEnd(systemText, ")");
        try {
            int priority = Integer.parseInt(systemText);
            return system(priority);
        } catch (NumberFormatException e) {
        }
    }
    // can not parse
    if (defaultCategory != null) {
        return defaultCategory;
    }
    throw new IllegalArgumentException("Unknown category " + text);
}

From source file:org.eclipse.wb.internal.core.model.property.event.ListenerInfo.java

/**
 * @return the name of listener method, to display for user. For example <code>key</code> for
 *         <code>addKeyListener()</code>.
 *///  ww w  .  j  av  a2s  . c  o  m
private static String _getListenerSimpleName(Method addListenerMethod) {
    String name = addListenerMethod.getName();
    // convert into simple name
    name = StringUtils.removeStart(name, "add");
    name = StringUtils.removeEnd(name, "Listener");
    name = StringUtils.removeEnd(name, "Handler");
    name = StringUtils.uncapitalize(name);
    // if become empty, use full name
    if (name.length() == 0) {
        name = addListenerMethod.getName();
    }
    return name;
}

From source file:org.eclipse.wb.internal.core.model.property.event.ListenerInfo.java

/**
 * @return the adapter class for given listener interface type, may be <code>null</code>.
 *//*from   w w  w.  j  av a  2  s  .  c  o  m*/
private static Class<?> _getAdapterType(Class<?> listenerType) {
    Class<?> adapterType = null;
    // -Listener/Handler +Adapter
    {
        String adapterClassName = listenerType.getName();
        adapterClassName = StringUtils.removeEnd(adapterClassName, "Listener");
        adapterClassName = StringUtils.removeEnd(adapterClassName, "Handler");
        adapterClassName = adapterClassName + "Adapter";
        adapterType = _getExistingType(listenerType, adapterClassName);
    }
    // +Adapter
    if (adapterType == null) {
        String adapterClassName = listenerType.getName();
        adapterClassName = adapterClassName + "Adapter";
        adapterType = _getExistingType(listenerType, adapterClassName);
    }
    // result
    return adapterType;
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java

/**
 * @return the primary {@link TypeDeclaration}.
 *//* www  .  j a va 2 s.  co  m*/
public TypeDeclaration getPrimaryType() {
    String unitName = m_modelUnit.getElementName();
    String typeName = StringUtils.removeEnd(unitName, ".java");
    return AstNodeUtils.getTypeByName(m_astUnit, typeName);
}

From source file:org.eclipse.wb.internal.core.xml.model.property.converter.DoubleConverter.java

@Override
public String toSource(XmlObjectInfo object, Object value) throws Exception {
    if (value instanceof Double) {
        String source = Double.toString((Double) value);
        source = StringUtils.removeEnd(source, ".0");
        return source;
    }//  ww  w . jav a2  s  .  c o  m
    return null;
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo.java

/**
 * @return {@link PropertyBindableInfo} property that association with given reference or or
 *         <code>null</code>.
 *///from  w  w w .j  a va  2 s  . co m
@Override
public final PropertyBindableInfo resolvePropertyReference(String reference) throws Exception {
    if (reference.indexOf('.') == -1 || !reference.startsWith("\"")) {
        for (PropertyBindableInfo property : getProperties()) {
            if (reference.equals(property.getReference())) {
                return property;
            }
        }
    } else {
        String localReference = StringUtils.removeStart(reference, "\"");
        localReference = StringUtils.removeEnd(localReference, "\"");
        return resolvePropertyReference(reference, StringUtils.split(localReference, "."), 0);
    }
    return null;
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo.java

protected final PropertyBindableInfo resolvePropertyReference(String reference, String[] references, int index)
        throws Exception {
    if (index == references.length - 1) {
        for (PropertyBindableInfo property : getProperties()) {
            if (reference.equals(property.getReference())) {
                return property;
            }/* www  .j a  v a2s  .c  o m*/
        }
    } else {
        String localReference = references[index];
        //
        for (PropertyBindableInfo property : getProperties()) {
            String propertyReference = StringUtils.removeStart(property.getReference(), "\"");
            propertyReference = StringUtils.removeEnd(propertyReference, "\"");
            int pointIndex = propertyReference.lastIndexOf('.');
            //
            if (pointIndex != -1) {
                propertyReference = propertyReference.substring(pointIndex + 1);
            }
            if (localReference.equals(propertyReference)) {
                return property.resolvePropertyReference(reference, references, index + 1);
            }
        }
    }
    return null;
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanPropertyDescriptorBindableInfo.java

private static String createReference(IObserveInfo parent, String reference) throws Exception {
    if (parent instanceof BeanPropertyDescriptorBindableInfo) {
        BeanPropertyDescriptorBindableInfo bindableParent = (BeanPropertyDescriptorBindableInfo) parent;
        return StringUtils.removeEnd(bindableParent.getReference(), "\"") + "." + reference + "\"";
    }//from   w  w  w .j  ava 2s.com
    return "\"" + reference + "\"";
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanPropertyDescriptorBindableInfo.java

private static IObservePresentation createPresentation(IObserveInfo parent, String reference,
        Class<?> objectType) throws Exception {
    if (parent instanceof BeanPropertyDescriptorBindableInfo) {
        BeanPropertyDescriptorBindableInfo bindableParent = (BeanPropertyDescriptorBindableInfo) parent;
        String parentReference = StringUtils.removeStart(bindableParent.getReference(), "\"");
        parentReference = StringUtils.removeEnd(parentReference, "\"");
        ///*w w w . j a  v a 2s  .  c  o m*/
        final String bindingReference = parentReference + "." + reference;
        return new SimpleObservePresentation(reference, bindingReference,
                TypeImageProvider.getImage(objectType));
    }
    return new SimpleObservePresentation(reference, TypeImageProvider.getImage(objectType));
}

From source file:org.eclipse.wb.internal.rcp.model.widgets.SashFormInfo.java

/**
 * Ensures that this {@link SashFormInfo} has "setWeights()" invocation.
 * //from   w  ww  .  j  ava  2 s.c o m
 * @return the {@link ArrayInitializer} for weights.
 */
private ArrayInitializer ensureWeights() throws Exception {
    MethodInvocation invocation = getMethodInvocation("setWeights(int[])");
    if (invocation == null) {
        String elementsSource;
        {
            elementsSource = StringUtils.repeat("1, ", getChildrenControls().size());
            elementsSource = StringUtils.removeEnd(elementsSource, ", ");
        }
        // add invocation
        String arraySource = "new int[] {" + elementsSource + "}";
        invocation = addMethodInvocation("setWeights(int[])", arraySource);
    }
    return ((ArrayCreation) DomGenerics.arguments(invocation).get(0)).getInitializer();
}