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:com.opensearchserver.affinities.process.AffinityProcess.java

static List<String> mergeReturnedFields(Affinity affinity, AffinityRequest request) {
    if (affinity.returned_fields == null)
        return request.returned_fields;
    if (request.returned_fields == null)
        return affinity.returned_fields;
    Set<String> set = new TreeSet<String>();
    set.addAll(affinity.returned_fields);
    set.addAll(request.returned_fields);
    return new ArrayList<String>(set);
}

From source file:com.offbynull.portmapper.pcp.PcpDiscovery.java

/**
 * Discover PCP-enabled routers.//from   w w  w. ja  va 2  s  . co m
 * @param extraAddresses extra addresses to check
 * @return a collection of discovered PCP devices
 * @throws InterruptedException if interrupted
 * @throws IOException if IO error occurs
 * @throws NullPointerException if any argument is {@code null} or contains {@code null}
 */
public static Set<DiscoveredPcpDevice> 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<DiscoveredPcpDevice> devices = new HashSet<>();
    for (Entry<InetAddress, InetAddress> e : localAddressToGatewayMap.entrySet()) {
        devices.add(new DiscoveredPcpDevice(e.getKey(), e.getValue()));
    }
    return devices;
}

From source file:Main.java

/**
 * Returns a {@link Collection} containing the intersection
 * of the given {@link Collection}s.//from   w  ww.  java 2 s .c om
 * <p/>
 * The cardinality of each element in the returned {@link Collection}
 * will be equal to the minimum 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 intersection of the two collections15
 * @see Collection#retainAll
 * @see #containsAny
 */
public static <E> Collection<E> intersection(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.min(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) {
            list.add(obj);
        }
    }
    return list;
}

From source file:TwitterClustering.java

/**
 * @param args//from w  ww  . j  av a2  s. co  m
 *            the command line arguments
 */
public static <T> Set<T> union(Set<T> setA, Set<T> setB) {
    Set<T> tmp = new TreeSet<T>(setA);
    tmp.addAll(setB);
    return tmp;
}

From source file:net.sf.wickedshell.util.ShellViewUtil.java

@SuppressWarnings("unchecked")
public static final List getTargetableExecutableFiles() {
    ShellView[] shellViews = ShellPlugin.getDefault().getRegisteredShellViews();
    Set executableFiles = new HashSet();
    for (int index = 0; index < shellViews.length; index++) {
        executableFiles.addAll(Arrays.asList(shellViews[index].getShellViewer().getShellFacade()
                .getShellDescriptor().getExecutableFiles(true)));
    }/*from   www  . j  a v a 2 s.co m*/
    return new ArrayList(executableFiles);
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.DockerService.java

private static String[] environmentFrom(CreateAgentRequest request, PluginSettings settings,
        String containerName) {/*from w w  w  . jav  a2 s  . c  o  m*/
    Set<String> env = new HashSet<>();

    env.addAll(settings.getEnvironmentVariables());
    if (StringUtils.isNotBlank(request.properties().get("Environment"))) {
        env.addAll(splitIntoLinesAndTrimSpaces(request.properties().get("Environment")));
    }

    env.addAll(Arrays.asList("GO_EA_MODE=" + mode(), "GO_EA_SERVER_URL=" + settings.getGoServerUrl(),
            "GO_EA_GUID=" + "docker-swarm." + containerName));

    env.addAll(request.autoregisterPropertiesAsEnvironmentVars(containerName));

    return env.toArray(new String[env.size()]);
}

From source file:Main.java

/**
 * Returns a {@link Collection} containing the exclusive disjunction
 * (symmetric difference) of the given {@link Collection}s.
 * <p/>//w w  w  .  jav a 2s. c o  m
 * The cardinality of each element <i>e</i> in the returned {@link Collection}
 * will be equal to
 * <tt>max(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>)) - min(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>))</tt>.
 * <p/>
 * This is equivalent to
 * <tt>{@link #subtract subtract}({@link #union union(a,b)},{@link #intersection intersection(a,b)})</tt>
 * or
 * <tt>{@link #union union}({@link #subtract subtract(a,b)},{@link #subtract subtract(b,a)})</tt>.
 *
 * @param a the first collection, must not be null
 * @param b the second collection, must not be null
 * @return the symmetric difference of the two collections15
 */
public static <E> Collection<E> disjunction(final Collection<E> a, final Collection<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)))
                - (Math.min(getFreq(obj, mapa), getFreq(obj, mapb)))); i < m; i++) {
            list.add(obj);
        }
    }
    return list;
}

From source file:ClassUtil.java

/**
 * Builds an <b>unordered</b> set of all interface and object classes that
 * are generalizations of the provided class.
 * @param classObject the class to find generalization of.
 * @return a Set of class objects.// w w w  . j a  v  a 2  s.  c o  m
 */
public static Set getGeneralizations(Class classObject) {
    Set generalizations = new HashSet();

    generalizations.add(classObject);

    Class superClass = classObject.getSuperclass();
    if (superClass != null) {
        generalizations.addAll(getGeneralizations(superClass));
    }

    Class[] superInterfaces = classObject.getInterfaces();
    for (int i = 0; i < superInterfaces.length; i++) {
        Class superInterface = superInterfaces[i];
        generalizations.addAll(getGeneralizations(superInterface));
    }

    return generalizations;
}

From source file:edu.usc.polar.OpenNLP.java

public static Set<String> combineSets(Map<String, Set<String>> list) {
    Set<String> a = new HashSet<>();
    for (Map.Entry<String, Set<String>> entry : list.entrySet()) {
        a.addAll(entry.getValue());
        System.out.println(a);/*from   w ww. j a  v  a 2s.  c  o m*/
    }
    return a;
}

From source file:eu.itesla_project.modules.topo.PrintSubstationTopoHistoryTool.java

private static ShortIdDictionary createDict(Set<Set<TopoBus>> topos) {
    Set<String> ids = new TreeSet<>();
    for (Set<TopoBus> topo : topos) {
        for (TopoBus b : topo) {
            ids.addAll(b.getEquipments());
        }//w ww . j  a  v  a  2  s  . com
    }
    return new ShortIdDictionary(ids);
}