Search in sources :

Example 81 with Splitter

use of com.google.common.base.Splitter in project graylog2-server by Graylog2.

the class Generator method shortenJsonSchemaURN.

private String shortenJsonSchemaURN(@Nullable String id) {
    if (id == null) {
        return null;
    }
    final Splitter splitter = Splitter.on(":");
    final List<String> segments = splitter.splitToList(id);
    return segments.size() > 0 ? segments.get(segments.size() - 1) : id;
}
Also used : Splitter(com.google.common.base.Splitter)

Example 82 with Splitter

use of com.google.common.base.Splitter in project grpc-java by grpc.

the class XdsClient method isResourceNameValid.

static boolean isResourceNameValid(String resourceName, String typeUrl) {
    checkNotNull(resourceName, "resourceName");
    if (!resourceName.startsWith(XDSTP_SCHEME)) {
        return true;
    }
    URI uri;
    try {
        uri = new URI(resourceName);
    } catch (URISyntaxException e) {
        return false;
    }
    String path = uri.getPath();
    // path must be in the form of /{resource type}/{id/*}
    Splitter slashSplitter = Splitter.on('/').omitEmptyStrings();
    if (path == null) {
        return false;
    }
    List<String> pathSegs = slashSplitter.splitToList(path);
    if (pathSegs.size() < 2) {
        return false;
    }
    String type = pathSegs.get(0);
    if (!type.equals(slashSplitter.splitToList(typeUrl).get(1))) {
        return false;
    }
    return true;
}
Also used : Splitter(com.google.common.base.Splitter) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 83 with Splitter

use of com.google.common.base.Splitter in project springside4 by springside.

the class MoreStringUtilTest method split.

@Test
public void split() {
    List<String> result = MoreStringUtil.split("192.168.0.1", '.', 4);
    assertThat(result).hasSize(4).containsSequence("192", "168", "0", "1");
    result = MoreStringUtil.split("192.168..1", '.', 4);
    assertThat(result).hasSize(3).containsSequence("192", "168", "1");
    result = MoreStringUtil.split("192.168.0.", '.', 4);
    assertThat(result).hasSize(3).containsSequence("192", "168", "0");
    assertThat(MoreStringUtil.split(null, '.', 4)).isNull();
    assertThat(MoreStringUtil.split("", '.', 4)).hasSize(0);
    Splitter splitter = MoreStringUtil.charsSplitter("/\\").omitEmptyStrings();
    result = splitter.splitToList("/a/b/c");
    assertThat(result).hasSize(3).containsSequence("a", "b", "c");
    result = splitter.splitToList("\\a\\b\\c");
    assertThat(result).hasSize(3).containsSequence("a", "b", "c");
}
Also used : Splitter(com.google.common.base.Splitter) Test(org.junit.Test)

Example 84 with Splitter

use of com.google.common.base.Splitter in project snow-owl by b2ihealthcare.

the class Highlighting method getSuffixes.

public static String[] getSuffixes(final String queryExpression, final String label) {
    final Splitter tokenSplitter = Splitter.on(TextConstants.WHITESPACE_OR_DELIMITER_MATCHER).omitEmptyStrings();
    final List<String> filterTokens = tokenSplitter.splitToList(queryExpression.toLowerCase());
    final boolean spaceAtTheEnd = !queryExpression.isEmpty() && Character.isWhitespace(queryExpression.charAt(queryExpression.length() - 1));
    final String lowerCaseLabel = label.toLowerCase();
    final Iterable<String> labelTokens = tokenSplitter.split(lowerCaseLabel);
    final List<String> elementSuffixes = Lists.newArrayList();
    for (final String labelToken : labelTokens) {
        final Iterator<String> itr = filterTokens.iterator();
        while (itr.hasNext()) {
            final String filterToken = itr.next();
            if (labelToken.startsWith(filterToken)) {
                // Last filter token? Also add suffix, unless it is already present in the filter and there's no whitespace at the end of it
                if (!itr.hasNext() && !filterTokens.contains(labelToken) && !spaceAtTheEnd) {
                    elementSuffixes.add(labelToken.substring(filterToken.length()));
                }
            }
        }
        // If there's whitespace at the end, add complete word suggestions as well
        if (shouldSuggest(filterTokens, labelToken) && spaceAtTheEnd) {
            elementSuffixes.add(labelToken);
        }
    }
    return Iterables.toArray(elementSuffixes, String.class);
}
Also used : Splitter(com.google.common.base.Splitter)

Example 85 with Splitter

use of com.google.common.base.Splitter in project snow-owl by b2ihealthcare.

the class BranchPathUtils method createPath.

/**
 * Returns a new {@code IBranchPath} instance where the path has this instance's path and the specified segment concatenated. Multiple
 * separators at the insertion point will be converted to a single separator.
 *
 * @param segmentToAppend the string segment to append to this path
 * @return the resulting path
 */
public static IBranchPath createPath(final IBranchPath branchPath, final String segmentToAppend) {
    checkNotNull(branchPath, "Source branch path may not be null.");
    checkNotNull(segmentToAppend, "Appended segment may not be null.");
    final Splitter splitter = Splitter.on(IBranchPath.SEPARATOR_CHAR).omitEmptyStrings().trimResults();
    final Iterable<String> sourceSegments = splitter.split(branchPath.getPath());
    final Iterable<String> appendedSegments = splitter.split(segmentToAppend);
    final Iterable<String> allSegments = Iterables.concat(sourceSegments, appendedSegments);
    return BranchPathUtils.createPath(Joiner.on(IBranchPath.SEPARATOR_CHAR).join(allSegments));
}
Also used : Splitter(com.google.common.base.Splitter)

Aggregations

Splitter (com.google.common.base.Splitter)86 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)12 HashSet (java.util.HashSet)10 File (java.io.File)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 BufferedReader (java.io.BufferedReader)4 NonNull (com.android.annotations.NonNull)3 URI (java.net.URI)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)3 CharMatcher (com.google.common.base.CharMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CharSource (com.google.common.io.CharSource)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2