Example usage for com.google.common.collect Sets newHashSet

List of usage examples for com.google.common.collect Sets newHashSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newHashSet.

Prototype

public static <E> HashSet<E> newHashSet(Iterator<? extends E> elements) 

Source Link

Document

Creates a mutable HashSet instance containing the given elements.

Usage

From source file:mtsar.api.csv.WorkerCSV.java

public static Iterator<Worker> parse(Stage stage, CSVParser csv) {
    final Set<String> header = csv.getHeaderMap().keySet();
    checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s",
            String.join(",", header));

    return StreamSupport.stream(csv.spliterator(), false).map(row -> {
        final String id = row.isSet("id") ? row.get("id") : null;
        final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags"))
                ? row.get("tags").split("\\|")
                : new String[0];
        final String datetime = row.isSet("datetime") ? row.get("datetime") : null;

        return new Worker.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id))
                .setStage(stage.getId()).addAllTags(Arrays.asList(tags))
                .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis()
                        : Long.parseLong(datetime) * 1000L))
                .build();/*  ww w  . j  av a2s  . c o m*/
    }).iterator();
}

From source file:org.sitemap4j.sitemap.url.ChangeFrequency.java

static public Set<ChangeFrequency> getAll() {
    return Sets.newHashSet(AvailableFrequenciesTable.values());
}

From source file:org.auraframework.impl.context.AbstractRegistryAdapterImpl.java

protected static <T extends Definition> DefRegistry createDefRegistry(DefFactory<T> factory, DefType defType,
        String prefix) {/* w w w.ja  v  a  2s  .c om*/
    return createDefRegistry(factory, EnumSet.of(defType), Sets.newHashSet(prefix));
}

From source file:org.thiesen.collections.set.impl.MutableHashSet.java

public static <T> MutableHashSet<T> copyOf(final T... elements) {
    return new MutableHashSet<T>(Sets.newHashSet(elements));
}

From source file:at.molindo.notify.model.Message.java

public static Message parse(String str, IRenderService.Type type) throws RenderException {

    Set<String> required = Sets.newHashSet(REQUIRED_FIELDS);
    Map<String, String> fieldValues = Maps.newHashMap();

    Message rendered = new Message();
    rendered.setType(type);//from   www  . java  2s  .  c om

    StringBuilder body = null;
    for (String line : StringUtils.split(str, "\n")) {
        if (body == null) {
            if (StringUtils.empty(StringUtils.trim(line))) {
                body = new StringBuilder();
            } else {
                int split = line.indexOf(':');
                if (split < 0) {
                    throw new RenderException("illegal line: " + line);
                }
                String fieldName = line.substring(0, split).trim();
                String fieldValue = line.substring(split + 1).trim();

                if (!SUPPORTED_FIELDS.contains(fieldName)) {
                    throw new RenderException("unknown field: " + fieldName);
                }

                fieldValues.put(fieldName, fieldValue);
            }
        } else if (body.length() > 0 || !StringUtils.empty(StringUtils.trim(line))) {
            body.append(line).append("\n");
        }
    }

    required.removeAll(fieldValues.keySet());
    if (required.size() > 0) {
        throw new RenderException("missing fields: " + required);
    }

    if (body == null || body.length() == 0) {
        throw new RenderException("empty body");
    }
    // remove trailing \n
    body.setLength(body.length() - 1);

    rendered.setSubject(fieldValues.get(FIELD_SUBJECT));
    rendered.setMessage(body.toString());

    return rendered;
}

From source file:com.opengamma.web.analytics.blotter.PropertyFilter.java

PropertyFilter(MetaProperty<?>... properties) {
    ArgumentChecker.notNull(properties, "properties");
    _properties = Sets.newHashSet(Arrays.asList(properties));
}

From source file:org.ow2.proactive.connector.iaas.fixtures.NetworkFixtures.java

public static Network simpleNetwork() {
    return new Network(Sets.newHashSet("netowrkId"), Sets.newHashSet("publicAddress"),
            Sets.newHashSet("privateAddress"));
}

From source file:org.eclipse.che.plugin.testing.junit.ide.JUnitTestFileExtension.java

public JUnitTestFileExtension() {
    jUnitExtensions = Sets.newHashSet(".java");
}

From source file:mtsar.api.csv.TaskCSV.java

public static Iterator<Task> parse(Stage stage, CSVParser csv) {
    final Set<String> header = csv.getHeaderMap().keySet();
    checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s",
            String.join(",", header));

    return StreamSupport.stream(csv.spliterator(), false).map(row -> {
        final String id = row.isSet("id") ? row.get("id") : null;
        final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags"))
                ? row.get("tags").split("\\|")
                : new String[0];
        final String type = row.get("type");
        final String description = row.isSet("description") ? row.get("description") : null;
        final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers"))
                ? row.get("answers").split("\\|")
                : new String[0];
        final String datetime = row.isSet("datetime") ? row.get("datetime") : null;

        return new Task.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id))
                .setStage(stage.getId()).addAllTags(Arrays.asList(tags))
                .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis()
                        : Long.parseLong(datetime) * 1000L))
                .setType(StringUtils.defaultIfEmpty(type, TaskDAO.TASK_TYPE_SINGLE)).setDescription(description)
                .addAllAnswers(Arrays.asList(answers)).build();
    }).iterator();/* w  w w.  j a v a 2  s  .co m*/
}

From source file:io.wcm.caravan.commons.stream.Collectors.java

/**
 * Collect to hash set//from  ww  w . j a v  a  2 s .  co  m
 * @param <T> Streaming type
 * @return Hash set
 */
public static <T> Collector<T, Set<T>> toSet() {
    return new Collector<T, Set<T>>() {
        @Override
        public Set<T> collect(Stream<? extends T> stream) {
            return Sets.newHashSet(stream.iterator());
        }
    };
}