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

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

Introduction

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

Prototype

@CheckReturnValue
public Iterable<String> split(final CharSequence sequence) 

Source Link

Document

Splits sequence into string components and makes them available through an Iterator , which may be lazily evaluated.

Usage

From source file:com.b2international.snowowl.datastore.BranchPathUtils.java

/**
 * Returns a new {@code IBranchPath} instance where the path has this instance's path and the specified segment concatenated. Multiple
 * separators at the insertion point will be converted to a single separator.
 * /*from w ww .ja  v a  2s  .co  m*/
 * @param segmentToAppend the string segment to append to this path
 * @return the resulting path
 */
public static IBranchPath createPath(final IBranchPath branchPath, final String segmentToAppend) {
    checkNotNull(branchPath, "Source branch path may not be null.");
    checkNotNull(segmentToAppend, "Appended segment may not be null.");

    final Splitter splitter = Splitter.on(IBranchPath.SEPARATOR_CHAR).omitEmptyStrings().trimResults();

    final Iterable<String> sourceSegments = splitter.split(branchPath.getPath());
    final Iterable<String> appendedSegments = splitter.split(segmentToAppend);
    final Iterable<String> allSegments = Iterables.concat(sourceSegments, appendedSegments);

    return BranchPathUtils.createPath(Joiner.on(IBranchPath.SEPARATOR_CHAR).join(allSegments));
}

From source file:com.google.cloud.tools.intellij.login.GoogleLoginPrefs.java

/**
 * Retrieves the persistently stored list of users.
 *
 * @return the stored list of users./*from  w  w w .j a va2  s.  c  o m*/
 */
@NotNull
public static List<String> getStoredUsers() {
    Preferences prefs = getPrefs();
    String allUsersString = prefs.get(USERS, "");
    List<String> allUsers = new ArrayList<String>();
    if (allUsersString.isEmpty()) {
        return allUsers;
    }

    Splitter splitter = Splitter.on(DELIMITER).omitEmptyStrings();
    for (String user : splitter.split(allUsersString)) {
        allUsers.add(user);
    }
    return allUsers;
}

From source file:com.google.cloud.tools.intellij.login.GoogleLoginPrefs.java

private static void addUser(String user) {
    Preferences prefs = getPrefs();
    String allUsersString = prefs.get(USERS, null);
    if (allUsersString == null) {
        prefs.put(USERS, user);/*from   w ww  .ja  v a 2s.c o  m*/
        return;
    }

    List<String> allUsers = new ArrayList<String>();
    Splitter splitter = Splitter.on(DELIMITER).omitEmptyStrings();
    for (String scope : splitter.split(allUsersString)) {
        allUsers.add(scope);
    }

    if (allUsers.contains(user)) {
        return;
    }

    Joiner joiner = Joiner.on(DELIMITER);
    prefs.put(USERS, joiner.join(allUsersString, user));
    flushPrefs(prefs);
}

From source file:buildcraft.core.InterModComms.java

public static void processAddFacadeIMC(IMCEvent event, IMCMessage m) {
    try {/*www. j a  v  a2 s .c  o m*/
        if (m.isStringMessage()) {
            Splitter splitter = Splitter.on("@").trimResults();

            String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class);
            if (array.length != 2) {
                BCLog.logger.info(String.format("Received an invalid add-facade request %s from mod %s",
                        m.getStringValue(), m.getSender()));
            } else {
                String blockName = array[0];
                Integer metaId = Ints.tryParse(array[1]);

                if (Strings.isNullOrEmpty(blockName) || metaId == null) {
                    BCLog.logger.info(String.format("Received an invalid add-facade request %s from mod %s",
                            m.getStringValue(), m.getSender()));
                } else {
                    Block block = (Block) Block.blockRegistry.getObject(blockName);
                    if (block.getRenderType() != 0 && block.getRenderType() != 31) {
                        BuildCraftTransport.facadeItem.addFacade(new ItemStack(block, 1, metaId));
                    } else {
                        logRedundantAddFacadeMessage(m, block.toString());
                    }
                }
            }
        } else if (m.isItemStackMessage()) {
            ItemStack modItemStack = m.getItemStackValue();

            Block block = Block.getBlockFromItem(modItemStack.getItem());
            if (block != null && block.getRenderType() != 0 && block.getRenderType() != 31) {
                BuildCraftTransport.facadeItem.addFacade(modItemStack);
            } else if (block != null) {
                logRedundantAddFacadeMessage(m, block.toString());
            }
        }
    } catch (Exception ex) {
    }
}

From source file:edu.mit.streamjit.tuner.RunApp.java

/**
 * Creates a new {@link Configuration} from the received python dictionary
 * string. This is not a good way to do.
 * <p>//from   ww w.jav a 2 s  .  co m
 * TODO: Need to add a method to {@link Configuration} so that the
 * configuration object can be updated from the python dict string. Now we
 * are destructing the old confg object and recreating a new one every time.
 * Not a appreciatable way.
 *
 * @param pythonDict
 *            Python dictionary string. Autotuner gives a dictionary of
 *            features with trial values.
 * @param config
 *            Old configuration object.
 * @return New configuration object with updated values from the pythonDict.
 */
private static Configuration rebuildConfiguration(String pythonDict, Configuration config) {
    // System.out.println(pythonDict);
    checkNotNull(pythonDict, "Received Python dictionary is null");
    pythonDict = pythonDict.replaceAll("u'", "");
    pythonDict = pythonDict.replaceAll("':", "");
    pythonDict = pythonDict.replaceAll("\\{", "");
    pythonDict = pythonDict.replaceAll("\\}", "");
    Splitter dictSplitter = Splitter.on(", ").omitEmptyStrings().trimResults();
    Configuration.Builder builder = Configuration.builder();
    System.out.println("New parameter values from Opentuner...");
    for (String s : dictSplitter.split(pythonDict)) {
        String[] str = s.split(" ");
        if (str.length != 2)
            throw new AssertionError("Wrong python dictionary...");
        Parameter p = config.getParameter(str[0]);
        if (p == null)
            continue;
        if (p instanceof IntParameter) {
            IntParameter ip = (IntParameter) p;
            builder.addParameter(
                    new IntParameter(ip.getName(), ip.getMin(), ip.getMax(), Integer.parseInt(str[1])));

        } else if (p instanceof SwitchParameter<?>) {
            SwitchParameter sp = (SwitchParameter) p;
            Class<?> type = sp.getGenericParameter();
            int val = Integer.parseInt(str[1]);
            SwitchParameter<?> sp1 = new SwitchParameter(sp.getName(), type, sp.getUniverse().get(val),
                    sp.getUniverse());
            builder.addParameter(sp1);
        }
    }
    return builder.build();
}

From source file:org.dcache.nfs.v3.MountServer.java

private static Inode path2Inode(VirtualFileSystem fs, String path) throws ChimeraNFSException, IOException {

    Splitter splitter = Splitter.on('/').omitEmptyStrings();
    Inode inode = fs.getRootInode();//from  w ww  . j ava2s.  co m

    for (String pathElement : splitter.split(path)) {
        inode = fs.lookup(inode, pathElement);
    }
    return inode;
}

From source file:com.mattc.launcher.util.Console.java

/**
 * Takes a Throwable and prints out the Stack Trace. This is <br />
 * basically equivalent to Throwable.printStackTrace().
 * /* ww w  .  j  a v  a2 s  .co  m*/
 * @param e
 */
public static void exception(Throwable e) {
    final Splitter splitter = Splitter.onPattern("\r?\n").trimResults().omitEmptyStrings();
    final Iterator<String> trace = splitter.split(Throwables.getStackTraceAsString(e)).iterator();

    error("===============EXCEPTION===============");
    error("");
    error(String.format("MESSAGE (T:%s): %s", e.getClass().getSimpleName(), e.getLocalizedMessage()));
    error(" " + trace.next());
    Iterators.advance(trace, 1);

    while (trace.hasNext()) {
        error(" \t" + trace.next());
    }

    logger.error("");
    logger.error("===============EXCEPTION===============");
}

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);
            }/*  ww w  .j  a v  a 2s .com*/

            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:com.github.steveash.jg2p.align.FilterWalkerDecorator.java

public static Set<Pair<String, String>> readFromFile(File file) throws IOException {
    Splitter splitter = Splitter.on('^').trimResults();
    List<String> lines = Files.readLines(file, Charsets.UTF_8);
    HashSet<Pair<String, String>> result = Sets.newHashSet();
    for (String line : lines) {
        if (isBlank(line)) {
            continue;
        }//  w  w  w .j a  v a 2  s.c  o m
        Iterator<String> fields = splitter.split(line).iterator();
        String x = fields.next();
        String y = fields.next();
        result.add(Pair.of(x, y));
    }
    return result;
}

From source file:com.streamsets.pipeline.lib.el.StringEL.java

@ElFunction(prefix = "str", name = "split", description = "Splits a string into a list by a separator")
public static List<Field> split(@ElParam("string") String string, @ElParam("separator") String separator) {
    if (Strings.isNullOrEmpty(string)) {
        return Collections.emptyList();
    }/*from w ww  .  j  a  v a  2  s. c  om*/

    Splitter splitter = Splitter.on(separator).trimResults().omitEmptyStrings();
    List<Field> fields = new ArrayList<>();
    splitter.split(string).iterator().forEachRemaining(e -> fields.add(Field.create(e)));
    return fields;
}