Example usage for java.util HashSet HashSet

List of usage examples for java.util HashSet HashSet

Introduction

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

Prototype

public HashSet(int initialCapacity) 

Source Link

Document

Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75).

Usage

From source file:Main.java

@SuppressWarnings("unchecked")
public static Collection<? extends Object> getUnion(Collection<? extends Object> list1,
        Collection<? extends Object> list2) {
    @SuppressWarnings("rawtypes")
    Collection union = new HashSet(list1);
    union.addAll(list2);/*from  w  ww. j av a2s.  co m*/
    return union;
}

From source file:Main.java

/**
 * Creates a new list with the given elements
 * @param values//from  w  w  w  .  j  ava  2  s .co m
 * @return
 */
@SafeVarargs
public static <T> Set<T> newSet(T... values) {
    HashSet<T> set = new HashSet<>(values.length);
    for (T element : values) {
        set.add(element);
    }

    return set;
}

From source file:Main.java

@SafeVarargs
public static <T> Set<T> toSet(T... array) {
    if (isEmpty(array)) {
        return new HashSet<>(0);
    }//from   w  ww.j a v a  2  s. c o m
    return new HashSet<>(Arrays.asList(array));
}

From source file:com.wakacommerce.common.util.PomEvaluator.java

/**
 * @param args/*from ww w. ja v  a2s .c  om*/
 */
public static void main(String[] args) {
    initializeKnownLibraries();
    BufferedReader br = null;

    try {
        String fileName = "/Users/brianpolster/blc-workspace/BroadleafCommerce/pom.xml";
        if (args.length > 0) {
            fileName = args[0];
        }

        br = new BufferedReader(new FileReader(fileName));

        forwardToTag("<dependencies>", br);

        List<Dependency> dependencies = populateDependencies(br);

        for (Dependency dependency : dependencies) {
            Category category = knownLibraries.get(dependency.groupId);
            if (category != null) {
                category.dependencyList.add(dependency);
                List<Dependency> licenseDependencyList = licenseDependencyMap.get(category.licenseType);
                if (licenseDependencyList == null) {
                    licenseDependencyList = new ArrayList<Dependency>();
                    licenseDependencyList.add(dependency);
                    licenseDependencyMap.put(category.licenseType, licenseDependencyList);
                }

            } else {

                if (dependency.scope != null
                        && (dependency.scope.equals("test") || dependency.scope.equals("provided"))) {
                    continue;
                }
                OTHER.dependencyList.add(dependency);
            }
        }

        Set<Category> categoryList = new HashSet<Category>(knownLibraries.values());

        System.out.println("Related Software Report\r");

        for (Category category : categoryList) {
            printOutDependencies(category, category.dependencyList);
        }

        if (OTHER.dependencyList.size() > 0) {
            printOutDependencies(OTHER, OTHER.dependencyList);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null)
                br.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:Main.java

public static <T> Set<T> makeSet(int size) {
    return new HashSet<T>(size);
}

From source file:Main.java

final static public Set<Object> createSet(final int size) {
    return new HashSet<Object>(size);
}

From source file:Main.java

public static Set<Integer> asSet(int... data) {
    return new HashSet<Integer>(asList(data));
}

From source file:Main.java

/**
 * Create a new {@link HashSet} from an existing set and another element.
 *
 * @param existing/*w w  w  .j  ava  2 s.  co  m*/
 * @param element
 * @return
 */
public static <T> HashSet<T> joinToHashSet(Set<T> existing, T element) {
    final HashSet<T> visitedWithNewPoint = new HashSet<T>(existing);

    visitedWithNewPoint.add(element);

    return visitedWithNewPoint;
}

From source file:Main.java

public static void setTabFocusTraversalKeys(final JComponent component) {
    component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            new HashSet<AWTKeyStroke>(Arrays.asList(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))));
    component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, new HashSet<AWTKeyStroke>(
            Arrays.asList(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))));
}

From source file:Main.java

public final static <T> Set<T> unicon(Set<T> set1, Set<T> set2) {
    Set<T> set = new HashSet<>(set1.size() + set2.size());
    set = set1;/*from  www  . j a  v a2s  . co m*/
    set.addAll(set2);
    return set;
}