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

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

Introduction

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

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

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

A null source string will return null .

Usage

From source file:com.thruzero.common.core.infonode.builder.TokenStreamInfoNodeBuilder.java

/** Remove single quotes from start and end of the given string. */
private String trimQuotes(String value) {
    // TODO-p1(george) Rewrite this using RegEx
    value = StringUtils.trimToNull(value);
    value = StringUtils.removeStart(value, "'");
    value = StringUtils.removeStart(value, "\"");
    value = StringUtils.removeEnd(value, "'");
    value = StringUtils.removeEnd(value, "\"");

    return value;
}

From source file:it.attocchi.utils.jdbc.QueryBuilderSqlServer.java

/**
 * Supporta la ricerca str* *str str che corrisponde a like %%
 * /*from   w  w w  .  ja  v  a  2 s .c o m*/
 * @param campo
 * @param semeRicerca
 * @return
 */
public static String likeSimple(String campo, String semeRicerca) {
    StringBuilder res = new StringBuilder();

    if (semeRicerca.startsWith(QueryBuilderSqlServer.RICERCA_STRING_CHAR)
            && semeRicerca.endsWith(QueryBuilderSqlServer.RICERCA_STRING_CHAR)) {
        /* CASO "ciao" */
        semeRicerca = StringUtils.removeStart(semeRicerca, QueryBuilderSqlServer.RICERCA_STRING_CHAR);
        semeRicerca = StringUtils.removeEnd(semeRicerca, QueryBuilderSqlServer.RICERCA_STRING_CHAR);

        res.append(campo + " = '" + encodeStringSQL(semeRicerca) + "'");
    } else if (semeRicerca.endsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CASO ciao* */
        semeRicerca = semeRicerca.replace(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR, "");

        res.append(campo + " LIKE '" + encodeStringSQL(semeRicerca) + "%'");
    } else if (semeRicerca.startsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CASO *ciao */
        semeRicerca = semeRicerca.replace(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR, "");

        res.append(campo + " LIKE '%" + encodeStringSQL(semeRicerca) + "'");
    } else {
        /* CASO ciao */
        res.append(campo + " LIKE '%" + encodeStringSQL(semeRicerca) + "%'");
    }

    return res.toString();
}

From source file:gobblin.data.management.copy.hive.HiveDataset.java

/***
 * Extract token value from source entity, where token value is represented by a token in the source entity.
 *
 * Eg.//from ww  w .ja  v  a  2 s . com
 * Source Entity  : prod_tableName_avro
 * Source Template: prod_$LOGICAL_TABLE_avro
 * Token          : $LOGICAL_TABLE
 * Extracted Value: tableName
 *
 * @param sourceEntity      Source entity (typically a table or database name).
 * @param sourceTemplate    Source template representing the source entity.
 * @param token             Token representing the value to extract from the source entity using the template.
 * @return Extracted token value from the source entity.
 */
@VisibleForTesting
protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) {
    Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank");
    Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank");
    Preconditions.checkArgument(sourceTemplate.contains(token),
            String.format("Source template: %s should contain token: %s", sourceTemplate, token));

    String extractedValue = sourceEntity;
    List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate));

    extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0));
    extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1));

    return extractedValue;
}

From source file:com.qq.tars.service.monitor.TARSStatMonitorService.java

private MultiKeyMap call(List<String> groupBy, List<String> conditions) throws IOException {
    String template = "{\"groupby\":%s,\"method\":\"query\",\"dataid\":\"tars_stat\","
            + "\"filter\":%s,\"indexs\":[\"succ_count\",\"timeout_count\",\"exce_count\",\"total_time\"]}";

    ObjectMapper mapper = new ObjectMapper();
    String request = String.format(template, mapper.writeValueAsString(groupBy),
            mapper.writeValueAsString(conditions));

    List<Pair<String, Integer>> addrs = adminService.getEndpoints("tars.tarsquerystat.NoTarsObj");
    if (addrs.isEmpty()) {
        throw new IOException("tars.tarsquerystat.NoTarsObj not found");
    }//ww  w.j  a  va  2  s  . com

    Pair<String, Integer> addr = addrs.get(0);
    log.info("tars.tarsquerystat.NoTarsObj, use {}:{}", addr.getLeft(), addr.getRight());

    TCPClient client = new TCPClient(addr.getLeft(), addr.getRight());
    List<String> response = client.sendAndReceive(request.getBytes(), 60000);

    log.debug("request={}", request);
    log.debug("reponse={}", StringUtils.join(response, "\n"));

    String line1 = response.get(0);
    if (!line1.startsWith("Ret:")) {
        throw new IOException(String.format("line #1, doesn't start with \"Ret:\", line=%s", line1));
    }
    int ret = Integer.parseInt(line1.substring(line1.lastIndexOf(':') + 1));
    if (ret == -1) {
        throw new IOException(String.format("line #1, Ret=%s", ret));
    }

    String line6 = response.get(5);
    if (!line6.startsWith("linecount:")) {
        throw new IOException(String.format("line #6, doesn't start with \"linecount:\", line=%s", line6));
    }
    int count = Integer.parseInt(line6.substring(line6.lastIndexOf(':') + 1));
    if (count + 7 != response.size()) {
        throw new IOException(String.format("line #6, size not match, %s vs %s", count + 7, response.size()));
    }

    String lastLine = response.get(response.size() - 1);
    if (!"endline".equals(lastLine)) {
        throw new IOException(
                String.format("line #%s, doesn't equal to \"endline\", line=%s", response.size(), lastLine));
    }

    MultiKeyMap result = new MultiKeyMap();
    for (int i = 6; i < response.size() - 1; i++) {
        String line = StringUtils.removeEnd(response.get(i), ",");
        String[] tokens = line.split(",");
        if (tokens.length != groupBy.size() + 4) {
            throw new IOException(String.format("line format error, line=%s", line));
        }

        String[] key = new String[groupBy.size()];
        int j = 0;
        for (; j < key.length; j++) {
            key[j] = tokens[j];
        }

        long[] value = new long[] { Long.parseLong(tokens[j++]), Long.parseLong(tokens[j++]),
                Long.parseLong(tokens[j++]), Long.parseLong(tokens[j]) };
        result.put(new MultiKey(key), value);
    }
    return result;
}

From source file:info.magnolia.ui.form.field.upload.basic.BasicUploadField.java

/**
 * Add File Name.<br>/*from ww w . j a  v  a2 s  .com*/
 * If editFileName is true, display an Input Text Field. <br>
 * Else display a simple label.
 */
protected Component getFileDetailFileName() {
    // Build the file name without the extension
    final boolean hasExtension = StringUtils.isNotBlank(getValue().getExtension());
    final String extension = hasExtension ? "." + getValue().getExtension() : "";
    String fileName = StringUtils.removeEnd(getValue().getFileName(), extension);

    if (this.editFileName && !isReadOnly()) {
        TextField textField = new TextField(i18n.translate(fileDetailNameCaption), fileName);
        textField.setNullRepresentation("");
        textField.setCaption(i18n.translate(fileDetailNameCaption));
        textField.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                Object newFileNameObject = event.getProperty().getValue();
                String newFileName = (newFileNameObject != null
                        && StringUtils.isNotBlank(newFileNameObject.toString())) ? newFileNameObject.toString()
                                : UploadReceiver.INVALID_FILE_NAME;
                getValue().setFileName(newFileName + extension);
                getPropertyDataSource().setValue(getValue());
            }
        });
        return textField;
    } else {
        Label label = new Label("", ContentMode.HTML);
        label.setCaption(i18n.translate(fileDetailNameCaption));
        label.setValue(fileName);
        return label;
    }
}

From source file:it.attocchi.utils.jdbc.QueryBuilderSqlServer.java

/**
 * ciao esegue ricerca = ciao* esegue ricerca ciao% *ciao esegue ricerca
 * %ciao *ciao* esegue ricerca %ciao%/*  w ww .ja  v a 2 s  .c  o m*/
 * 
 * @param campo
 * @param semeRicerca
 * @return
 */
public static String likeOrEquaByUser(String campo, String semeRicerca) {
    StringBuilder res = new StringBuilder();

    if (semeRicerca.startsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)
            && semeRicerca.endsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CASO "ciao" */
        semeRicerca = StringUtils.removeStart(semeRicerca, QueryBuilderSqlServer.RICERCA_JOLLY_CHAR);
        semeRicerca = StringUtils.removeEnd(semeRicerca, QueryBuilderSqlServer.RICERCA_JOLLY_CHAR);
        res.append(campo + " LIKE '%" + encodeStringSQL(semeRicerca) + "%'");
    } else if (semeRicerca.endsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CASO ciao* */
        semeRicerca = semeRicerca.replace(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR, "");
        res.append(campo + " LIKE '" + encodeStringSQL(semeRicerca) + "%'");
    } else if (semeRicerca.startsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CASO *ciao */
        semeRicerca = semeRicerca.replace(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR, "");
        res.append(campo + " LIKE '%" + encodeStringSQL(semeRicerca) + "'");
    } else {
        /* CASO ciao */
        res.append(campo + " = '" + encodeStringSQL(semeRicerca) + "'");
    }

    return res.toString();
}

From source file:cn.calm.osgi.conter.FelixOsgiHost.java

protected void addExportedPackages(Properties strutsConfigProps, Properties configProps) {
    String[] rootPackages = StringUtils.split(strutsConfigProps.getProperty("scanning.package.includes"), ",");
    List<String> exportedPackages = new ArrayList<String>();
    // build a list of subpackages
    StringBuilder strB = new StringBuilder();
    //      org.osgi.framework;version="[1.4,2)"
    for (String rootPackage : rootPackages) {
        String sp[] = StringUtils.split(rootPackage, ";");
        strB.delete(0, strB.length());//from  w ww.j  a v  a2 s  .  co  m
        strB.append(sp[0]);
        strB.append(";version=\"");
        try {
            strB.append(sp[1]);
        } catch (Exception e) {
            strB.append("0.0.0");
        }
        strB.append("\"");
        exportedPackages.add(strB.toString());
    }
    //
    //      // make a string with the exported packages and add it to the system
    //      // properties
    if (!exportedPackages.isEmpty()) {
        String systemPackages = (String) configProps.get(Constants.FRAMEWORK_SYSTEMPACKAGES);
        systemPackages = StringUtils.removeEnd(systemPackages, ",") + ","
                + StringUtils.join(exportedPackages, ",");
        configProps.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages);
    }
    System.out.println(exportedPackages);
}

From source file:com.neophob.sematrix.glue.Collector.java

/**
 * load a saved preset.//w  ww  . j  a  v a  2s.  co  m
 *
 * @param preset the new current status
 */
public void setCurrentStatus(List<String> preset) {
    setLoadingPresent(true);
    for (String s : preset) {
        s = StringUtils.trim(s);
        s = StringUtils.removeEnd(s, ";");
        MessageProcessor.processMsg(StringUtils.split(s, ' '), false);
    }
    setLoadingPresent(false);
}

From source file:com.moscona.dataSpace.DataSpace.java

/**
 * Gets the name space part of a dot separated name.
 * "my.name" => "my"//w w w . ja v a 2  s  .  c  om
 * "name" => ""
 * @param name
 * @return
 */
private String getNameSpace(String name) {
    String var = getVariable(name);
    return StringUtils.removeEnd(StringUtils.removeEnd(name, var), ".");
}

From source file:it.attocchi.utils.jdbc.QueryBuilderSqlServer.java

/**
 * //from   w  w w  .ja v a2 s . c  o  m
 * @param campo
 * @param semeRicerca
 * @param multipleValuesSeparator
 * @return
 */
public static String likeOrEquaByUser2(String campo, String semeRicerca, String multipleValuesSeparator) {
    StringBuilder res = new StringBuilder();

    if (semeRicerca.startsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)
            && semeRicerca.endsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CASO *ciao* */
        semeRicerca = StringUtils.removeStart(semeRicerca, QueryBuilderSqlServer.RICERCA_JOLLY_CHAR);
        semeRicerca = StringUtils.removeEnd(semeRicerca, QueryBuilderSqlServer.RICERCA_JOLLY_CHAR);
        res.append(campo + " LIKE '%" + multipleValuesSeparator + "%" + encodeStringSQL(semeRicerca) + "%"
                + multipleValuesSeparator + "%'");
    } else if (semeRicerca.endsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CERCO ciao* quindi LIKE '%;%CIAO;%' */
        semeRicerca = StringUtils.removeEnd(semeRicerca, QueryBuilderSqlServer.RICERCA_JOLLY_CHAR);
        res.append(campo + " LIKE '%" + multipleValuesSeparator + encodeStringSQL(semeRicerca) + "%"
                + multipleValuesSeparator + "%'");
    } else if (semeRicerca.startsWith(QueryBuilderSqlServer.RICERCA_JOLLY_CHAR)) {
        /* CERCO *ciao quindi LIKE '%;%CIAO;%' */
        semeRicerca = StringUtils.removeStart(semeRicerca, QueryBuilderSqlServer.RICERCA_JOLLY_CHAR);
        res.append(campo + " LIKE '%" + multipleValuesSeparator + "%" + encodeStringSQL(semeRicerca)
                + multipleValuesSeparator + "%'");
    } else {
        /* CERCO ciao quindi LIKE '%;ciao;%' */
        res.append(campo + " LIKE '%" + multipleValuesSeparator + encodeStringSQL(semeRicerca)
                + multipleValuesSeparator + "%'");
    }

    return res.toString();
}