Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:gov.nih.nci.ncicb.cadsr.common.util.SessionUtils.java

private static void clearStaleObject() {
    synchronized (sessionObjectCacheTimeout) {
        log.error("SessionUtil.clearStaleObject start :" + TimeUtils.getEasternTime());
        Set keys = sessionObjectCacheTimeout.keySet();
        Collection copyKeys = new ArrayList();
        keys.addAll(copyKeys); // done to avoid java.util.ConcurrentModificationException
        if (keys != null) {
            Iterator it = copyKeys.iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                Long storedTime = (Long) sessionObjectCacheTimeout.get(key);
                if (new Long(new Date().getTime()).longValue() > storedTime.longValue() + CACHE_TIMEOUT_VALUE) {
                    sessionObjectCache.remove(key);
                    sessionObjectCacheTimeout.remove(key);
                }/* w w  w . jav  a 2s  .c o  m*/
            }
        }
        log.error("SessionUtil.clearStaleObject( start :" + TimeUtils.getEasternTime());
    }
}

From source file:ch.ifocusit.plantuml.utils.ClassUtils.java

public static Set<Class> getConcernedTypes(Field field) {
    Set<Class> classes = new HashSet<>();
    classes.add(field.getType());/*from ww  w .j  a  v a2 s.  com*/
    classes.addAll(getGenericTypes(field));
    return classes;
}

From source file:models.Watch.java

public static Set<User> findActualWatchers(final Set<User> baseWatchers, final Resource resource) {
    Set<User> actualWatchers = new HashSet<>();
    actualWatchers.addAll(baseWatchers);

    // Add every user who watches the project to which this resource belongs
    if (!(resource instanceof GlobalResource)) {
        Project project = resource.getProject();
        actualWatchers.addAll(findWatchers(project.asResource()));
    }/*from   w w w  . j a  v a 2s. c o m*/

    // For this resource, add every user who watch explicitly and remove who unwatch explicitly.
    actualWatchers.addAll(findWatchers(resource));
    actualWatchers.removeAll(findUnwatchers(resource));

    // Filter the watchers who has no permission to read this resource.
    CollectionUtils.filter(actualWatchers, new Predicate() {
        @Override
        public boolean evaluate(Object watcher) {
            return AccessControl.isAllowed((User) watcher, resource, Operation.READ);
        }
    });
    return actualWatchers;
}

From source file:ch.ifocusit.plantuml.utils.ClassUtils.java

public static Set<Class> getConcernedTypes(Parameter parameter) {
    Set<Class> classes = new HashSet<>();
    classes.add(parameter.getType());/*from   ww w  . j ava2s.c  o m*/
    classes.addAll(getGenericTypes(parameter));
    return classes;
}

From source file:com.offbynull.portmapper.natpmp.NatPmpDiscovery.java

/**
 * Discover NAT-PMP-enabled routers.//from  w  w w  .  jav  a 2s .c o m
 * @param extraAddresses extra addresses to check
 * @return a collection of discovered PCP devices
 * @throws InterruptedException if interrupted
 * @throws IOException if IO error
 * @throws NullPointerException if any argument is {@code null} or contains {@code null}
 */
public static Set<DiscoveredNatPmpDevice> discover(InetAddress... extraAddresses)
        throws InterruptedException, IOException {
    Validate.noNullElements(extraAddresses);

    Set<InetAddress> gateways = discoverGateways();
    gateways.addAll(Arrays.asList(extraAddresses));
    Map<InetAddress, InetAddress> localAddressToGatewayMap = discoverLocalAddressesToGateways(gateways);

    Set<DiscoveredNatPmpDevice> devices = new HashSet<>();
    for (Entry<InetAddress, InetAddress> e : localAddressToGatewayMap.entrySet()) {
        devices.add(new DiscoveredNatPmpDevice(e.getKey(), e.getValue()));
    }
    return devices;
}

From source file:com.jlfex.hermes.common.utils.CollectionUtil.java

/**
 * List?  Set ?//w w  w  .  j  a v a2  s.c  om
 * @param a
 * @return
 */
public static <T> Set<T> switchList2Set(List<T> a) {
    Set<T> sets = new HashSet<T>();
    sets.addAll(a);
    return sets;
}

From source file:com.eryansky.common.utils.collections.Collections3.java

/**
 * ?list2list1??/*from   ww w .  ja  v  a2  s .c  om*/
 * ???List?hashcodeequals
 * A={2,3} comple B={1,1,2,6} => C={1,6}
 * @param a
 * @param b
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static <T> List<T> comple(Collection<T> a, Collection<T> b) {
    Set<T> set = new LinkedHashSet();
    set.addAll(a);
    set.removeAll(intersection(a, b));
    return new ArrayList(set);
}

From source file:com.haulmont.timesheets.global.DateTimeUtils.java

public static Set<String> getDatesRangeAsSeparateStrings(Date startDate, Date endDate, String format) {
    List<Holiday> holidays = projectsService().getHolidaysForPeriod(startDate, endDate);
    if (CollectionUtils.isEmpty(holidays)) {
        return Collections.emptySet();
    }/*from ww w.j  av a 2s.c  o  m*/
    Set<String> stringHolidays = new HashSet<>();

    for (Holiday holiday : holidays) {
        stringHolidays.addAll(holidayAsSeparateStrings(holiday, startDate, endDate, format));
    }

    return stringHolidays;
}

From source file:org.bremersee.common.spring.autoconfigure.JaxbAutoConfiguration.java

private static Set<String> createPackageSet(Collection<String> packages) {
    final Set<String> packageSet = new LinkedHashSet<>(Arrays.asList(DEFAULT_JAXB_CONTEXT_PATHS));
    if (packages != null) {
        packageSet.addAll(packages);
    }/* w  ww .ja  va 2s . co m*/
    return packageSet;
}

From source file:Main.java

/**
 * Returns a {@link Collection} containing the union
 * of the given {@link Collection}s./*w w w .j  av  a2  s  .  c o  m*/
 * <p/>
 * The cardinality of each element in the returned {@link Collection}
 * will be equal to the maximum of the cardinality of that element
 * in the two given {@link Collection}s.
 *
 * @param a the first collection, must not be null
 * @param b the second collection, must not be null
 * @return the union of the two collections15
 * @see Collection#addAll
 */
public static <E> Collection<E> union(final Collection<? extends E> a, final Collection<? extends E> b) {
    ArrayList<E> list = new ArrayList<E>();
    Map mapa = getCardinalityMap(a);
    Map mapb = getCardinalityMap(b);
    Set<E> elts = new HashSet<E>(a);
    elts.addAll(b);
    Iterator<E> it = elts.iterator();
    while (it.hasNext()) {
        E obj = it.next();
        for (int i = 0, m = Math.max(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) {
            list.add(obj);
        }
    }
    return list;
}