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

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

Introduction

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

Prototype

public static <E> LinkedHashSet<E> newLinkedHashSet() 

Source Link

Document

Creates a mutable, empty LinkedHashSet instance.

Usage

From source file:com.griddynamics.jagger.coordinator.zookeeper.tester.CoordinatorConsumer.java

public static void main(String[] args) {
    ZooKeeperFactory zooKeeperFactory = new ZooKeeperFactory();
    zooKeeperFactory.setConnectString("localhost:2181");
    zooKeeperFactory.setSessionTimeout(1000000);
    Zoo zoo = new Zoo(zooKeeperFactory.create());
    ZNode root = zoo.root().child(args[0]);

    Coordinator coordinator = new ZookeeperCoordinator(root, Executors.newSingleThreadExecutor());

    Set<Worker> workers = Sets.newLinkedHashSet();
    workers.add(new PrintValWorker());
    NodeId id = NodeId.kernelNode("my-kernel");
    try {//from  ww w. ja  va  2  s. co  m
        coordinator.registerNode(Coordination.emptyContext(id), workers, new StatusChangeListener() {
            @Override
            public void onNodeStatusChanged(NodeId nodeId, NodeStatus status) {
                System.out.println(nodeId + " " + status);
            }

            @Override
            public void onCoordinatorDisconnected() {
                System.out.println("Coordinator disconnected");
            }

            @Override
            public void onCoordinatorConnected() {
                System.out.println("Coordinator connected");
            }
        });
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }

    while (true) {
    }

}

From source file:com.yahoo.yqlplus.engine.internal.java.backends.java.KeyAccumulator.java

public static KeyAccumulator concat(List<KeyAccumulator> cursors) {
    final LinkedHashSet<Object> out = Sets.newLinkedHashSet();
    for (KeyAccumulator cursor : cursors) {
        for (Object key : cursor) {
            out.add(key);// www.  j  a  va  2s  . co m
        }
    }
    return new KeyAccumulator() {
        @Override
        protected Record createKey(List columns) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Iterator iterator() {
            return out.iterator();
        }
    };
}

From source file:org.carrot2.text.linguistic.TextResourceUtils.java

/**
 * Loads words from a given {@link IResource} (one word per line).
 *//*from w  ww  .  j a  va  2 s . c  o m*/
public static Set<String> load(IResource wordsResource) throws IOException {
    final InputStream is = wordsResource.open();
    if (is == null) {
        throw new IOException("Resource stream handle is null: " + wordsResource);
    }

    final Set<String> words = Sets.newLinkedHashSet();
    final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line.startsWith("#") || line.length() == 0) {
                continue;
            }

            words.add(line);
        }
    } finally {
        reader.close();
    }

    return words;
}

From source file:org.gradle.internal.component.model.AttributeSelectionUtils.java

public static Attribute<?>[] collectExtraAttributes(AttributeSelectionSchema schema,
        ImmutableAttributes[] candidateAttributeSets, ImmutableAttributes requested) {
    Set<Attribute<?>> extraAttributes = Sets.newLinkedHashSet();
    for (ImmutableAttributes attributes : candidateAttributeSets) {
        extraAttributes.addAll(attributes.keySet());
    }/*from ww  w  .j a va  2 s . co  m*/
    extraAttributes.removeAll(requested.keySet());
    Attribute<?>[] extraAttributesArray = extraAttributes.toArray(new Attribute[0]);
    for (int i = 0; i < extraAttributesArray.length; i++) {
        Attribute<?> extraAttribute = extraAttributesArray[i];
        Attribute<?> schemaAttribute = schema.getAttribute(extraAttribute.getName());
        if (schemaAttribute != null) {
            extraAttributesArray[i] = schemaAttribute;
        }
    }
    return extraAttributesArray;
}

From source file:brooklyn.entity.rebind.TreeUtils.java

public static Collection<Location> findLocationsInHierarchy(Location root) {
    Set<Location> result = Sets.newLinkedHashSet();

    Deque<Location> tovisit = new ArrayDeque<Location>();
    tovisit.addFirst(root);/*from  w  w  w . j av a  2s  . c o  m*/

    while (tovisit.size() > 0) {
        Location current = tovisit.pop();
        result.add(current);
        for (Location child : current.getChildren()) {
            if (child != null) {
                tovisit.push(child);
            }
        }
    }

    Location parentLocation = root.getParent();
    while (parentLocation != null) {
        result.add(parentLocation);
        parentLocation = parentLocation.getParent();
    }

    return result;
}

From source file:zipkin.storage.elasticsearch.http.PseudoAddressRecordSet.java

static Dns create(List<String> urls, Dns actualDns) {
    Set<String> schemes = Sets.newLinkedHashSet();
    Set<String> hosts = Sets.newLinkedHashSet();
    Set<InetAddress> ipAddresses = Sets.newLinkedHashSet();
    Set<Integer> ports = Sets.newLinkedHashSet();

    for (String url : urls) {
        HttpUrl httpUrl = HttpUrl.parse(url);
        schemes.add(httpUrl.scheme());// ww  w. j av  a 2  s . c  o  m
        if (InetAddresses.isInetAddress(httpUrl.host())) {
            ipAddresses.add(InetAddresses.forString(httpUrl.host()));
        } else {
            hosts.add(httpUrl.host());
        }
        ports.add(httpUrl.port());
    }

    checkArgument(ports.size() == 1, "Only one port supported with multiple hosts %s", urls);
    checkArgument(schemes.size() == 1 && schemes.iterator().next().equals("http"),
            "Only http supported with multiple hosts %s", urls);

    if (hosts.isEmpty())
        return new StaticDns(ipAddresses);
    return new ConcatenatingDns(ipAddresses, hosts, actualDns);
}

From source file:org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil.java

@NotNull
public static Set<JetType> getValues(@Nullable TypeConstraints typeConstraints) {
    Set<JetType> values = Sets.newLinkedHashSet();
    if (typeConstraints != null && !typeConstraints.isEmpty()) {
        values.addAll(typeConstraints.getExactBounds());
        if (!typeConstraints.getLowerBounds().isEmpty()) {
            JetType superTypeOfLowerBounds = CommonSupertypes.commonSupertype(typeConstraints.getLowerBounds());
            for (JetType value : values) {
                if (!JetTypeChecker.INSTANCE.isSubtypeOf(superTypeOfLowerBounds, value)) {
                    values.add(superTypeOfLowerBounds);
                    break;
                }//from www .ja v a 2s  .  c o m
            }
            if (values.isEmpty()) {
                values.add(superTypeOfLowerBounds);
            }
        }
        if (!typeConstraints.getUpperBounds().isEmpty()) {
            //todo subTypeOfUpperBounds
            JetType subTypeOfUpperBounds = typeConstraints.getUpperBounds().iterator().next(); //todo
            for (JetType value : values) {
                if (!JetTypeChecker.INSTANCE.isSubtypeOf(value, subTypeOfUpperBounds)) {
                    values.add(subTypeOfUpperBounds);
                    break;
                }
            }
            if (values.isEmpty()) {
                values.add(subTypeOfUpperBounds);
            }
        }
    }
    return values;
}

From source file:com.puppetlabs.geppetto.pp.dsl.ui.preferences.editors.GlobPatternFieldEditor.java

public static Set<String> parseGlobPatterns(String filter) {
    if (filter != null) {
        filter = filter.trim();/*ww  w  . j a  v  a  2  s  .  co  m*/
        if (filter.length() > 0) {
            StringTokenizer st = new StringTokenizer(filter, ":\n\r");
            Set<String> v = Sets.newLinkedHashSet();
            while (st.hasMoreElements())
                v.add(((String) st.nextElement()).trim());
            return v;
        }
    }
    return Collections.emptySet();
}

From source file:net.roddrim.number5.tools.collect.FluentSet.java

public static <E> FluentSet<E> ofNewLinkedHashSet() {
    return of(Sets.newLinkedHashSet());
}

From source file:com.cinchapi.concourse.util.TSets.java

/**
 * Return a Set that contains only the elements that are in both {@code a}
 * and {@code b}./*from  w w w .  java  2 s  .  c om*/
 * 
 * @param a
 * @param b
 * @return the intersection of the Sets
 */
public static <T> Set<T> intersection(Set<T> a, Set<T> b) {
    if (a instanceof SortedSet && b instanceof SortedSet) {
        return sortedIntersection((SortedSet<T>) a, (SortedSet<T>) b);
    } else {
        Set<T> intersection = Sets.newLinkedHashSet();
        Set<T> smaller = a.size() <= b.size() ? a : b;
        Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b);
        for (T element : smaller) {
            if (larger.contains(element)) {
                intersection.add(element);
            }
        }
        return intersection;
    }
}