Package com.google.common.base

Examples of com.google.common.base.Splitter


        setupIndex();
    }

    private void readDelimitedData(String lookup, List<String> lines) {
        Splitter splitter;
        if (lookup.matches(".*\\.csv")) {
            splitter = Splitter.on(",");
        } else if (lookup.matches(".*\\.tsv")) {
            splitter = Splitter.on("\t");
        } else {
            throw new IllegalArgumentException("Must have file with .csv, .tsv or .json suffix");
        }

        List<String> names = Lists.newArrayList(splitter.split(lines.get(0)));
        JsonNodeFactory nf = JsonNodeFactory.withExactBigDecimals(false);
        ArrayNode localData = nf.arrayNode();
        for (String line : lines.subList(1, lines.size())) {
            ObjectNode r = nf.objectNode();
            List<String> fields = Lists.newArrayList(splitter.split(line));
            Preconditions.checkState(names.size() == fields.size(), "Wrong number of fields, expected ", names.size(), fields.size());
            Iterator<String> ix = names.iterator();
            for (String field : fields) {
                r.put(ix.next(), field);
            }
View Full Code Here


    List<Multinomial<String>> sampler = ImmutableList.of(
            new Multinomial<String>(), new Multinomial<String>(), new Multinomial<String>()
    );

    public StreetNameSampler() {
        Splitter onTabs = Splitter.on("\t");
        try {
            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) {
View Full Code Here

    }

    protected void readDistribution(String resourceName) {
        try {
            if (distribution.compareAndSet(null, new Multinomial<String>())) {
                Splitter onTab = Splitter.on("\t").trimResults();
                for (String line : Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8)) {
                    if (!line.startsWith("#")) {
                        Iterator<String> parts = onTab.split(line).iterator();
                        String name = translate(parts.next());
                        double weight = Double.parseDouble(parts.next());
                        distribution.get().add(name, weight);
                    }
                }
View Full Code Here

    public NameSampler() {
        try {
            if (first.compareAndSet(null, new Multinomial<String>())) {
                Preconditions.checkState(last.getAndSet(new Multinomial<String>()) == null);

                Splitter onTab = Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().trimResults();
                for (String resourceName : ImmutableList.of("dist.male.first", "dist.female.first")) {
                    for (String line : Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8)) {
                        if (!line.startsWith("#")) {
                            Iterator<String> parts = onTab.split(line).iterator();
                            String name = initialCap(parts.next());
                            double weight = Double.parseDouble(parts.next());
                            if (first.get().getWeight(name) == 0) {
                                first.get().add(name, weight);
                            } else {
                                // do this instead of add because some first names may appear more than once
                                first.get().set(name, first.get().getWeight(name) + weight);
                            }
                        }
                    }
                }

                for (String line : Resources.readLines(Resources.getResource("dist.all.last"), Charsets.UTF_8)) {
                    if (!line.startsWith("#")) {
                        Iterator<String> parts = onTab.split(line).iterator();
                        String name = initialCap(parts.next());
                        double weight = Double.parseDouble(parts.next());
                        last.get().add(name, weight);
                    }
                }
View Full Code Here

    private String pad(String s, int length, String padding) {
        return (s + padding).substring(0, length);
    }

    private static Map<String, String> mapResource(String name) throws IOException {
        final Splitter onTab = Splitter.on("\t");

        return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<Map<String, String>>() {
            final Map<String, String> r = Maps.newHashMap();

            @Override
            public boolean processLine(String line) throws IOException {
                Iterator<String> pieces = onTab.split(line).iterator();
                String key = pieces.next();
                r.put(key, pieces.next());
                return true;
            }
View Full Code Here

            }
        });
    }

    private static SetMultimap<String, String> multiMapResource(String name) throws IOException {
        final Splitter onTab = Splitter.on("\t");

        return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<SetMultimap<String, String>>() {
            final SetMultimap<String, String> r = HashMultimap.create();

            @Override
            public boolean processLine(String line) throws IOException {
                Iterator<String> pieces = onTab.split(line).iterator();
                String key = pieces.next();
                r.put(key, pieces.next());
                return true;
            }
View Full Code Here

        if (getName().getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)) {
            return;
        }

        // everything else should be merged, duplicates should be eliminated.
        Splitter splitter = Splitter.on(',');
        ImmutableSet.Builder<String> targetValues = ImmutableSet.builder();
        targetValues.addAll(splitter.split(higherPriority.getValue()));
        targetValues.addAll(splitter.split(getValue()));
        higherPriority.getXml().setValue(Joiner.on(',').join(targetValues.build()));
    }
View Full Code Here

    return createPrefix(groupId, relevantArtifactId);
  }

  @Nonnull
  private static String createPrefix(@Nonnull String relevantGroupId, @Nonnull String relevantArtifactId) {
    Splitter splitter = Splitter.on(new PackageSeparatorCharMatcher());

    List<String> partsList = Lists.newArrayList(splitter.split(relevantGroupId));
    partsList.addAll(Lists.<String>newArrayList(splitter.split(relevantArtifactId)));


    return Joiner.on(File.separator).join(partsList);
  }
View Full Code Here

   */
  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()));
View Full Code Here

        mSymbols = symbols;
        mValues = values;
    }

    void write() throws IOException {
        Splitter splitter = Splitter.on('.');
        Iterable<String> folders = splitter.split(mPackageName);
        File file = new File(mOutFolder);
        for (String folder : folders) {
            file = new File(file, folder);
        }
        file.mkdirs();
View Full Code Here

TOP

Related Classes of com.google.common.base.Splitter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.