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.mapr.synth.samplers.StreetNameSampler.java

public StreetNameSampler() {
    Splitter onTabs = Splitter.on("\t");
    try {//from w  w  w .  ja v a 2s . c  om
        for (String line : Resources.readLines(Resources.getResource("street-name-seeds"), Charsets.UTF_8)) {
            if (!line.startsWith("#")) {
                Iterator<Multinomial<String>> i = sampler.iterator();
                for (String name : onTabs.split(line)) {
                    i.next().add(name, 1);
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Couldn't read built-in resource", e);
    }
}

From source file:com.google.devtools.build.android.resources.RClassWriter.java

/**
 * Builds the bytecode and writes out the R.class file, and R$inner.class files.
 *///  ww w.j a va 2 s  .c  om
public void write() throws IOException {
    Splitter splitter = Splitter.on('.');
    Iterable<String> folders = splitter.split(packageName);
    File packageDir = outFolder;
    for (String folder : folders) {
        packageDir = new File(packageDir, folder);
    }
    File rClassFile = new File(packageDir, SdkConstants.FN_COMPILED_RESOURCE_CLASS);
    Files.createParentDirs(rClassFile);
    String packageWithSlashes = packageName.replaceAll("\\.", "/");
    String rClassName = packageWithSlashes + "/R";
    ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classWriter.visit(JAVA_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER, rClassName,
            null, SUPER_CLASS, null);
    classWriter.visitSource(SdkConstants.FN_RESOURCE_CLASS, null);
    writeConstructor(classWriter);

    Table<String, String, SymbolEntry> symbols = getAllSymbols();
    Table<String, String, SymbolEntry> values = getSymbols(symbolValues);

    Set<String> rowSet = symbols.rowKeySet();
    List<String> rowList = new ArrayList<>(rowSet);
    Collections.sort(rowList);

    // Build the R.class w/ the inner classes, then later build the individual R$inner.class.
    for (String row : rowList) {
        String innerClassName = rClassName + "$" + row;
        classWriter.visitInnerClass(innerClassName, rClassName, row,
                Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC);
    }
    classWriter.visitEnd();
    Files.write(classWriter.toByteArray(), rClassFile);

    // Now generate the R$inner.class files.
    for (String row : rowList) {
        writeInnerClass(symbols, values, packageDir, rClassName, row);
    }
}

From source file:com.notifier.desktop.transport.usb.impl.Adb.java

public List<Device> devices() throws IOException, InterruptedException {
    Preconditions.checkNotNull(sdkHome, "Android SDK home has not been set");
    String output = runAdb("devices");
    Iterator<String> lines = Splitter.on('\n').trimResults().split(output).iterator();
    for (; lines.next().startsWith("*");) {
        ; // Ignore daemon messages
    }//  www  . jav a2  s.c o  m
    List<Device> devices = Lists.newArrayList();
    Splitter lineSplitter = Splitter.on('\t').trimResults();
    while (lines.hasNext()) {
        String line = lines.next();
        if (!line.isEmpty()) {
            Iterator<String> parts = lineSplitter.split(line).iterator();
            String serialNumber = parts.next();
            Device.Type type = Device.Type.parse(parts.next());
            devices.add(new Device(serialNumber, type));
        }
    }
    return devices;
}

From source file:blob.store.BlobStore.java

private void populateIndex() {
    try {/*from  w ww . ja  v  a 2 s . c o m*/
        Splitter splitter = Splitter.on(INDEX_LINE_SEPARATOR);
        for (String line : readLines(indexFile, UTF_8)) {
            Iterator<String> iterator = splitter.split(line).iterator();
            index.put(iterator.next(), iterator.next());
        }
    } catch (IOException e) {
        throw new BlobStoreException("Error while reading from the index file", e);
    } catch (NoSuchElementException e) {
        throw new BlobStoreException("Corrupt index file", e);
    }
}

From source file:org.splevo.ui.dashboard.ConfigurationTab.java

/**
 * Extract a label from a configuration key. The key will be split and concatenated again
 * separated by whitespaces.//  ww  w. ja  va2  s.  co m
 * 
 * @param configKey
 *            The key convert.
 * @return The resulting label.
 */
private String getLabelFromKey(String configKey) {
    Splitter splitter = Splitter.on(CharMatcher.anyOf(".")).omitEmptyStrings().trimResults();
    Joiner joiner = Joiner.on(" ").skipNulls();
    return joiner.join(splitter.split(configKey));
}

From source file:com.ning.metrics.collector.guice.module.EventSpoolWriterModule.java

/**
 * This method scans the system properties for properties with keys matching
 * the pattern for perEventSpoolWriterClasses
 * @return map of eventType (derived from property string) to list of
 *          spool writer class names//w ww.  ja  va  2 s.  c o m
 */
private Map<String, Iterable<String>> getSpoolWriterClassesByEventType() {

    Map<String, Iterable<String>> result = Maps.newHashMap();
    Splitter splitter = Splitter.on(",").trimResults().omitEmptyStrings();

    for (Map.Entry keyValue : System.getProperties().entrySet()) {

        Matcher matcher = perEventSpoolWriterClassesPattern.matcher((String) keyValue.getKey());

        if (matcher.matches()) {
            result.put(matcher.group(1), splitter.split((String) keyValue.getValue()));
        }
    }

    return result;
}

From source file:org.wso2.siddhi.debs2016.graph.GraphAnalyzer.java

/**
 * Displays the friendship graph//from   w ww .jav  a2 s.com
 *
 * @param displayWhileLoading true will display while stream is processing
 * @param numberOfEventsToLoad will limit the number of events to load
 * @param updateRate speed at which graph grows
 */
private void loadFriendshipGraph(boolean displayWhileLoading, int numberOfEventsToLoad, int updateRate) {

    if (displayWhileLoading) {
        graph.display();
    }

    int count = 0;

    try {
        Splitter splitter = Splitter.on('|');
        BufferedReader br = new BufferedReader(
                new FileReader("/Users/malithjayasinghe/debs2016/DataSet/data" + "/friendships.dat"),
                10 * 1024 * 1024);
        String line = br.readLine();
        while (line != null) {
            Iterator<String> dataStrIterator = splitter.split(line).iterator();
            Long user1ID = Long.parseLong(dataStrIterator.next());
            Long user2ID = Long.parseLong(dataStrIterator.next());

            if (updateRate > 0) {
                try {
                    Thread.sleep(updateRate);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            addEdge(user1ID, user2ID);
            line = br.readLine();
            count++;

            if (count == numberOfEventsToLoad) {
                break;
            }

        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.myrrix.common.LoadRunner.java

/**
 * @param client recommender to load/*from  www .ja  v a2 s  .  c o m*/
 * @param dataDirectory a directory containing data files from which user and item IDs should be read
 * @param steps number of load steps to run
 */
public LoadRunner(MyrrixRecommender client, File dataDirectory, int steps) throws IOException {
    Preconditions.checkNotNull(client);
    Preconditions.checkNotNull(dataDirectory);
    Preconditions.checkArgument(steps > 0);

    log.info("Reading IDs...");
    FastIDSet userIDsSet = new FastIDSet();
    FastIDSet itemIDsSet = new FastIDSet();
    Splitter comma = Splitter.on(',');
    for (File f : dataDirectory.listFiles(new PatternFilenameFilter(".+\\.csv(\\.(zip|gz))?"))) {
        for (CharSequence line : new FileLineIterable(f)) {
            Iterator<String> it = comma.split(line).iterator();
            userIDsSet.add(Long.parseLong(it.next()));
            itemIDsSet.add(Long.parseLong(it.next()));
        }
    }

    this.client = client;
    this.uniqueUserIDs = userIDsSet.toArray();
    this.uniqueItemIDs = itemIDsSet.toArray();
    this.steps = steps;
}

From source file:io.prestosql.server.HttpRequestSessionContext.java

private Set<String> parseClientTags(HttpServletRequest servletRequest) {
    Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings();
    return ImmutableSet.copyOf(splitter.split(nullToEmpty(servletRequest.getHeader(PRESTO_CLIENT_TAGS))));
}

From source file:co.cask.cdap.shell.util.AsciiTable.java

/**
 * Generates a record row. A record row can span across multiple lines on the screen.
 *
 * @param columns The set of columns to output.
 * @param collection Collection for collecting the generated {@link Row} object.
 * @return Returns true if the row spans multiple lines.
 *//*  w ww . j a  v  a2  s .co  m*/
private boolean generateRow(Object[] columns, Collection<? super Row> collection) {
    ImmutableList.Builder<Cell> builder = ImmutableList.builder();

    boolean multiLines = false;
    Splitter splitter = Splitter.on(System.getProperty("line.separator"));
    for (Object field : columns) {
        String fieldString = field == null ? "" : field.toString();
        Cell cell = new Cell(splitter.split(fieldString));
        multiLines = multiLines || cell.size() > 1;
        builder.add(cell);
    }

    collection.add(new Row(builder.build()));
    return multiLines;
}