Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:Main.java

public static void getAllFileAndFolder(File folder, Set<File> all) {
    all.add(folder);
    if (folder.isFile()) {
        return;//from   w  w w . j a  v  a2s.  c  o m
    }
    for (File file : folder.listFiles()) {
        all.add(file);
        if (file.isDirectory()) {
            getAllFileAndFolder(file, all);
        }
    }
}

From source file:Set2.java

public static Set fill(Set a, int size) {
    for (int i = 0; i < size; i++)
        a.add(new Integer(i));
    return a;//from w ww .  ja  v  a 2 s . co  m
}

From source file:Main.java

public static <T> Set<T> toSet(T element) {
    Set<T> set = new HashSet<T>(1);
    set.add(element);
    return set;//from w  ww.ja  va  2s  . co m
}

From source file:Main.java

/**
A set with the given element./*from w ww  . j  a  v a2  s  .  c  o m*/
 */
public static <T> Set<T> a(T root) {
    Set<T> result = new HashSet<T>();
    result.add(root);
    return result;
}

From source file:Main.java

public static Set setWith(Object anElement) {
    Set asSet = new HashSet();
    asSet.add(anElement);
    return asSet;
}

From source file:Main.java

public static Set<String> getAvailableIds() {
    Set<String> ids = new HashSet<>();
    ids.add(POOL1_NAME);
    ids.add(POOL2_NAME);//from www. j  av a2  s  . c  om
    return ids;
}

From source file:Main.java

public static Set setWith(Object anElement, Object anotherElement) {
    Set asSet = setWith(anElement);
    asSet.add(anotherElement);
    return asSet;
}

From source file:Main.java

public static <T> Set<T> immutableSet(T element) {
    Set<T> immutableSet = new HashSet<T>();
    immutableSet.add(element);
    return immutableSet(immutableSet);
}

From source file:Main.java

private static String makeUniqueName(String name, Set<String> seenElements) {
    if (!seenElements.add(name)) {
        int suffix = 2;
        while (true) {
            String newName = name + suffix++;
            if (seenElements.add(newName)) {
                name = newName;/*from   ww w . j  av  a  2s .  com*/
                break;
            }
        }
    }
    return name;
}

From source file:MainClass.java

public static Set fill(Set a, int size) {
    for (int i = 0; i < size; i++)
        a.add(new MyType(i));
    return a;/* w  w  w. j a  v a  2  s.  c  o m*/
}