Example usage for java.util HashSet addAll

List of usage examples for java.util HashSet addAll

Introduction

In this page you can find the example usage for java.util HashSet 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:Main.java

public static java.util.HashSet<Object> toSet(Object... args) {
    java.util.HashSet<Object> set = new java.util.HashSet<>();
    if (args != null) {
        set.addAll(Arrays.asList(args));
    }/*from  ww w. j  a  va2  s. co  m*/
    return set;
}

From source file:Main.java

public static java.util.HashSet<String> toSet(String... args) {
    java.util.HashSet<String> set = new java.util.HashSet<>();
    if (args != null) {
        set.addAll(Arrays.asList(args));
    }/*from   w ww  .  j a  va2  s .  c  o m*/
    return set;
}

From source file:org.cidarlab.eugene.dom.collection.CollectionOps.java

public static EugeneCollection union(EugeneCollection col1, EugeneCollection col2) {
    if (null == col1 || null == col2) {
        return null;
    }//from   w w  w . ja v a 2  s.  co  m

    EugeneCollection objCollection = new EugeneCollection(col1.getName() + "_" + col2.getName());

    HashSet<CollectionElement> s = new HashSet<CollectionElement>();
    s.addAll(col1.getElements());
    s.addAll(col2.getElements());
    objCollection.setElements(s);
    return objCollection;
}

From source file:Main.java

/**
 * Convenient method to chain two sets together.
 * @param first first set/*from  w  w w.  ja  v a  2s  .co  m*/
 * @param others other sets
 * @return chained set
 */
@SuppressWarnings("unchecked")
@SafeVarargs
public static <T> Set<T> chain(Set<T> first, Set<T>... others) {
    HashSet<T> result = new HashSet<>(first);
    for (Set<T> other : others) {
        result.addAll(other);
    }
    return result;
}

From source file:Main.java

/**
 * Return a set containing the union of all provided collections. We use a
 * {@link HashSet}, i.e. the elements should support hashing.
 * /*from  w ww  .  j  a va  2s . c  o m*/
 * We use two separate arguments to ensure on the interface level that at
 * least one collection is provided. This is transparent for the caller.
 */
public static <T> HashSet<T> unionSet(Collection<T> collection1,
        @SuppressWarnings("unchecked") Collection<T>... furtherCollections) {
    HashSet<T> result = new HashSet<T>(collection1);
    for (Collection<T> collection : furtherCollections) {
        result.addAll(collection);
    }
    return result;
}

From source file:de.awtools.basic.AWTools.java

/**
 * Erstellt ein HashSet.//  ww  w  .j av  a 2 s  .c  om
 *
 * @param <T> Typ des Sets.
 * @param values Die Werte.
 * @return Ein Set.
 */
@SafeVarargs
public static <T> Set<T> hashSet(final T... values) {
    HashSet<T> set = new HashSet<>();
    boolean addAll = set.addAll(Arrays.asList(values));
    if (!addAll) {
        throw new IllegalStateException("There is a failure here.");
    }
    return set;
}

From source file:org.eclipse.winery.repository.resources.admin.NamespacesResource.java

/**
 * Returns the list of all namespaces registered with his manager and used
 * at component instances./*from   w  w  w . ja va2 s.c o  m*/
 */
public static Collection<Namespace> getNamespaces() {
    HashSet<Namespace> res = NamespacesResource.INSTANCE.getRegisteredNamespaces();
    res.addAll(Repository.INSTANCE.getUsedNamespaces());
    return res;
}

From source file:net.sf.jabref.bibtex.DuplicateCheck.java

public static double compareEntriesStrictly(BibEntry one, BibEntry two) {
    HashSet<String> allFields = new HashSet<>();
    allFields.addAll(one.getFieldNames());
    allFields.addAll(two.getFieldNames());

    int score = 0;
    for (String field : allFields) {
        Object en = one.getField(field);
        Object to = two.getField(field);
        if (((en != null) && (to != null) && en.equals(to)) || ((en == null) && (to == null))) {
            score++;//  w w  w .  j av  a 2  s .  co  m
        }
    }
    if (score == allFields.size()) {
        return 1.01; // Just to make sure we can
        // use score>1 without
        // trouble.
    }
    return (double) score / allFields.size();
}

From source file:org.cloudfoundry.identity.uaa.util.UaaTokenUtils.java

public static Set<String> retainAutoApprovedScopes(Collection<String> requestedScopes,
        Set<String> autoApprovedScopes) {
    HashSet<String> result = new HashSet<>();
    if (autoApprovedScopes == null) {
        return result;
    }/*from   ww w . j av  a 2s . c  o  m*/
    if (autoApprovedScopes.contains("true")) {
        result.addAll(requestedScopes);
        return result;
    }
    Set<Pattern> autoApprovedScopePatterns = UaaStringUtils.constructWildcards(autoApprovedScopes);
    // Don't want to approve more than what's requested
    for (String scope : requestedScopes) {
        if (UaaStringUtils.matches(autoApprovedScopePatterns, scope)) {
            result.add(scope);
        }
    }
    return result;
}

From source file:ac.dynam.rundeck.plugin.resources.ovirt.InstanceToNodeMapper.java

/**
 * Convert an oVirt Instance to a RunDeck INodeEntry based on the mapping input
 *///w w w . j  av  a2  s  .co m
@SuppressWarnings("unchecked")
static INodeEntry instanceToNode(final VM inst) throws GeneratorException {
    final NodeEntryImpl node = new NodeEntryImpl();

    node.setNodename(inst.getName());
    node.setOsArch(inst.getCpu().getArchitecture());
    node.setOsName(inst.getOs().getType());
    node.setDescription(inst.getDescription());
    node.setUsername("root");
    InetAddress address = null;
    if (inst.getGuestInfo() != null) {
        try {
            address = InetAddress.getByName(inst.getGuestInfo().getFqdn());
            logger.debug("Host " + node.getNodename() + " Guest FQDN " + inst.getGuestInfo().getFqdn()
                    + " Address: " + address.getHostName());
            if (address.getHostName() == "localhost")
                throw new UnknownHostException();
        } catch (UnknownHostException e) {
            /* try the first IP instead then */
            logger.warn("Host " + node.getNodename() + " address " + inst.getGuestInfo().getFqdn()
                    + " does not resolve. Trying IP addresses instead");
            for (int i = 0; i < inst.getGuestInfo().getIps().getIPs().size(); i++) {
                logger.debug("Host " + node.getNodename() + " Trying "
                        + inst.getGuestInfo().getIps().getIPs().get(i).getAddress());
                try {
                    address = InetAddress.getByName(inst.getGuestInfo().getIps().getIPs().get(i).getAddress());
                    if (address != null) {
                        if (address.isLinkLocalAddress() || address.isMulticastAddress()) {
                            logger.warn("Host " + node.getNodename() + " ip address is not valid: "
                                    + inst.getGuestInfo().getIps().getIPs().get(i).getAddress());
                            continue;
                        }
                        logger.debug("Host " + node.getNodename() + " ip address " + address.getHostAddress()
                                + " will be used instead");
                        break;
                    }
                } catch (UnknownHostException e1) {
                    logger.warn("Host " + node.getNodename() + " IP Address "
                            + inst.getGuestInfo().getIps().getIPs().get(i).getAddress() + " is invalid");
                }
            }
        }
    }
    if (address == null) {
        /* try resolving based on name */
        try {
            address = InetAddress.getByName(node.getNodename());
        } catch (UnknownHostException e) {
            logger.warn("Unable to Find IP address for Host " + node.getNodename());
            return null;
        }
    }

    if (address != null)
        node.setHostname(address.getCanonicalHostName());

    if (inst.getTags() != null) {
        VMTags tags = inst.getTags();
        final HashSet<String> tagset = new HashSet<String>();
        try {
            for (int j = 0; j < tags.list().size(); j++) {
                tagset.add(tags.list().get(j).getName());
            }
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ServerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (null == node.getTags()) {
            node.setTags(tagset);
        } else {
            final HashSet<String> orig = new HashSet<String>(node.getTags());
            orig.addAll(tagset);
            node.setTags(orig);
        }
    }

    if (inst.getHighAvailability().getEnabled())
        node.setAttribute("HighAvailability", "true");
    if (inst.getType() != null)
        node.setAttribute("Host Type", inst.getType());
    node.setAttribute("oVirt VM", "true");
    node.setAttribute("oVirt Host", inst.getHost().getName());

    return node;
}