Example usage for com.google.common.base Splitter onPattern

List of usage examples for com.google.common.base Splitter onPattern

Introduction

In this page you can find the example usage for com.google.common.base Splitter onPattern.

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter onPattern(String separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching a given pattern (regular expression) to be a separator.

Usage

From source file:org.geoserver.wps.gs.GeorectifyCoverage.java

/**
 * Split a whitespace-separated list into a list of strings, discarding all excess whitespace.
 * No empty strings are returned. If the string is empty or contains only whitespace, the
 * returned list will be empty.//from   ww  w .j av a  2s. c o m
 */
private static List<String> splitToList(String s) {
    return Splitter.onPattern("\\s+").omitEmptyStrings().splitToList(s);
}

From source file:fr.obeo.intent.specification.parser.SpecificationParser.java

/**
 * Text to parse : "Feature: MyFeature1/*from w w w.java 2s .c  om*/
 * [ReferencedFeature1,ReferencedFeature2] Feature: MyFeature2
 * [ReferencedFeature2,ReferencedFeature3]"
 * 
 * @param intentSection
 * @param validElements
 * @return
 */
private void parseFeatures(IntentSection intentSection, StringBuffer validElements) {
    // Get valid features
    StringBuffer validFeatures = new StringBuffer();
    for (String element : Splitter.onPattern("\r?\n").trimResults().omitEmptyStrings().split(validElements)) {
        if (isFeature(element)) {
            validFeatures.append(element + "\n");
        }
    }

    // "Feature:"
    final String featurePattern = SpecificationKeyword.FEATURE.value + COLON;

    for (String description : Splitter.onPattern(featurePattern).trimResults().omitEmptyStrings()
            .split(validFeatures)) {
        Map<String, String> result = Splitter.onPattern("\r?\n").trimResults().omitEmptyStrings()
                .withKeyValueSeparator(COLON).split(featurePattern + description);
        String featureDescription = result.get(SpecificationKeyword.FEATURE.value);
        String featureName;
        if (featureDescription.contains(OPEN_BRACKET)) {
            featureName = featureDescription.substring(0, featureDescription.indexOf(OPEN_BRACKET)).trim();
        } else {
            featureName = featureDescription;
        }
        NamedElement namedElement = getNamedElement(featureName, Feature.class);
        Feature feature = null;
        if (namedElement == null) {
            feature = specificationFactory.createFeature();
            feature.setName(featureName);
            specification.getFeatures().add((Feature) feature);
            parsedElements.add(new ParsedElement(intentSection, feature));
        } else if (namedElement instanceof Feature) {
            feature = (Feature) namedElement;
        } else {
            throw new UnsupportedOperationException();
        }

        if (featureDescription.contains(OPEN_BRACKET)) {
            String features = featureDescription.substring(featureDescription.indexOf(OPEN_BRACKET) + 1,
                    featureDescription.indexOf(CLOSE_BRACKET));
            for (String refFeatureName : Splitter.on(COMMA).trimResults().omitEmptyStrings().split(features)) {
                namedElement = getNamedElement(refFeatureName, Feature.class);
                Feature refFeature = null;
                if (namedElement == null) {
                    refFeature = specificationFactory.createFeature();
                    refFeature.setName(refFeatureName);
                    specification.getFeatures().add(refFeature);
                    parsedElements.add(new ParsedElement(intentSection, refFeature));
                } else if (namedElement instanceof Feature) {
                    refFeature = (Feature) namedElement;
                } else {
                    throw new UnsupportedOperationException();
                }
                refFeature.getRefFeatures().add((Feature) feature);
            }
        }
    }
}

From source file:no.asgari.civilization.server.excel.ItemReader.java

private static Iterable<String> split(String string) {
    return Splitter.onPattern(",|\\.").omitEmptyStrings().trimResults().split(string);
}