Example usage for com.google.common.base Splitter splitToList

List of usage examples for com.google.common.base Splitter splitToList

Introduction

In this page you can find the example usage for com.google.common.base Splitter splitToList.

Prototype

@CheckReturnValue
@Beta
public List<String> splitToList(CharSequence sequence) 

Source Link

Document

Splits sequence into string components and returns them as an immutable list.

Usage

From source file:org.apache.gobblin.data.management.copy.hive.WhitelistBlacklist.java

private static void populateMultimap(SetMultimap<Pattern, Pattern> multimap, String list) throws IOException {
    Splitter tokenSplitter = Splitter.on(",").omitEmptyStrings().trimResults();
    Splitter partSplitter = Splitter.on(".").omitEmptyStrings().trimResults();
    Splitter tableSplitter = Splitter.on("|").omitEmptyStrings().trimResults();

    for (String token : tokenSplitter.split(list)) {

        if (!Strings.isNullOrEmpty(token)) {
            List<String> parts = partSplitter.splitToList(token);
            if (parts.size() > 2) {
                throw new IOException("Invalid token " + token);
            }// w  w  w  .  j  a va 2 s .c  om

            Pattern databasePattern = Pattern.compile(parts.get(0).replace("*", ".*"));
            Set<Pattern> tablePatterns = Sets.newHashSet();
            if (parts.size() == 2) {
                String tables = parts.get(1);
                for (String table : tableSplitter.split(tables)) {
                    if (table.equals("*")) {
                        // special case, must use ALL_TABLES due to use of set.contains(ALL_TABLES) in multimapContains
                        tablePatterns.add(ALL_TABLES);
                    } else {
                        tablePatterns.add(Pattern.compile(table.replace("*", ".*")));
                    }
                }
            } else {
                tablePatterns.add(ALL_TABLES);
            }
            multimap.putAll(databasePattern, tablePatterns);
        }
    }
}

From source file:org.mskcc.juber.waltz.Waltz.java

/**
 * make given number of interval lists from the given bed file
 * //from   w  w  w  .ja  va  2  s  .c o  m
 * @param targetBed
 * @param numberOfLists
 * @param header
 * @return
 * @throws IOException
 */
private static IntervalList[] makeIntervalLists(File bedFile, int numberOfLists, SAMFileHeader header)
        throws IOException {
    boolean addChr = hasChr(header);

    IntervalList[] intervalLists = new IntervalList[numberOfLists];
    for (int i = 0; i < intervalLists.length; i++) {
        intervalLists[i] = new IntervalList(header);
    }

    Splitter tabSplitter = Splitter.on('\t');

    BufferedReader reader = new BufferedReader(new FileReader(bedFile));
    String line = null;
    int lineNumber = 1;
    while ((line = reader.readLine()) != null) {
        List<String> words = tabSplitter.splitToList(line);
        String chr = null;
        if (addChr) {
            chr = "chr" + words.get(0);
        } else {
            chr = words.get(0);
        }

        // adding padding
        int start = Integer.parseInt(words.get(1)) - basePadding;
        int end = Integer.parseInt(words.get(2)) + basePadding;

        Interval interval = new Interval(chr, start, end, false, words.get(4));
        // add intervals to interval lists equitably
        IntervalList intervalList = intervalLists[lineNumber % numberOfLists];
        intervalList.add(interval);
    }

    reader.close();
    return intervalLists;
}

From source file:ec.tss.tsproviders.utils.Parsers.java

@Nonnull
public static Parser<List<String>> onSplitter(@Nonnull Splitter splitter) {
    return new FailSafeParser<List<String>>() {
        @Override//  w  w w  .  j av a2  s .c  o  m
        protected List<String> doParse(CharSequence input) throws Exception {
            return splitter.splitToList(input);
        }
    };
}

From source file:gobblin.util.AvroUtils.java

public static Map<String, Object> getMultiFieldValue(GenericRecord record, String fieldLocation) {
    Preconditions.checkNotNull(record);//  w w  w .  j a v  a2  s  . c o m
    Preconditions.checkArgument(!Strings.isNullOrEmpty(fieldLocation));

    Splitter splitter = Splitter.on(FIELD_LOCATION_DELIMITER).omitEmptyStrings().trimResults();
    List<String> pathList = splitter.splitToList(fieldLocation);

    if (pathList.size() == 0) {
        return Collections.emptyMap();
    }

    HashMap<String, Object> retVal = new HashMap<String, Object>();
    AvroUtils.getFieldHelper(retVal, record, pathList, 0);
    return retVal;
}

From source file:com.zulily.omicron.conf.Configuration.java

private static ImmutableMap<ConfigKey, String> loadConfig(final String configFilePath) {

    if (Strings.isNullOrEmpty(configFilePath.trim())) {

        info("No config file specified. Will use defaults.");

        return ImmutableMap.of();

    }//from w w w  .j  a v a 2 s  .c  om

    final File configFile = new File(configFilePath);

    if (!Utils.fileExistsAndCanRead(configFile)) {

        info("Config file not found, not a file, or cannot be read. Will use defaults.");

        return ImmutableMap.of();

    }

    final Splitter equalSplitter = Splitter.on('=').trimResults().omitEmptyStrings();
    final HashMap<ConfigKey, String> config = Maps.newHashMap();

    try {

        ImmutableList<String> configLines = Files.asCharSource(configFile, Charset.defaultCharset())
                .readLines();

        for (final String configLine : configLines) {

            final String trimmed = configLine.trim();

            //Skip commented/blank lines
            if (trimmed.isEmpty() || '#' == trimmed.charAt(0)) {
                continue;
            }

            final List<String> configLineParts = equalSplitter.splitToList(trimmed);

            if (configLineParts.size() != 2) {

                warn("Skipping malformed config line: {0}", trimmed);
                continue;

            }

            final ConfigKey configKey = ConfigKey.fromString(configLineParts.get(0));

            if (configKey == ConfigKey.Unknown) {

                warn("Skipping unknown config param: {0}", trimmed);
                continue;

            }

            config.put(configKey, configLineParts.get(1));

        }

    } catch (IOException e) {
        throw Throwables.propagate(e);
    }

    if (config.isEmpty()) {
        warn("Config file values not loaded. Will use defaults.");
    }

    return ImmutableMap.copyOf(config);
}

From source file:com.textocat.textokit.postagger.MorphCasUtils.java

/**
 * Make Word annotation for each given simple word where Word.grammemes feature are filled by splitting
 * SimpleWord#posTag value by the given separator char.
 * <p> This method is intended for a quick test data creation.</p>
 *
 * @param jCas        -//from w w  w  .j a v a 2  s.co  m
 * @param simpleWords -
 * @param grammemeSep separator of grammatical values in 'posTag' feature of a SimpleWord annotation.
 * @see com.textocat.textokit.commons.io.axml.AXMLReader
 */
public static void makeWordsAndTokens(JCas jCas, Iterable<SimplyWord> simpleWords, char grammemeSep) {
    Splitter gramSplitter = Splitter.on(grammemeSep).omitEmptyStrings();
    for (SimplyWord simpleWord : simpleWords) {
        // make token
        Token token = TokenUtils.makeToken(jCas, simpleWord.getCoveredText(), simpleWord.getBegin(),
                simpleWord.getEnd());
        token.addToIndexes();
        // assign token to the source simple word
        simpleWord.setToken(token);
        // make word
        Word resWord = new Word(jCas, simpleWord.getBegin(), simpleWord.getEnd());
        resWord.setToken(token);
        Wordform wf = new Wordform(jCas);
        wf.setWord(resWord);
        String posTag = simpleWord.getPosTag();
        if (posTag != null) {
            wf.setPos(posTag);
            wf.setGrammems(FSUtils.toStringArray(jCas, gramSplitter.splitToList(posTag)));
        }
        wf.setLemma(simpleWord.getLemma());
        wf.setLemmaId(simpleWord.getLemmaId());
        resWord.setWordforms(FSUtils.toFSArray(jCas, wf));
        resWord.addToIndexes();
    }
}

From source file:com.teradata.tempto.internal.convention.tabledefinitions.JdbcDataFileDescriptor.java

private List<String> parseLine(String line, String delimiter, Splitter valuesSplitter) {
    List<String> rowValues = valuesSplitter.splitToList(line);
    if (line.trim().endsWith(delimiter)) {
        rowValues = rowValues.subList(0, rowValues.size() - 1);
    }/*from w w  w .  j  a  v  a2 s.c  om*/
    return rowValues;
}

From source file:annis.CommonHelper.java

public static Match extractMatch(SDocument doc) throws URISyntaxException {
    Splitter idSplit = Splitter.on(',').trimResults();
    Match m = null;//from  w  ww . j av  a 2  s.  c o  m

    // get the matched node IDs
    SFeature featIDs = doc.getSFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_MATCHEDIDS);

    if (featIDs != null) {
        LinkedList<URI> idList = new LinkedList<>();
        for (String rawID : idSplit.split(featIDs.getSValueSTEXT())) {
            idList.add(new URI(rawID));
        }
        SFeature featAnnos = doc.getSFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_MATCHEDANNOS);
        if (featAnnos == null) {
            m = new Match(idList);
        } else {
            m = new Match(idList, idSplit.splitToList(featAnnos.getSValueSTEXT()));
        }
    }

    return m;
}

From source file:ee.ria.xroad.monitor.executablelister.AbstractExecLister.java

private T parseLine(String line, Splitter splitter) {
    List<String> columns = splitter.splitToList(line);
    if (columns.size() != numberOfColumnsToParse()) {
        throw new ExecListingFailedException("output should have " + numberOfColumnsToParse() + " columns, had "
                + columns.size() + ": " + line);
    }//  ww w.  j  a  v  a2  s .  c o  m
    T data = parse(columns);
    return data;
}

From source file:org.eclipse.viatra.addon.databinding.runtime.observables.ObservableLabelFeature.java

private final Map<String, IObservableValue> initializeObservableMap(String expression, IPatternMatch match) {
    Map<String, IObservableValue> map = new HashMap<>();

    //StringTokenizer tokenizer = new StringTokenizer(expression, "$", true);
    Splitter tokenizer = Splitter.on("$");
    expressionTokens = tokenizer.splitToList(expression);
    boolean inExpression = false;
    boolean foundToken = false;
    for (String token : expressionTokens) {
        if (Strings.isNullOrEmpty(token)) {
            if (inExpression && !foundToken) {
                throw new IllegalArgumentException("Empty reference ($$) in message is not allowed.");
            }//  ww w .  j a  va2  s.  com
            inExpression = !inExpression;
        } else if (inExpression) {
            if (!map.containsKey(token)) {
                IObservableValue value = ViatraObservables.getObservableValue(match, token);
                map.put(token, value);
            }
            foundToken = true;
        }
    }
    if (inExpression) {
        throw new IllegalArgumentException("Inconsistent model references - a $ character is missing.");
    }

    return map;
}