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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

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

Usage

From source file:it.TestCustomFields.java

@Test
public void importingWithSelectCustomField() {
    final String cid = StringUtils.removeStart(
            administration.customFields().addCustomField(SELECT_CF_TYPE, "Select"),
            FieldManager.CUSTOM_FIELD_PREFIX);
    administration.customFields().addOptions(cid, "Core", "Subsystem", "API", "UX");

    assertSelectOrRadio();/*from w  w w.j a v  a 2 s  .  c  o  m*/
}

From source file:edu.cornell.med.icb.geo.GEOPlatformIndexed.java

/**
 * Set the current state of the object from a map of properties.
 * @param propertyMap A map of properties indexed by string key names that can be then
 * used to reconstruct the object state.
 *///from www. j  av  a2  s  .  c  o m
public void fromPropertyMap(final Map<String, Properties> propertyMap) {
    if (propertyMap == null) {
        throw new IllegalArgumentException("Property map cannot be null");
    }

    // IndexedIdentifier probeIds2ProbeIndex
    final Map<String, Properties> probeIds2ProbeIndexPropertyMap = new HashMap<String, Properties>();
    for (final Map.Entry<String, Properties> entry : propertyMap.entrySet()) {
        final String key = entry.getKey();
        if (key.startsWith(PROBE_IDS2_PROBE_INDEX_KEY)) {
            probeIds2ProbeIndexPropertyMap.put(StringUtils.removeStart(key, PROBE_IDS2_PROBE_INDEX_KEY),
                    entry.getValue());
        }
    }
    probeIds2ProbeIndex.fromPropertyMap(probeIds2ProbeIndexPropertyMap);

    // IndexedIdentifier externalIds2TranscriptIndex
    final Map<String, Properties> externalIds2TranscriptIndexPropertyMap = new HashMap<String, Properties>();
    for (final Map.Entry<String, Properties> entry : propertyMap.entrySet()) {
        final String key = entry.getKey();
        if (key.startsWith(EXTERNAL_IDS2_TRANSCRIPT_INDEX_KEY)) {
            externalIds2TranscriptIndexPropertyMap
                    .put(StringUtils.removeStart(key, EXTERNAL_IDS2_TRANSCRIPT_INDEX_KEY), entry.getValue());
        }
    }
    externalIds2TranscriptIndex.fromPropertyMap(externalIds2TranscriptIndexPropertyMap);

    // Int2IntMap probeIndex2ExternalIDIndex
    probeIndex2ExternalIDIndex.clear(); // reset any previous state
    final Properties probeIndex2ExternalIDIndexProperties = propertyMap.get(PROBE_INDEX2_EXTERNAL_IDINDEX_KEY);
    if (probeIndex2ExternalIDIndexProperties != null) {
        for (final Map.Entry<Object, Object> entry : probeIndex2ExternalIDIndexProperties.entrySet()) {
            probeIndex2ExternalIDIndex.put(NumberUtils.toInt(entry.getKey().toString()),
                    NumberUtils.toInt(entry.getValue().toString()));
        }
    }

    // MutableString externalIdType
    final Properties externalIdTypeProperties = propertyMap.get(EXTERNAL_ID_TYPE_KEY);
    if (externalIdTypeProperties != null) {
        externalIdType = new MutableString(
                StringUtils.defaultString(externalIdTypeProperties.getProperty(EXTERNAL_ID_TYPE_KEY)));
    } else {
        externalIdType = null;
    }

    // MutableString name
    final Properties nameProperties = propertyMap.get(NAME_KEY);
    if (nameProperties != null) {
        name = new MutableString(StringUtils.defaultString(nameProperties.getProperty(NAME_KEY)));
    } else {
        name = null;
    }

    // Int2ObjectMap<MutableString> externalIndex2Id
    externalIndex2Id.clear(); // reset any previous state
    final Properties externalIndex2IdProperties = propertyMap.get(EXTERNAL_INDEX2_ID_KEY);
    if (externalIndex2IdProperties != null) {
        for (final Map.Entry<Object, Object> entry : externalIndex2IdProperties.entrySet()) {
            externalIndex2Id.put(NumberUtils.toInt(entry.getKey().toString()),
                    new MutableString(entry.getValue().toString()));
        }
    }

    // Int2ObjectMap<MutableString> probeIndex2probeId
    probeIndex2probeId.clear(); // reset any previous state
    final Properties probeIndex2probeIdProperties = propertyMap.get(PROBE_INDEX2PROBE_ID_KEY);
    if (probeIndex2probeIdProperties != null) {
        for (final Map.Entry<Object, Object> entry : probeIndex2probeIdProperties.entrySet()) {
            probeIndex2probeId.put(NumberUtils.toInt(entry.getKey().toString()),
                    new MutableString(entry.getValue().toString()));
        }
    }
}

From source file:adalid.util.velocity.MavenArchetypeBuilder.java

private boolean copyTextFiles() {
    Collection<File> files = FileUtils.listFiles(projectFolder, textFileFilter(), textDirFilter());
    //      ColUtils.sort(files);
    String source, target, targetParent, template, clazz;
    boolean java;
    Charset cs;// ww  w  . ja v  a  2 s.  c o  m
    SmallFile smallSource;
    for (File file : files) {
        source = file.getPath();
        java = StringUtils.endsWithIgnoreCase(source, ".java");
        target = source.replace(projectFolderPath, velocityTemplatesTargetFolderPath);
        template = StringUtils.removeStart(target, velocityTemplatesTargetFolderPath + FS).replace('\\', '/');
        clazz = StringUtils
                .removeStartIgnoreCase(StringUtils.removeEndIgnoreCase(template, ".java"), "src/main/java/")
                .replace('/', '.');
        if (java) {
            classes.add(clazz);
            sources.add(template);
        } else {
            resources.add(template);
        }
    }
    String alias = alias(false);
    String ALIAS = alias(true);
    String packageX1 = packageName + ".";
    String packageX2 = packageName + ";";
    List<String> sourceLines;
    List<String> targetLines = new ArrayList<>();
    for (File file : files) {
        source = file.getPath();
        java = StringUtils.endsWithIgnoreCase(source, ".java");
        target = source.replace(projectFolderPath, velocityTemplatesTargetFolderPath);
        targetParent = StringUtils.substringBeforeLast(target, FS);
        targetLines.clear();
        FilUtils.mkdirs(targetParent);
        smallSource = new SmallFile(source);
        sourceLines = smallSource.read();
        check(smallSource);
        if (smallSource.isNotEmpty()) {
            for (String line : sourceLines) {
                if (StringUtils.isNotBlank(line)) {
                    line = line.replace(group, "${groupId}");
                    line = line.replace(artifact, "${artifactId}");
                    line = line.replace(project + "ap", alias + "ap");
                    line = line.replace(PROJECT + "AP", ALIAS + "AP");
                    line = line.replace("package " + packageX1, "package ${package}." + packageX1);
                    line = line.replace("package " + packageX2, "package ${package}." + packageX2);
                    for (String name : classes) {
                        if (name.startsWith(packageX1)) {
                            line = line.replace(name, "${package}." + name);
                        }
                    }
                }
                targetLines.add(line);
            }
        }
        cs = java ? StandardCharsets.UTF_8 : WINDOWS_CHARSET;
        if (write(target, targetLines, cs)) {
            textFilesCopied++;
        }
    }
    return true;
}

From source file:it.TestCustomFields.java

@Test
public void importingWithRadioCustomField() {
    final String cid = StringUtils.removeStart(
            administration.customFields().addCustomField(RADIOBUTTONS_CF_TYPE, "Select"),
            FieldManager.CUSTOM_FIELD_PREFIX);
    administration.customFields().addOptions(cid, "Core", "Subsystem", "API", "UX");

    assertSelectOrRadio();// w  w w  .  j  a  v  a 2s . c o  m
}

From source file:hydrograph.ui.expression.editor.enums.DataTypes.java

public static String getDataTypefromString(String value) {
    for (DataTypes dataType : DataTypes.values()) {
        if (StringUtils.equalsIgnoreCase(dataType.reflectionValue, value)) {
            return dataType.getDataTypeName();
        } else if (StringUtils.containsIgnoreCase(value, dataType.toString())) {
            return dataType.getDataTypeName();
        }// ww  w.  j a v  a 2s . c o m
    }
    return StringUtils.removeStart(value, Constants.DATA_TYPE_PREFIX_FOR_SOUCE_CODE);
}

From source file:hudson.plugins.clearcase.AbstractClearCaseScm.java

/**
 * Return string array containing the paths in the view that should be used when polling for changes.
 * @param variableResolver TODO//from   w ww  .  j  a  va2s .  co  m
 * @param build TODO
 * @param launcher TODO
 * @return string array that will be used by the lshistory command and for constructing the config spec, etc.
 * @throws InterruptedException
 * @throws IOException
 */
public String[] getViewPaths(VariableResolver<String> variableResolver, AbstractBuild build, Launcher launcher)
        throws IOException, InterruptedException {
    String loadRules = getLoadRules(variableResolver);
    if (StringUtils.isBlank(loadRules)) {
        return null;
    }

    String[] rules = loadRules.split("[\\r\\n]+");
    for (int i = 0; i < rules.length; i++) {
        String rule = rules[i];
        // Remove "load " from the string, just in case.
        rule = StringUtils.removeStart(rule, "load ");
        // Remove "\\", "\" or "/" from the load rule. (bug#1706) Only if
        // the view is not dynamic
        // the user normally enters a load rule beginning with those chars
        rule = StringUtils.stripStart(rule, "\\/");
        rules[i] = rule;
    }
    return rules;
}

From source file:ips1ap101.lib.core.app.FiltroBusqueda.java

public String toString(Map<String, String> map) {
    String where = StringUtils.EMPTY;
    String token;//from ww  w  .j ava2  s. co  m
    for (CriterioBusqueda criterio : criterios) {
        token = criterio.toString(map);
        where += StringUtils.isBlank(token) ? "" : conjuncion.palabra() + token;
    }
    for (FiltroBusqueda filtro : filtros) {
        token = filtro.toString(map);
        where += StringUtils.isBlank(token) ? "" : conjuncion.palabra() + token;
    }
    where = StringUtils.removeStart(where, conjuncion.palabra());
    return StringUtils.isBlank(where) ? null : "(" + where.trim() + ")";
}

From source file:com.activecq.experiments.redis.impl.RedisSessionUtilImpl.java

protected Set<String> getAttributeNames(final String sessionId) {
    if (StringUtils.isBlank(sessionId)) {
        return new HashSet<String>();
    }/*from www  .  j av  a  2  s . c  o  m*/
    final String indexKey = this.getIndexKey(sessionId);

    final Jedis jedis = this.getJedis();

    try {
        final Set<String> members = jedis.smembers(indexKey);
        this.updateExpiration(sessionId);

        final Set<String> attributes = new HashSet<String>();
        final String remove = this.getAttrKeyPrefix(sessionId);

        for (final String member : members) {
            final String tmp = StringUtils.removeStart(member, remove);
            attributes.add(tmp);
        }

        return attributes;
    } finally {
        this.returnJedis(jedis);
    }
}

From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.ChecksumGeneratorImpl.java

/**
 * Generates the relative key used for tracking nodes and properties.
 * @param aggregatePath the absolute path of the node being aggregated.
 * @param path the path of the item being checksumed
 * @return the key/*from w  w  w  .  j  a v a  2  s . co  m*/
 */
protected String getChecksumKey(String aggregatePath, String path) {
    if ("/".equals(aggregatePath) && "/".equals(path)) {
        return "/";
    } else if ("/".equals(aggregatePath)) {
        return path;
    }

    String baseNodeName = Text.getName(aggregatePath);
    String relPath = StringUtils.removeStart(path, aggregatePath);

    return baseNodeName + relPath;
}

From source file:com.intellij.lang.jsgraphql.ide.documentation.JSGraphQLDocumentationProvider.java

@Nullable
private String createQuickNavigateDocumentation(PsiElement element, boolean fullDocumentation) {
    if (!isDocumentationSupported(element)) {
        return null;
    }/* ww w.ja  v  a2 s.  c  o  m*/
    if (element instanceof JSGraphQLDocumentationPsiElement) {
        JSGraphQLDocumentationPsiElement docElement = (JSGraphQLDocumentationPsiElement) element;
        return getTypeDocumentation(docElement);
    }

    if (element instanceof JSGraphQLNamedPsiElement) {

        final Project project = element.getProject();

        if (element instanceof JSGraphQLNamedPropertyPsiElement) {
            final JSGraphQLNamedPropertyPsiElement propertyPsiElement = (JSGraphQLNamedPropertyPsiElement) element;
            String typeName = JSGraphQLSchemaLanguageProjectService.getService(project)
                    .getTypeName(propertyPsiElement);
            if (typeName == null) {
                // in structure view we don't get the schema psi element, so try to find it using the reference
                final PsiReference reference = propertyPsiElement.getReference();
                if (reference != null) {
                    final PsiElement schemaReference = reference.resolve();
                    if (schemaReference instanceof JSGraphQLNamedPropertyPsiElement) {
                        typeName = JSGraphQLSchemaLanguageProjectService.getService(project)
                                .getTypeName((JSGraphQLNamedPropertyPsiElement) schemaReference);
                    } else if (schemaReference instanceof JSGraphQLSchemaFile) {
                        // field belongs to a built in type which isn't shown in the schema file
                        // hence our reference to the file -- see JSGraphQLSchemaLanguageProjectService.getReference()
                        final String buffer = element.getContainingFile().getText();
                        final LogicalPosition pos = getTokenPos(buffer, element);
                        final String environment = JSGraphQLLanguageInjectionUtil
                                .getEnvironment(element.getContainingFile());
                        final TokenDocumentationResponse tokenDocumentation = JSGraphQLNodeLanguageServiceClient
                                .getTokenDocumentation(buffer, pos.line, pos.column, project, environment);
                        if (tokenDocumentation != null) {
                            String doc = "";
                            if (tokenDocumentation.getDescription() != null) {
                                if (tokenDocumentation.getType() != null
                                        && !JSGraphQLSchemaLanguageProjectService.SCALAR_TYPES
                                                .contains(tokenDocumentation.getType())) {
                                    doc += "<div style=\"margin-bottom: 4px\">"
                                            + tokenDocumentation.getDescription() + "</div>";
                                }
                            }
                            doc += "<code>" + element.getText() + ": "
                                    + getTypeHyperLink(tokenDocumentation.getType()) + "</code>";
                            return getDocTemplate(fullDocumentation).replace("${body}", doc);
                        }
                    }
                }
            }
            if (typeName != null) {
                final TokenDocumentationResponse fieldDocumentation = JSGraphQLNodeLanguageServiceClient
                        .getFieldDocumentation(typeName, propertyPsiElement.getName(), project);
                if (fieldDocumentation != null) {
                    String doc = "";
                    if (fieldDocumentation.getDescription() != null) {
                        doc += "<div style=\"margin-bottom: 4px\">"
                                + StringEscapeUtils.escapeHtml(fieldDocumentation.getDescription()) + "</div>";
                    }
                    String typeNameOrLink = fullDocumentation ? getTypeHyperLink(typeName) : typeName;
                    doc += "<code>" + typeNameOrLink + " <b>" + element.getText() + "</b>: "
                            + getTypeHyperLink(fieldDocumentation.getType()) + "</code>";
                    return getDocTemplate(fullDocumentation).replace("${body}", doc);
                }
            }
        } else if (element instanceof JSGraphQLNamedTypePsiElement) {
            if (((JSGraphQLNamedTypePsiElement) element).isDefinition()) {
                if (element.getParent() instanceof JSGraphQLFragmentDefinitionPsiElement) {
                    // the named type represents the name of a fragment definition,
                    // so return doc along the lines of 'fragment MyFrag on SomeType'
                    final StringBuilder doc = new StringBuilder("<code>fragment ");
                    doc.append("<b>").append(element.getText()).append("</b>");
                    final JSGraphQLNamedTypePsiElement fragmentType = PsiTreeUtil.getNextSiblingOfType(element,
                            JSGraphQLNamedTypePsiElement.class);
                    if (fragmentType != null) {
                        doc.append(" on ").append(getTypeHyperLink(fragmentType.getName()));
                    }
                    doc.append("</code>");
                    return getDocTemplate(fullDocumentation).replace("${body}", doc);
                }
            }
            if (fullDocumentation) {
                final PsiManager psiManager = PsiManager.getInstance(project);
                final String link = GRAPHQL_DOC_PREFIX + "/" + GRAPHQL_DOC_TYPE + "/" + element.getText();
                final PsiElement documentationElement = getDocumentationElementForLink(psiManager, link,
                        element);
                if (documentationElement instanceof JSGraphQLDocumentationPsiElement) {
                    return getTypeDocumentation((JSGraphQLDocumentationPsiElement) documentationElement);
                }
            }
            TypeDocumentationResponse typeDocumentation = JSGraphQLNodeLanguageServiceClient
                    .getTypeDocumentation(element.getText(), project);
            if (typeDocumentation != null) {
                String doc = "";
                if (typeDocumentation.description != null) {
                    doc += "<div style=\"margin-bottom: 4px\">"
                            + StringEscapeUtils.escapeHtml(typeDocumentation.description) + "</div>";
                }
                doc += "<code><b>" + element.getText() + "</b>";
                if (!ContainerUtil.isEmpty(typeDocumentation.interfaces)) {
                    doc += ": ";
                    for (int i = 0; i < typeDocumentation.interfaces.size(); i++) {
                        if (i > 0) {
                            doc += ", ";
                        }
                        doc += getTypeHyperLink(typeDocumentation.interfaces.get(i));
                    }
                }
                doc += "</code>";
                return getDocTemplate(fullDocumentation).replace("${body}", doc);
            }
        } else if (element instanceof JSGraphQLAttributePsiElement) {
            String doc = "";
            PsiElement prevLeaf = PsiTreeUtil.prevLeaf(element);
            String documentation = "";
            while (prevLeaf instanceof PsiWhiteSpace || prevLeaf instanceof PsiComment) {
                documentation = StringUtils.removeStart(prevLeaf.getText(), "# ") + documentation;
                prevLeaf = PsiTreeUtil.prevLeaf(prevLeaf);
            }
            documentation = documentation.trim();
            if (StringUtils.isNotBlank(documentation)) {
                doc += "<div style=\"margin-bottom: 4px\">" + StringEscapeUtils.escapeHtml(documentation)
                        + "</div>";
            }
            doc += "<code>" + element.getText();
            PsiElement nextLeaf = PsiTreeUtil.nextLeaf(element);
            // include the attribute type (stopping at newline, ",", and ")")
            while (nextLeaf != null && !nextLeaf.getText().contains("\n") && !nextLeaf.getText().contains(",")
                    && !nextLeaf.getText().contains(")")) {
                doc += nextLeaf.getText();
                nextLeaf = PsiTreeUtil.nextLeaf(nextLeaf);
            }
            doc += "</code>";
            return getDocTemplate(fullDocumentation).replace("${body}", doc);
        }

    } else if (element instanceof JSGraphQLEndpointDocumentationAware) {
        final JSGraphQLEndpointDocumentationAware documentationAware = (JSGraphQLEndpointDocumentationAware) element;
        final String documentation = documentationAware.getDocumentation(fullDocumentation);
        String doc = "";
        if (documentation != null) {
            doc += "<div style=\"margin-bottom: 4px\">" + StringEscapeUtils.escapeHtml(documentation)
                    + "</div>";
        }
        doc += "<code>" + documentationAware.getDeclaration() + "</code>";
        return getDocTemplate(fullDocumentation).replace("${body}", doc);
    }

    return null;
}