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 final <T> Set<T> setOf(final T... elements) {
    final Set<T> set = new HashSet<T>();

    for (final T t : elements) {
        set.add(t);
    }// w  w  w. j a  v a  2s  .c  o m

    return set;
}

From source file:Main.java

/**
 * Build a set from any {@link Iterator}.
 * @param it/*from  w w  w. ja va  2  s.co  m*/
 * @return
 */
public static <E> Set<E> buildSetFromIterator(final Iterator<E> it) {
    final Set<E> set = new HashSet<>();

    while (it.hasNext()) {
        set.add(it.next());
    }

    return set;
}

From source file:Main.java

public static String[] union(String[] arr1, String[] arr2) {
    Set<String> set = new HashSet<>();
    for (String str : arr1) {
        set.add(str);
    }// ww w.  j  a v a 2s  . c o m
    for (String str : arr2) {
        set.add(str);
    }
    String[] result = {};
    return set.toArray(result);
}

From source file:Main.java

static void findAllInterfaces(Class c, Set<Class> interfaces) {
    if (c.isInterface()) {
        interfaces.add(c);
    }/* ww w.  j  a  v  a 2s.  c o m*/
    Class s = c.getSuperclass();
    if (s != null) {
        findAllInterfaces(s, interfaces);
    }
    Class[] is = c.getInterfaces();
    for (int i = 0; i < is.length; i++) {
        findAllInterfaces(is[i], interfaces);
    }
}

From source file:Main.java

/**
 * Turns a var arg list into a set./* w  w w.j a  v  a2s.  c  o  m*/
 * <p/>
 * Returns a {@link java.util.HashSet}.
 */
public static <A> Set<A> asSet(A... as) {
    Set<A> r = new HashSet<A>(as.length);
    for (A a : as)
        r.add(a);
    return r;
}

From source file:com.kurtraschke.wsf.gtfsrealtime.WSFRealtimeModule.java

public static void addModuleAndDependencies(Set<Module> modules) {
    modules.add(new WSFRealtimeModule());
    GtfsRealtimeExporterModule.addModuleAndDependencies(modules);
    JSR250Module.addModuleAndDependencies(modules);
}

From source file:Main.java

public static <T> Set<T> toTreeSet(Collection<T> collection, Comparator<T> comparator) {
    final Set<T> treeSet = new TreeSet<>(comparator);
    for (T t : collection) {
        treeSet.add(t);
    }//  w  ww .  j  a v a 2 s.c  o m
    return treeSet;
}

From source file:Main.java

private static void extractPrefix(String prefix, Set<String> prefixes) {
    if (prefix != null) {
        prefixes.add(prefix);
    }/*from   w  w  w.ja  v a2 s  .c  om*/
}

From source file:eval.dataset.ParseWikiLog.java

private static void updateMap(TreeMap<String, Set<String>> userPageMap, String user, String page) {
    if (userPageMap.containsKey(user)) {
        userPageMap.get(user).add(page);
    } else {/*from ww  w  . j  ava2  s. co  m*/
        Set<String> pageSet = new TreeSet();
        pageSet.add(page);
        userPageMap.put(user, pageSet);
    }

}

From source file:Main.java

public static boolean isShootingStatus(String currentStatus) {
    Set<String> shootingStatus = new HashSet<>();
    shootingStatus.add("IDLE");
    shootingStatus.add("StillCapturing");
    shootingStatus.add("StillSaving");
    shootingStatus.add("MovieWaitRecStart");
    shootingStatus.add("MovieRecording");
    shootingStatus.add("MovieWaitRecStop");
    shootingStatus.add("MovieSaving");
    shootingStatus.add("IntervalWaitRecStart");
    shootingStatus.add("IntervalRecording");
    shootingStatus.add("IntervalWaitRecStop");
    shootingStatus.add("AudioWaitRecStart");
    shootingStatus.add("AudioRecording");
    shootingStatus.add("AudioWaitRecStop");
    shootingStatus.add("AudioSaving");

    return shootingStatus.contains(currentStatus);
}