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

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

Introduction

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

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter on(final Pattern separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching pattern to be a separator.

Usage

From source file:org.eclipse.xtext.tasks.PreferenceTaskTagProvider.java

public static List<TaskTag> parseTags(final String names, final String priorities) {
    final Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
    final List<String> tags = IterableExtensions.<String>toList(splitter.split(names));
    final List<String> prios = IterableExtensions.<String>toList(splitter.split(priorities));
    final ArrayList<TaskTag> elements = CollectionLiterals.<TaskTag>newArrayList();
    int _size = tags.size();
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
    for (final Integer i : _doubleDotLessThan) {
        TaskTag _taskTag = new TaskTag();
        final Procedure1<TaskTag> _function = (TaskTag it) -> {
            it.setName(tags.get((i).intValue()));
            Priority _xifexpression = null;
            int _size_1 = prios.size();
            boolean _greaterEqualsThan = (_size_1 >= (i).intValue());
            if (_greaterEqualsThan) {
                Priority _xtrycatchfinallyexpression = null;
                try {
                    _xtrycatchfinallyexpression = Priority.valueOf(prios.get((i).intValue()));
                } catch (final Throwable _t) {
                    if (_t instanceof IllegalArgumentException) {
                        final IllegalArgumentException e = (IllegalArgumentException) _t;
                        _xtrycatchfinallyexpression = Priority.NORMAL;
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }/*from  w  w w  .j av a2  s  .c  om*/
                }
                _xifexpression = _xtrycatchfinallyexpression;
            } else {
                _xifexpression = Priority.NORMAL;
            }
            it.setPriority(_xifexpression);
        };
        TaskTag _doubleArrow = ObjectExtensions.<TaskTag>operator_doubleArrow(_taskTag, _function);
        elements.add(_doubleArrow);
    }
    return elements;
}

From source file:net.orpiske.sfs.filter.dictionary.DictionaryEntry.java

/**
 * Creates a new dictionary entry from a line in the .dic file
 * @param string the line//from   www . ja  v  a  2s  . c  om
 * @return
 */
public static DictionaryEntry fromString(final String string) {
    if (string.trim().isEmpty()) {
        return null;
    }

    Iterable<String> iterable = Splitter.on("/").split(string);
    Iterator<String> it = iterable.iterator();

    String word = it.next();
    String categoryTag = it.next();

    Category cat = Category.fromString(categoryTag);

    return new DictionaryEntry(word, cat);
}

From source file:org.jclouds.location.config.ProvideRegionsViaProperties.java

@Inject
ProvideRegionsViaProperties(@Named(PROPERTY_REGIONS) String regions) {
    this.regions = ImmutableSet.copyOf(Splitter.on(',').split(regions));
}

From source file:com.netflix.metacat.common.server.properties.PropertyUtils.java

/**
 * Convert a delimited string into a Set of {@code QualifiedName}.
 *
 * @param names     The list of names to split
 * @param delimiter The delimiter to use for splitting
 * @return The list of qualified names/*  w  w  w  . j av a2 s  . co m*/
 */
static Set<QualifiedName> delimitedStringsToQualifiedNamesSet(@Nonnull @NonNull final String names,
        final char delimiter) {
    if (StringUtils.isNotBlank(names)) {
        return Splitter.on(delimiter).omitEmptyStrings().splitToList(names).stream()
                .map(QualifiedName::fromString).collect(Collectors.toSet());
    } else {
        return Sets.newHashSet();
    }
}

From source file:jhc.redsniff.internal.util.StringDiffFormatter.java

public String formatDifference(String expected, String actual, String format) {
    List<String> expectedLines = Splitter.on("|||").splitToList(expected);
    List<String> actualLines = Splitter.on("|||").splitToList(actual);

    MyersDiff myersDiff = new MyersDiff();
    Patch diff = myersDiff.diff(expectedLines, actualLines);

    List<String> expectedDifferences = new ArrayList<>(expectedLines.size());
    expectedDifferences.addAll(expectedLines);
    List<String> actualDifferences = new ArrayList<>(actualLines.size());
    actualDifferences.addAll(actualLines);

    for (Delta delta : diff.getDeltas()) {

        List<String> orig = (List<String>) delta.getOriginal().getLines();
        List<String> rev = (List<String>) delta.getRevised().getLines();

        String origString = Joiner.on("\n").join(orig);
        List<String> origCharList = asStringList(origString);
        String revString = Joiner.on("\n").join(rev);
        List<String> revCharList = asStringList(revString);

        List<Delta> inlineDeltas = myersDiff.diff(origCharList, revCharList).getDeltas();

        if (inlineDeltas.size() < sensitivity) {
            Collections.reverse(inlineDeltas);
            for (Delta inlineDelta : inlineDeltas) {
                Chunk inlineOrig = inlineDelta.getOriginal();
                Chunk inlineRev = inlineDelta.getRevised();
                origString = highlight(origString, inlineOrig.getPosition(),
                        inlineOrig.getPosition() + inlineOrig.size());
                revString = highlight(revString, inlineRev.getPosition(),
                        inlineRev.getPosition() + inlineRev.size());
            }/* w  w  w.j av a 2  s.  co  m*/
        } else {
            Delta firstDelta = inlineDeltas.get(0);
            Delta lastDelta = inlineDeltas.get(inlineDeltas.size() - 1);
            origString = highlight(origString, firstDelta.getOriginal().getPosition(),
                    lastDelta.getOriginal().getPosition() + lastDelta.getOriginal().size());
            revString = highlight(revString, firstDelta.getRevised().getPosition(),
                    lastDelta.getRevised().getPosition() + lastDelta.getRevised().size());

        }

        expectedDifferences.set(delta.getOriginal().getPosition(), origString);
        actualDifferences.set(delta.getRevised().getPosition(), revString);

    }
    String formattedExpected = "";
    for (int i = 0; i < expectedDifferences.size(); i++) {
        String diffLine = expectedDifferences.get(i);
        String line = diffLine != null ? diffLine : expectedLines.get(i);
        formattedExpected += line;
    }
    String formattedActual = "";
    for (int i = 0; i < actualDifferences.size(); i++) {
        String diffLine = actualDifferences.get(i);
        String line = diffLine != null ? diffLine : actualLines.get(i);
        formattedActual += line;
    }
    return String.format(format, formattedActual, formattedExpected);
}

From source file:org.rf.ide.core.testdata.model.table.keywords.names.QualifiedKeywordName.java

public static boolean isOccurrenceEqualToDefinition(final String keywordOccurrence,
        final String keywordDefinition) {
    if (EmbeddedKeywordNamesSupport.hasEmbeddedArguments(keywordDefinition)) { // ignore embedded keyword names 
        return true;
    }//from   w  w  w  . j  av a 2 s  .  co m
    final List<String> splittedOccurrence = Splitter.on('.').splitToList(keywordOccurrence);
    final String nameInOccurrence = splittedOccurrence.get(splittedOccurrence.size() - 1).trim();
    return nameInOccurrence.equalsIgnoreCase(keywordDefinition);
}

From source file:org.springframework.schema.beans.MartiniCategoryBeanDefinitionParser.java

protected void doParse(Element element, BeanDefinitionBuilder bean) {
    String name = element.getAttribute("name");
    bean.addConstructorArgValue(name);// w w  w  .  jav a 2 s .  co  m

    String parents = element.getAttribute("parentNames");
    List<String> parentList = null == parents ? null
            : Splitter.on(',').trimResults().omitEmptyStrings().splitToList(parents);
    bean.addConstructorArgValue(null == parentList ? Collections.emptyList() : parentList);
}

From source file:org.jclouds.elasticstack.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java

@Override
public List<Map<String, String>> apply(String from) {
    List<Map<String, String>> maps = Lists.newArrayList();
    for (String listOfKeyValues : Splitter.on("\n\n").split(from)) {
        if (!"".equals(listOfKeyValues)) {
            Map<String, String> map = Maps.newLinkedHashMap();
            for (String keyValueLine : Splitter.on('\n').split(listOfKeyValues)) {
                if (!"".equals(keyValueLine)) {
                    int firstIndex = keyValueLine.indexOf(' ');
                    if (firstIndex != -1) {
                        String key = keyValueLine.substring(0, firstIndex);
                        String value = keyValueLine.substring(firstIndex + 1).replace("\\n", "\n");
                        map.put(key, value);
                    }/*from w w w  . j  a va  2  s  .  c  om*/
                }
            }
            if (map.size() != 0)
                maps.add(map);
        }
    }
    return maps;
}

From source file:com.techshroom.wood.ModuleDependency.java

public static FluentIterable<ModuleDependency> fromList(String list) {
    Iterable<String> splits = Splitter.on(';').split(list);
    return FluentIterable.from(splits).transform(ModuleDependency::fromString);
}

From source file:com.fractal.facebooksentiment.processor.FacebookSentimentCalculator.java

private FacebookSentimentCalculator() {
    commentSentimentMap = Maps.newTreeMap();
    afinnSentimentMap = Maps.newTreeMap();

    try {//from  w w  w  .jav  a2  s .  c o  m
        final URL url = Resources.getResource(Constants.AFINN_SENTIMENT_FILE_NAME);
        final String text = Resources.toString(url, Charsets.UTF_8);
        final Iterable<String> lineSplit = Splitter.on("\n").trimResults().omitEmptyStrings().split(text);
        List<String> tabSplit;
        for (final String str : lineSplit) {
            tabSplit = Lists.newArrayList(Splitter.on("\t").trimResults().omitEmptyStrings().split(str));
            afinnSentimentMap.put(tabSplit.get(0), Integer.parseInt(tabSplit.get(1)));
        }
    } catch (final IOException ioException) {
        ioException.printStackTrace();
        // Should not occur. If it occurs, we cant continue. So, exiting at this point itself.
        // System.exit(1);
    }
}