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:de.micromata.tpsb.doc.parser.japa.handler.AddCommentMethodCallHandler.java

@Override
public void handle(MethodCallExpr node, ParserContext ctx) {
    List<Expression> methodArgs = node.getArgs();
    if (methodArgs == null || methodArgs.size() != 1) {
        return;//from   w  w w . j a v  a  2 s . c o  m
    }
    String comment = methodArgs.iterator().next().toString();
    if (StringUtils.isBlank(comment) == true) {
        return;
    }

    if (comment.startsWith(QUOTE) == true) {
        comment = StringUtils.removeStart(comment, QUOTE);
    }

    if (comment.endsWith(QUOTE) == true) {
        comment = StringUtils.removeEnd(comment, QUOTE);
    }

    ctx.setCurrentInlineComment(comment);
}

From source file:fathom.test.FathomTest.java

/**
 * Returns the complete URL of the specified path for the running Fathom TEST instance.
 *
 * @param path//  w w w  .  j  a va2  s . c  om
 * @return an url
 */
protected String urlFor(String path) {
    String url = StringUtils.removeEnd(RestAssured.baseURI, "/") + StringUtils.prependIfMissing(path, "/");
    return url;
}

From source file:de.blizzy.documentr.markdown.macro.impl.TabMacro.java

static List<TabData> getTabs(String s) {
    String[] parts = StringUtils.splitByWholeSeparator(s, TAB_START_MARKER);
    List<TabData> tabs = Lists.newArrayList();
    for (String part : parts) {
        part = StringUtils.removeEnd(part, TAB_END_MARKER);
        if (StringUtils.isNotBlank(part)) {
            TabData tabData = TabData.deserialize(part);
            tabs.add(tabData);//from  w  w  w.j a  va 2s  . c o  m
        }
    }
    return tabs;
}

From source file:de.bmarwell.j9kwsolver.util.ResponseUtils.java

/**
 * @param response The response sent by the server.
 * @return null if response is null or empty, else a HashMap.
 *//*from  www. j  av a 2s .  c  o  m*/
public static Map<String, Integer> stringResponseToIntMap(final String response) {
    Map<String, Integer> result = new HashMap<String, Integer>();

    if (StringUtils.isEmpty(response)) {
        /* 
         * Response should be like so:
         * worker=15|avg24h=12s|avg1h=12s|avg15m=13s|avg5m=13s|inwork=8|
         *     queue=0|queue1=0|queue2=0|workermouse=13|
         *     workerconfirm=14|workertext=13
         */
        return null;
    }

    List<String> serverstatelist = Arrays.asList(StringUtils.split(response, '|'));

    /* Iterate each item in response */
    for (String item : serverstatelist) {
        String[] keyValue = StringUtils.split(item, '=');
        int value = 0;

        if (keyValue.length != 2) {
            LOG.warn("Key-Value splitting on '=' doesn't return 2 items: {}.", item);
            continue;
        }

        String key = keyValue[0];
        String textvalue = keyValue[1];
        textvalue = StringUtils.removeEnd(textvalue, "s");

        if (!NumberUtils.isDigits(textvalue)) {
            LOG.warn("Key-Value where value is non-numeric: {}", item);
            continue;
        } else {
            value = NumberUtils.toInt(textvalue);
        }

        result.put(key, value);
    }

    return result;
}

From source file:hoot.services.db.postgres.PostgresUtils.java

/**
 * Converts an hstore Postgres object to a string map
 * /* www.  j av  a  2s . c  o  m*/
 * @param postgresObj a Postgres object containing an hstore
 * @return a string map with the hstore's data
 * @throws Exception
 */
public static Map<String, String> postgresObjToHStore(final PGobject postgresObj) throws Exception {
    //type = hstore
    //value = "key 1"=>"val 1", "key 2"=>"val 2"

    //TODO: don't understand why this string doesn't match up
    //System.out.println(postgresObj.getType());
    //if (postgresObj.getType().equals("hstore"))
    //{
    //throw new Exception("Invalid PGobject type.  Expected: hstore");
    //}

    Map<String, String> hstore = new HashMap<String, String>();
    if (postgresObj != null && postgresObj.getValue() != null
            && StringUtils.trimToNull(postgresObj.getValue()) != null) {
        String[] vals = postgresObj.getValue().split(",");
        for (int i = 0; i < vals.length; i++) {
            String[] pair = vals[i].split("=>");
            if (pair.length == 2) {
                //remove the quotes at the very beginning and end of the string
                String key = pair[0].trim();
                key = StringUtils.removeStart(key, "\"");
                key = StringUtils.removeEnd(key, "\"");
                String val = pair[1].trim();
                val = StringUtils.removeStart(val, "\"");
                val = StringUtils.removeEnd(val, "\"");
                hstore.put(key, val);
            }
        }
    }
    return hstore;
}

From source file:de.knightsoftnet.validators.client.gin.ServiceModule.java

@Provides
@RestApplicationPath/*from  w  ww .jav  a 2  s . co  m*/
String getApplicationPath() {
    return StringUtils.removeEnd(
            StringUtils.removeEnd(StringUtils.removeEnd(GWT.getModuleBaseURL(), "/"), GWT.getModuleName()),
            "/");
}

From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java

public SwaggerServlet(String contextPath) {
    this.rootContextPath = contextPath;

    while (rootContextPath.endsWith("*") || rootContextPath.endsWith("/")) {
        rootContextPath = StringUtils.removeEnd(rootContextPath, "*");
        rootContextPath = StringUtils.removeEnd(rootContextPath, "/");
    }/* ww  w.  j  av a  2  s . c o  m*/
}

From source file:jongo.sql.dialect.H2Dialect.java

@Override
public String toStatementString(Insert insert) {
    if (insert.getColumns().isEmpty())
        throw new IllegalArgumentException("An insert query can't be empty");

    final StringBuilder b = new StringBuilder("INSERT INTO ");
    b.append(insert.getTable().getDatabase()).append(".");
    b.append(insert.getTable().getName());
    if (!insert.getColumns().isEmpty()) {
        b.append(" (");
        b.append(StringUtils.join(insert.getColumns().keySet(), ","));
        b.append(") VALUES (");
        b.append(StringUtils.removeEnd(StringUtils.repeat("?,", insert.getColumns().size()), ","));
        b.append(")");
    }//  w  w  w  .ja  v a2 s.  c  om
    l.debug(b.toString());
    return b.toString();
}

From source file:jongo.sql.dialect.SQLDialect.java

@Override
public String toStatementString(final Insert insert) {
    if (insert.getColumns().isEmpty())
        throw new IllegalArgumentException("An insert query can't be empty");

    final StringBuilder b = new StringBuilder("INSERT INTO ");
    b.append(insert.getTable().getName());
    if (!insert.getColumns().isEmpty()) {
        b.append(" (");
        b.append(StringUtils.join(insert.getColumns().keySet(), ","));
        b.append(") VALUES (");
        b.append(StringUtils.removeEnd(StringUtils.repeat("?,", insert.getColumns().size()), ","));
        b.append(")");
    }//from  w  w  w.  j  a  va2 s.  c  o  m
    l.debug(b.toString());
    return b.toString();
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.util.URLUtil.java

/**
 * Returns a URL created from the given params without postfix
 *
 * @param urlParams given params//from   w ww. j a v a  2  s . c  o  m
 * @return URL with the given params
 */
public static String buildURLForParamsWithoutPostfix(String... urlParams) {
    String url = buildURLForParams(urlParams);
    return StringUtils.removeEnd(url, "/");
}