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

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

Introduction

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

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter on(final Pattern separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching pattern to be a separator.

Usage

From source file:org.apache.isis.core.metamodel.facets.object.membergroups.annotprop.MemberGroupLayoutFacetProperties.java

static String[] asGroupList(Properties properties, final String key) {
    final String property = properties.getProperty(key);
    if (property == null) {
        return new String[0];
    }/*from w  w w .ja v  a2s .com*/
    final Iterable<String> split = Splitter.on(',').split(property);
    return Iterables.toArray(
            Iterables.filter(Iterables.transform(split, StringFunctions.TRIM), StringPredicates.NOT_EMPTY),
            String.class);
}

From source file:org.robotframework.ide.eclipse.main.plugin.launch.remote.RemoteConnectionStatusTracker.java

private static String indentMessage(final String message) {
    final List<String> msgLines = Splitter.on('\n').splitToList(message);
    return "\t" + String.join("\n\t", msgLines);
}

From source file:ilcc.ccgparser.utils.Utils.java

public static CCGJNode parseDrivString(String treeString, CCGJSentenceChart sent) {

    sent.setCcgDeriv(treeString);//w  ww  .ja  v a2  s .  c  o m
    Stack<CCGJNode> nodes = new Stack<>();
    Stack<Character> cStack = new Stack<>();
    char[] cArray = treeString.toCharArray();
    boolean foundOpenLessThan = false;
    int id = 0;

    for (Character c : cArray) {
        if (c == '<') {
            foundOpenLessThan = true;
        } else if (c == '>') {
            foundOpenLessThan = false;
        }

        if (c == ')' && !foundOpenLessThan) {
            StringBuilder sb = new StringBuilder();
            Character cPop = cStack.pop();
            while (cPop != '<') {
                sb.append(cPop);
                cPop = cStack.pop();
            }
            sb.append(cPop);
            // pop (
            cStack.pop();
            sb.reverse();
            String nodeString = sb.toString();
            // (<L (S/S)/NP IN IN In (S_113/S_113)/NP_114>)
            if (nodeString.charAt(1) == 'L') {
                CCGJNode node = new CCGJNode(id + 1, nodeString);
                sent.addCCGJNode(node);
                nodes.add(node);
                id++;
            } else if (nodeString.charAt(1) == 'T') {
                // (<T S/S 0 2> (<L (S/S)/NP IN IN In (S_113/S_113)/NP_114>)
                ArrayList<String> items = Lists.newArrayList(Splitter.on(CharMatcher.anyOf("<> ")).trimResults()
                        .omitEmptyStrings().split(nodeString));
                CCGJNode node = new CCGJNode();
                int childrenSize = Integer.parseInt(items.get(3));
                int headId = Integer.parseInt(items.get(2));
                node.setHeadId(headId);
                while (childrenSize > 0) {
                    node.addChild(nodes.pop(), 0);
                    childrenSize--;
                }
                String rescatstr = items.get(1);
                CCGcat rescat;
                childrenSize = Integer.parseInt(items.get(3));
                if (childrenSize == 1) {
                    CCGcat lcat = node.getChild(0).getCCGcat();
                    rescat = CCGcat.typeRaiseTo(lcat, rescatstr);
                    if (rescat == null)
                        rescat = CCGcat.typeChangingRule(lcat, rescatstr);
                } else {
                    CCGcat lcat = node.getChild(0).getCCGcat();
                    CCGcat rcat = node.getChild(1).getCCGcat();
                    rescat = CCGcat.combine(lcat, rcat, rescatstr);
                }
                node.setConllNode(node.getChild(headId).getConllNode());
                node.setCCGcat(rescat);
                nodes.add(node);
            }
        } else {
            cStack.add(c);
        }
    }
    Preconditions.checkArgument(nodes.size() == 1, "Bad Tree");
    CCGJNode root = nodes.pop();
    sent.setccgDerivTree(root);
    return root;
}

From source file:es.upm.oeg.oaipmh.analyzer.writer.CsvWriter.java

public CsvWriter(Mode mode, File directory, String name) throws IOException {

    this.header = true;

    // Create directory
    directory.mkdirs();//from   www .jav a 2  s  .c o  m

    // Create an empty file
    File csv = new File(directory, name + ".csv");
    csv.createNewFile();
    csv.setWritable(true);

    // Initialize file writer
    this.writer = new FileWriter(csv);

    // Get dc:terms
    this.terms = Splitter.on(',').trimResults().omitEmptyStrings()
            .split("abstract , accessRights , accrualMethod , accrualPeriodicity , accrualPolicy , "
                    + "alternative , audience , available , bibliographicCitation , conformsTo , contributor , "
                    + "coverage , created , creator , date , dateAccepted , dateCopyrighted , dateSubmitted , "
                    + "description , educationLevel , extent , format , hasFormat , hasPart , hasVersion , identifier , "
                    + "instructionalMethod , isFormatOf , isPartOf , isReferencedBy , isReplacedBy , isRequiredBy , issued , "
                    + "isVersionOf , language , license , mediator , medium , modified , provenance , publisher , references , "
                    + "relation , replaces , requires , rights , rightsHolder , source , spatial , subject , tableOfContents , "
                    + "temporal , title , type , valid");

    // Get dc:elements
    this.elements = Splitter.on(',').trimResults().omitEmptyStrings().split(
            "contributor , coverage , creator , date , description , format , identifier , language , publisher , "
                    + "relation , rights , source , subject , title , type");

    // Initialize dataline
    initialize(mode);

}

From source file:io.airlift.airship.shared.MavenCoordinates.java

private static MavenCoordinates fromGAV(String coordinates, String defaultPackaging) {
    Matcher matcher = MAVEN_COORDINATES_PATTERN.matcher(coordinates);
    if (!matcher.matches()) {
        return null;
    }/*from  w w w .  j  a va 2  s  .  c o m*/

    List<String> parts = ImmutableList.copyOf(Splitter.on(':').split(coordinates));
    if (parts.size() == 5) {
        return new MavenCoordinates(parts.get(0), parts.get(1), parts.get(4), parts.get(2), parts.get(3), null);
    } else if (parts.size() == 4) {
        return new MavenCoordinates(parts.get(0), parts.get(1), parts.get(3), parts.get(2), null, null);
    } else if (defaultPackaging != null) {
        if (parts.size() == 3) {
            return new MavenCoordinates(parts.get(0), parts.get(1), parts.get(2), defaultPackaging, null, null);
        } else if (parts.size() == 2) {
            return new MavenCoordinates(null, parts.get(0), parts.get(1), defaultPackaging, null, null);
        }
    }
    return null;
}

From source file:com.facebook.presto.execution.resourceGroups.ResourceGroupId.java

public static ResourceGroupId fromString(String value) {
    requireNonNull(value, "value is null");
    return new ResourceGroupId(Splitter.on(".").splitToList(value));
}

From source file:annis.gui.requesthandler.ContentRange.java

/**
 * Parses the header value of a HTTP Range request
 * @param rawRange raw range value as given by the header
 * @param totalSize total size of the content
 * @param maxNum maximal number of allowed ranges. Will throw exception if client requests more ranges.
 * @return//from  ww  w.  ja  va2  s.  co m
 * @throws annis.gui.requesthandler.ContentRange.InvalidRangeException 
 */
public static List<ContentRange> parseFromHeader(String rawRange, long totalSize, int maxNum)
        throws InvalidRangeException {
    List<ContentRange> result = new ArrayList<>();
    if (rawRange != null) {
        if (!fullPattern.matcher(rawRange).matches()) {
            throw new InvalidRangeException("invalid syntax");
        }

        rawRange = rawRange.substring("bytes=".length(), rawRange.length());

        for (String partRange : Splitter.on(",").omitEmptyStrings().trimResults().split(rawRange)) {
            if (result.size() >= totalSize) {
                throw new InvalidRangeException("more ranges than acceptable");
            }

            long from = 0;
            long to = totalSize - 1;

            Matcher m = partPattern.matcher(partRange);
            if (!m.find()) {
                throw new InvalidRangeException("invalid syntax for partial range");
            }

            String fromString = m.group(1);
            String toString = m.group(2);

            if (fromString != null && !fromString.isEmpty()) {
                from = Long.parseLong(fromString);
            }
            if (toString != null && !toString.isEmpty()) {
                to = Long.parseLong(toString);
            }

            if (from > to) {
                throw new InvalidRangeException("start is larger then end");
            }

            result.add(new ContentRange(from, to, totalSize));

        }
    }
    return result;
}

From source file:org.obm.push.bean.ServerId.java

public static ServerId of(String value) {
    Iterable<String> parts = Splitter.on(SERVER_ID_SEPARATOR).split(value);
    if (Iterables.size(parts) > 2) {
        throw new InvalidServerId("Too many parts for a serverId");
    }/*www .  ja  v a  2  s . c  o m*/
    Iterator<String> iterator = parts.iterator();
    return of(getCollectionId(iterator, value), getItemId(iterator));
}

From source file:org.apache.phoenix.hive.util.PhoenixUtil.java

public static String getPhoenixType(String hiveTypeName) {
    if (hiveTypeName.startsWith("array")) {
        List<String> tokenList = Lists
                .newArrayList(Splitter.on(CharMatcher.is('<').or(CharMatcher.is('>'))).split(hiveTypeName));
        return getPhoenixType(tokenList.get(1)) + "[]";
    } else if (hiveTypeName.startsWith("int")) {
        return "integer";
    } else if (hiveTypeName.equals("string")) {
        return "varchar";
    } else {//from   www  .  j  ava 2  s . c  o m
        return hiveTypeName;
    }
}

From source file:com.spotify.helios.servicescommon.ManagedStatsdReporter.java

public ManagedStatsdReporter(final String endpoint, final MetricRegistry registry) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(endpoint));

    final List<String> parts = Splitter.on(":").splitToList(endpoint);
    checkArgument(parts.size() == 2,//from   ww w.j  ava2  s.  com
            "Specification of statsd host port has wrong number of " + "parts. Should be host:port");
    final String host = parts.get(0);
    final int port = Integer.valueOf(parts.get(1));
    statsdReporter = StatsDReporter.forRegistry(registry).build(host, port);
}