Example usage for java.util LinkedHashSet LinkedHashSet

List of usage examples for java.util LinkedHashSet LinkedHashSet

Introduction

In this page you can find the example usage for java.util LinkedHashSet LinkedHashSet.

Prototype

public LinkedHashSet() 

Source Link

Document

Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).

Usage

From source file:Main.java

public static <T> LinkedHashSet<T> getDuplicates(final Iterable<T> iterable) {
    LinkedHashSet<T> duplicates = new LinkedHashSet<>();
    Set<T> dupeChecker = new LinkedHashSet<>();
    iterable.forEach((m) -> {//  w  w  w  . j  av  a 2  s.co m
        if (!dupeChecker.add(m)) {
            duplicates.add(m);
        }
    });
    return duplicates;
}

From source file:Main.java

public static final <E> LinkedHashSet<E> createLinkedHashSet(E... elements) {
    LinkedHashSet<E> list = new LinkedHashSet<E>();
    addToCollection(list, elements);//from w  w w.  j  ava2  s . c om
    return list;
}

From source file:Main.java

public static LinkedHashSet<String> convertStringToSet(String input) {
    String[] array = input.split(",");
    LinkedHashSet<String> list = new LinkedHashSet<>();
    for (int i = 0; i < array.length; i++) {
        list.add(array[i]);//w  ww  .j  a  v  a2s .co  m
    }
    return list;
}

From source file:Main.java

private static <K, T> void add(Map<K, Set<T>> map, K key, T val) {
    Set<T> n = map.get(key);
    if (null == n) {
        n = new LinkedHashSet<T>();
        map.put(key, n);/*from  w w w  .ja va  2 s  .c  o  m*/
    }
    n.add(val);
}

From source file:Main.java

public static Set<Node> getChildrenElements(Node node) {
    final Set<Node> result = new LinkedHashSet<>();

    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.TEXT_NODE) {
            result.add(child);//from  w w  w  . ja  v  a2  s  . com
        }
    }

    return result;
}

From source file:Main.java

public static <T> LinkedHashSet<T> createLinkedHashSet() {
    return new LinkedHashSet<T>();
}

From source file:Main.java

public static Set<Node> findChildElementsByTag(Node node, String tag) {
    final Set<Node> result = new LinkedHashSet<>();

    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (tag.equals(child.getNodeName())) {
            result.add(child);//from  w w w . j a v a2 s  .  c  o  m
        } else if (child.hasChildNodes()) {
            result.addAll(findChildElementsByTag(child, tag));
        }
    }

    return result;
}

From source file:Main.java

/**
 * Create new {@link java.util.LinkedHashSet}.
 *
 * @param <K>//  ww w .  j a  v a2s . c o  m
 *            key
 * @return {@link java.util.LinkedHashSet}
 */
public static <K> Set<K> newLinkedHashSet() {
    return new LinkedHashSet<K>();
}

From source file:Main.java

/**
 * create set from array/*from   w ww  .  j  ava 2s.c  om*/
 *
 * @param <T>
 * @param values
 * @return array values in list
 */
public static <T> Set<T> toSet(T... values) {
    Set<T> list = new LinkedHashSet<T>();
    list.addAll(Arrays.asList(values));
    return list;
}

From source file:Main.java

public static <T, V extends T> LinkedHashSet<T> createLinkedHashSet(V... args) {
    if ((args == null) || (args.length == 0)) {
        return new LinkedHashSet();
    }//w ww.  j a  v  a2 s . co  m
    LinkedHashSet<T> set = new LinkedHashSet(args.length);
    for (V v : args) {
        set.add(v);
    }
    return set;
}