List of usage examples for com.google.common.base Splitter on
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter on(final Pattern separatorPattern)
From source file:com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec.java
@Nullable public static ArtifactDependencySpec create(@NotNull String notation) { // Example: org.gradle.test.classifiers:service:1.0:jdk15@jar where // group: org.gradle.test.classifiers // name: service // version: 1.0 // classifier: jdk15 // extension: jar List<String> segments = Splitter.on(GRADLE_PATH_SEPARATOR).trimResults().omitEmptyStrings() .splitToList(notation);/* ww w. j a v a 2 s . c o m*/ int segmentCount = segments.size(); if (segmentCount > 0) { segments = Lists.newArrayList(segments); String lastSegment = segments.remove(segmentCount - 1); String extension = null; int indexOfAt = lastSegment.indexOf('@'); if (indexOfAt != -1) { extension = lastSegment.substring(indexOfAt + 1, lastSegment.length()); lastSegment = lastSegment.substring(0, indexOfAt); } segments.add(lastSegment); segmentCount = segments.size(); String group = null; String name = null; String version = null; String classifier = null; if (segmentCount == 1) { name = segments.get(0); } else if (segmentCount == 2) { if (!lastSegment.isEmpty() && Character.isDigit(lastSegment.charAt(0))) { name = segments.get(0); version = lastSegment; } else { group = segments.get(0); name = segments.get(1); } } else if (segmentCount == 3 || segmentCount == 4) { group = segments.get(0); name = segments.get(1); version = segments.get(2); if (segmentCount == 4) { classifier = segments.get(3); } } if (isNotEmpty(name)) { return new ArtifactDependencySpec(name, group, version, classifier, extension); } } return null; }
From source file:org.apache.james.core.User.java
public static User fromUsername(String username) { Preconditions.checkNotNull(username); Preconditions.checkArgument(!Strings.isNullOrEmpty(username)); List<String> parts = ImmutableList.copyOf(Splitter.on('@').split(username)); switch (parts.size()) { case 1:// w w w .j a va 2 s . co m return fromLocalPartWithoutDomain(username); case 2: return fromLocalPartWithDomain(parts.get(0), parts.get(1)); } throw new IllegalArgumentException("The username should not contain multiple domain delimiter."); }
From source file:com.metabroadcast.common.intl.Countries.java
public static Set<Country> fromDelimtedList(String list) { return fromCodes(Splitter.on(DELIMTER_PATTERN).split(list)); }
From source file:com.wadpam.guja.api.SemanticVersionCheckPredicate.java
private static Map<String, String> parsePropertyMap(String formattedMap) { return Splitter.on(",").withKeyValueSeparator("=").split(formattedMap); }
From source file:org.apache.phoenix.pig.util.ColumnInfoToStringEncoderDecoder.java
public static List<ColumnInfo> decode(final String columnInfoStr) { Preconditions.checkNotNull(columnInfoStr); List<ColumnInfo> columnInfos = Lists.newArrayList( Iterables.transform(Splitter.on(COLUMN_INFO_DELIMITER).omitEmptyStrings().split(columnInfoStr), new Function<String, ColumnInfo>() { @Override public ColumnInfo apply(String colInfo) { if (colInfo.isEmpty()) { return null; }//from w w w . ja v a 2 s.c o m return ColumnInfo.fromString(colInfo); } })); return columnInfos; }
From source file:com.google.idea.blaze.base.lang.buildfile.validation.GlobPatternValidator.java
@Nullable private static String checkPatternForError(String pattern) { if (pattern.isEmpty()) { return "pattern cannot be empty"; }/*from w ww. j a va 2s. c o m*/ if (pattern.charAt(0) == '/') { return "pattern cannot be absolute"; } for (int i = 0; i < pattern.length(); i++) { char c = pattern.charAt(i); switch (c) { case '(': case ')': case '{': case '}': case '[': case ']': return "illegal character '" + c + "'"; } } Iterable<String> segments = Splitter.on('/').split(pattern); for (String segment : segments) { if (segment.isEmpty()) { return "empty segment not permitted"; } if (segment.equals(".") || segment.equals("..")) { return "segment '" + segment + "' not permitted"; } if (segment.contains("**") && !segment.equals("**")) { return "recursive wildcard must be its own segment"; } } return null; }
From source file:org.fcrepo.kernel.api.utils.MessageExternalBodyContentType.java
/** * Utility method to parse the external body content in format: message/external-body; access-type=URL; * url="http://www.example.com/file"/*from w w w. j a v a 2 s. c o m*/ * * @param mimeType the MimeType value for external resource * @return MessageExternalBodyContentType value * @throws UnsupportedAccessTypeException if mimeType param is not a valid message/external-body content type. */ public static MessageExternalBodyContentType parse(final String mimeType) throws UnsupportedAccessTypeException { final Map<String, String> map = new HashMap<String, String>(); Splitter.on(';').omitEmptyStrings().trimResults().withKeyValueSeparator(Splitter.on('=').limit(2)) .split(MIME_TYPE_FIELD + "=" + mimeType.trim()) // use lower case for keys, unwrap the quoted values (double quotes at the beginning and the end) .forEach((k, v) -> map.put(k.toLowerCase(), v.replaceAll("^\"|\"$", ""))); final String accessType = map.get("access-type").toLowerCase(); final String resourceLocation = map.get(accessType); if (MEDIA_TYPE.equals(map.get(MIME_TYPE_FIELD)) && "url".equals(accessType) && !StringUtils.isBlank(resourceLocation)) { return new MessageExternalBodyContentType(accessType, resourceLocation); } throw new UnsupportedAccessTypeException( "The specified type is not a valid message/external body content type: value=" + mimeType); }
From source file:com.facebook.buck.parcelable.Parser.java
public static ParcelableClass parse(File xml) throws IOException { Document doc = XmlDomParser.parse(xml); // packageName, className, creatorClass Element classElement = (Element) doc.getElementsByTagName("class").item(0); String classNameAttr = getAttribute(classElement, "name"); int splitIndex = classNameAttr.lastIndexOf('.'); String packageName = classNameAttr.substring(0, splitIndex); String className = classNameAttr.substring(splitIndex + 1); String creatorClassName = getAttribute(classElement, "creatorClass"); // imports/*from w w w .ja v a2s .co m*/ Element importsElement = (Element) doc.getElementsByTagName("imports").item(0); String importsText = importsElement.getTextContent(); Iterable<String> imports = Splitter.on('\n').omitEmptyStrings().trimResults().split(importsText); // defaultFieldVisibility Element fieldsElement = (Element) doc.getElementsByTagName("fields").item(0); String defaultFieldVisibility = getAttribute(fieldsElement, "defaultVisibility"); if (defaultFieldVisibility == null) { defaultFieldVisibility = "private"; } // fields ImmutableList.Builder<ParcelableField> fields = ImmutableList.builder(); NodeList fieldNodes = fieldsElement.getElementsByTagName("field"); for (int i = 0; i < fieldNodes.getLength(); i++) { Element fieldElement = (Element) fieldNodes.item(i); ParcelableField field = new ParcelableField(escapeJavaType(getAttribute(fieldElement, "type")), getAttribute(fieldElement, "name"), getBooleanAttribute(fieldElement, "mutable"), getAttribute(fieldElement, "visibility"), getAttribute(fieldElement, "jsonProperty"), getAttribute(fieldElement, "defaultValue")); fields.add(field); } return new ParcelableClass(packageName, imports, className, creatorClassName == null ? className : creatorClassName, defaultFieldVisibility, fields.build(), getAttribute(classElement, "extends"), getAttribute(classElement, "superParams")); }
From source file:org.apache.isis.viewer.restfulobjects.applib.util.PathNode.java
public static List<String> split(String path) { List<String> parts = Lists.newArrayList(); String curr = null;//from w w w.j a v a 2 s.c om for (String part : Splitter.on(".").split(path)) { if (curr != null) { if (part.contains("]")) { curr = curr + "." + part; parts.add(curr); curr = null; } else { curr = curr + "." + part; } continue; } if (!part.contains("[")) { parts.add(part); continue; } if (part.contains("]")) { parts.add(part); } else { curr = part; } } return parts; }
From source file:org.jooby.internal.raml.Doc.java
public static String toYaml(final String text, final int level) { List<String> lines = Splitter.on("\n").splitToList(text); long count = lines.stream().filter(l -> l.trim().length() > 0).count(); if (count == 1) { return "'" + text.trim().replace("'", "''") + "'"; }//from w w w. ja v a 2 s.c om StringBuilder indent = new StringBuilder(); for (int i = 0; i < level + 2; i++) { indent.append(" "); } return "|-\n" + lines.stream().map(line -> { if (line.trim().length() > 0) { return indent + line; } return ""; }).collect(Collectors.joining("\n")).replaceAll("^[\\n]+", ""); }