Search in sources :

Example 61 with Splitter

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;
}
Also used : Splitter(com.google.common.base.Splitter) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 62 with Splitter

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;
}
Also used : Splitter(com.google.common.base.Splitter)

Example 63 with Splitter

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);
}
Also used : Splitter(com.google.common.base.Splitter) HashSet(java.util.HashSet)

Example 64 with Splitter

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);
}
Also used : Splitter(com.google.common.base.Splitter)

Example 65 with Splitter

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