use of com.google.common.base.Splitter in project ANNIS by korpling.
the class Match method parseFromString.
public static Match parseFromString(String raw, char separator) {
Match match = new Match();
Splitter splitter = matchSplitter;
if (separator != ' ') {
splitter = Splitter.on(separator).trimResults().omitEmptyStrings();
}
for (String singleMatch : splitter.split(raw)) {
URI uri;
// undo any escaping
singleMatch = singleMatch.replace("%20", " ").replace("%25", "%");
String id = "";
String anno = null;
if (singleMatch.startsWith("salt:/")) {
id = singleMatch;
} else {
// split into the annotation namespace/name and the salt URI
List<String> components = annoIDSplitter.splitToList(singleMatch);
int componentsSize = components.size();
Preconditions.checkArgument(componentsSize == 3 || componentsSize == 2, "A match containing " + "annotation information always has to have the form " + "ns::name::salt:/.... or name::salt:/....");
String ns = "";
String name = "";
if (componentsSize == 3) {
id = components.get(2);
ns = components.get(0);
name = components.get(1);
} else if (componentsSize == 2) {
id = components.get(1);
name = components.get(0);
}
if (ns.isEmpty()) {
anno = name;
} else {
anno = ns + "::" + name;
}
}
try {
uri = new java.net.URI(id).normalize();
if (!"salt".equals(uri.getScheme()) || uri.getFragment() == null) {
throw new URISyntaxException("not a Salt id", uri.toString());
}
// check if the path ends with "/" (which was wrongly used by older ANNIS versions)
String path = uri.getPath();
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
uri = new URI(uri.getScheme(), uri.getHost(), path, uri.getFragment());
}
} catch (URISyntaxException ex) {
log.error("Invalid syntax for ID " + singleMatch, ex);
continue;
}
match.addSaltId(uri, anno);
}
return match;
}
use of com.google.common.base.Splitter in project openflowplugin by opendaylight.
the class ByteBufUtils method hexStringToBytes.
/**
* Converts String into byte[].
*
* @param hexSrc input String
* @param withSpaces if there are spaces in string
* @return byte[] filled with input data
*/
public static byte[] hexStringToBytes(final String hexSrc, final boolean withSpaces) {
final Splitter splitter = withSpaces ? HEXSTRING_SPLITTER : HEXSTRING_NOSPACE_SPLITTER;
List<String> byteChips = Lists.newArrayList(splitter.split(hexSrc));
byte[] result = new byte[byteChips.size()];
int index = 0;
for (String chip : byteChips) {
result[index] = (byte) Short.parseShort(chip, 16);
index++;
}
return result;
}
use of com.google.common.base.Splitter in project closure-compiler by google.
the class RefasterJs method getInputs.
private List<String> getInputs() throws IOException {
Set<String> patterns = new HashSet<>();
// The args4j library can't handle multiple files provided within the same flag option,
// like --inputs=file1.js,file2.js so handle that here.
Splitter commaSplitter = Splitter.on(',');
for (String input : inputs) {
patterns.addAll(commaSplitter.splitToList(input));
}
patterns.addAll(arguments);
return CommandLineRunner.findJsFiles(patterns);
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class AvroUtils method getField.
/**
* Given a GenericRecord, this method will return the field specified by the path parameter. The
* fieldLocation parameter is an ordered string specifying the location of the nested field to retrieve. For example,
* field1.nestedField1 takes field "field1", and retrieves "nestedField1" from it.
* @param schema is the record to retrieve the schema from
* @param fieldLocation is the location of the field
* @return the field
*/
public static Optional<Field> getField(Schema schema, String fieldLocation) {
Preconditions.checkNotNull(schema);
Preconditions.checkArgument(!Strings.isNullOrEmpty(fieldLocation));
Splitter splitter = Splitter.on(FIELD_LOCATION_DELIMITER).omitEmptyStrings().trimResults();
List<String> pathList = Lists.newArrayList(splitter.split(fieldLocation));
if (pathList.size() == 0) {
return Optional.absent();
}
return AvroUtils.getFieldHelper(schema, pathList, 0);
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class AvroUtils method getFieldSchema.
/**
* Given a GenericRecord, this method will return the schema of the field specified by the path parameter. The
* fieldLocation parameter is an ordered string specifying the location of the nested field to retrieve. For example,
* field1.nestedField1 takes the the schema of the field "field1", and retrieves the schema "nestedField1" from it.
* @param schema is the record to retrieve the schema from
* @param fieldLocation is the location of the field
* @return the schema of the field
*/
public static Optional<Schema> getFieldSchema(Schema schema, String fieldLocation) {
Preconditions.checkNotNull(schema);
Preconditions.checkArgument(!Strings.isNullOrEmpty(fieldLocation));
Splitter splitter = Splitter.on(FIELD_LOCATION_DELIMITER).omitEmptyStrings().trimResults();
List<String> pathList = Lists.newArrayList(splitter.split(fieldLocation));
if (pathList.size() == 0) {
return Optional.absent();
}
return AvroUtils.getFieldSchemaHelper(schema, pathList, 0);
}
Aggregations