Example usage for java.lang String replaceFirst

List of usage examples for java.lang String replaceFirst

Introduction

In this page you can find the example usage for java.lang String replaceFirst.

Prototype

public String replaceFirst(String regex, String replacement) 

Source Link

Document

Replaces the first substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.textnormalizer.frequency.ExpressiveLengtheningNormalizer.java

public String getBestReplacement(String token) throws IOException {
    Pattern pattern = Pattern.compile("([a-zA-Z])\\1{1,}");
    Matcher matcher = pattern.matcher(token);

    // In case there are no abnormalities
    if (!matcher.find())
        return token;

    // Collecting the start points of all abnormal parts
    List<Integer> abnormalities = new ArrayList<Integer>();
    matcher.reset();//from   w  w  w  .j  a  v  a 2 s  . c  o  m
    while (matcher.find()) {
        abnormalities.add(matcher.start());
    }

    // splitting in parts starting with first character abnormalities
    List<String> parts = new ArrayList<String>();

    for (int i = 0; i < abnormalities.size(); i++) {
        // in case the token has only one abnormality
        if (abnormalities.size() == 1) {
            parts.add(token);
            break;
        }

        // first abnormality
        if (i == 0) {
            parts.add(token.substring(0, abnormalities.get(i + 1)));
            continue;
        }

        // last abnormality
        if (i == abnormalities.size() - 1) {
            parts.add(token.substring(abnormalities.get(i)));
            continue;
        }

        if (i < abnormalities.size() - 1) {
            parts.add(token.substring(abnormalities.get(i), abnormalities.get(i + 1)));
            continue;
        }
    }

    // Fills big list of arrays with all parts and their versions
    List<String[]> bigList = new ArrayList<String[]>();
    for (String part : parts) {
        String v1 = part.replaceFirst(pattern.pattern(), "$1");
        String v2 = part.replaceFirst(pattern.pattern(), "$1$1");
        String v3 = part.replaceFirst(pattern.pattern(), "$1$1$1");

        bigList.add(new String[] { v1, v2, v3 });
    }

    List<String> candidates = permute(bigList, 0, new ArrayList<String>(), "");

    return getMostFrequentCandidate(candidates);
}

From source file:org.openmrs.module.pharmacyapi.api.dispensation.validation.DispensationDrugAvailabilityRule.java

private String getFormattedMessage(final List<Drug> drugsWithoutStock) {

    String formattedString = StringUtils.EMPTY;
    for (final Drug drug : drugsWithoutStock) {
        formattedString += ", " + drug.getDisplayName();
    }/* www . j a  v a 2  s  .c om*/
    return formattedString.replaceFirst(",", "");
}

From source file:com.tera.common.dataload.xml.XMLDataLoadService.java

/**
 * @param directory//  w  ww  .  jav  a2  s.  c  om
 * @param clazz
 * @param xsdLocation
 * @param classLoader
 * @return
 */
protected final T loadFrom(String directory, String clazz, String xsdLocation, ClassLoader classLoader) {
    if (directory.startsWith("vc:")) {
        directory = directory.replaceFirst("vc:", "");
        return loadFromVirtual(directory, clazz, xsdLocation, classLoader);
    }
    return loadFromReal(directory, clazz, xsdLocation, classLoader);
}

From source file:org.gvnix.service.roo.addon.addon.util.WsdlParserUtils.java

/**
 * Get the local name of an element./*from w w  w  .  j a  v  a 2 s.c  om*/
 * <p>
 * Local name is the text after first namespace separator character. For
 * example, for element name soap12:address the local name is 'address'.
 * </p>
 * 
 * @param elementName An element name
 * @return Sufix of the name or name if not
 */
protected static String getLocalName(String elementName) {

    Validate.notNull(elementName, "Element name required");

    return elementName.replaceFirst(getNamespace(elementName) + NAMESPACE_SEPARATOR, "");
}

From source file:es.upv.grycap.opengateway.core.vertx.OgVerticleFactory.java

@Override
public Verticle createVerticle(final String verticleName, final ClassLoader classLoader) throws Exception {
    final String checkedVerticleName = requireNonNull(trimToNull(verticleName), "A non-empty name expected");
    final Verticle verticle = javaVerticleFactory.createVerticle(checkedVerticleName.replaceFirst(
            String.format("^%s:", prefix()), String.format("%s:", javaVerticleFactory.prefix())), classLoader);
    try {//from  w w  w . j a  v  a  2  s .c  o  m
        final Method method = verticle.getClass().getMethod("setLoadBalancer",
                new Class<?>[] { LoadBalancerClient.class });
        if (method != null)
            method.invoke(verticle, loadBalancerClient);
    } catch (NoSuchMethodException ignore) {
    }
    return verticle;
}

From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso.RDFServiceVirtuoso.java

private String tweakUpdateStringSyntax(String updateString) {
    if (updateString.startsWith("INSERT DATA")) {
        return updateString.replaceFirst("INSERT DATA", "INSERT");
    }/*from  w  w  w  . ja  v a  2 s  .com*/
    return updateString;
}

From source file:com.norconex.collector.http.crawler.CrawlURL.java

public final void setUrl(String url) {
    this.url = url;
    if (url != null) {
        this.urlRoot = url.replaceFirst("(.*?://.*?)(/.*)", "$1");
    } else {/* w ww  .j  a  v a  2 s .  co m*/
        this.urlRoot = null;
    }
}

From source file:com.ankang.report.pool.AbstractReportAliasPool.java

protected final String getAlias(String name) {

    if (!StringUtils.isEmpty(name) && !name.contains(".")) {
        return name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toLowerCase());
    }/*from w  w w .j  a  v  a2s  .  c om*/
    return name;
}

From source file:com.qcadoo.model.internal.HibernateServiceImpl.java

private InternalDataDefinition resolveDataDefinitionFromClassType(final String classType) {
    String[] tmp = classType.replaceFirst("com.qcadoo.model.beans.", "").split("\\.");
    String model = tmp[1].replaceFirst(tmp[0].substring(0, 1).toUpperCase(Locale.ENGLISH) + tmp[0].substring(1),
            "");/* w w w .j ava2  s  . com*/
    Preconditions.checkState(StringUtils.isNotBlank(model), "Can't parse model name from class' binary name.");
    model = model.substring(0, 1).toLowerCase(Locale.ENGLISH) + model.substring(1);
    return (InternalDataDefinition) dataDefinitionService.get(tmp[0], model);
}

From source file:com.domsplace.DomsCommands.Objects.Chat.DomsChatObject.java

public String compile() {
    String result = "{";

    List<DomsChatComponent> extras = new ArrayList<DomsChatComponent>();

    for (int i = 0; i < this.components.size(); i++) {
        if (this.components.get(i).getType().equals(ComponentType.EXTRA)) {
            extras.add(this.components.get(i));
            continue;
        }/*from   w w w .j av a  2  s  .  co  m*/
        result += this.components.get(i).compile();
        if (i < (this.components.size() - 1))
            result += ",";
    }

    if (extras.size() > 0) {
        if (!result.endsWith("{") && !result.endsWith(","))
            result += ",";
        result += ComponentType.EXTRA.getKey() + ":[";
        for (int i = 0; i < extras.size(); i++) {
            String compile = extras.get(i).compile();
            compile = compile.replaceFirst(ComponentType.EXTRA.getKey() + ":\\[", "");
            compile = Base.trim(compile, compile.length() - 1);
            result += compile;
            if (i < (extras.size() - 1))
                result += ",";
        }
        result += "]";
    }

    result += "}";
    return result;
}