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;
}
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;
}
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");
}
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);
}
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));
}
Aggregations