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:edu.usc.polar.CompositeNERAgreementParser.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(entry.getValue()+" -- "+a);
    }/*from   ww w.  ja v  a 2s  .com*/
    //System.out.println(" -- "+a);
    return a;
}

From source file:hsyndicate.utils.IPUtils.java

public static boolean isLocalIPAddress(String address) {
    Collection<String> localhostAddress = IPUtils.getHostAddress();
    Set<String> localhostAddrSet = new HashSet<String>();
    localhostAddrSet.addAll(localhostAddress);

    String hostname = address;//from w w w  .j a v a  2 s.  c  o m
    int pos = hostname.indexOf(":");
    if (pos > 0) {
        hostname = hostname.substring(0, pos);
    }

    if (hostname.equalsIgnoreCase("localhost") || hostname.equals("127.0.0.1")) {
        // localloop
        return true;
    }

    if (localhostAddrSet.contains(hostname)) {
        return true;
    }

    return false;
}

From source file:io.fabric8.maven.core.util.ClassUtil.java

public static Set<String> getResources(String resource, List<ClassLoader> additionalClassLoaders)
        throws IOException {

    ClassLoader[] classLoaders = mergeClassLoaders(additionalClassLoaders);

    Set<String> ret = new HashSet<>();
    for (ClassLoader cl : classLoaders) {
        Enumeration<URL> urlEnum = cl.getResources(resource);
        ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
    }/*from   w w  w.j ava 2  s.c  om*/
    return ret;
}

From source file:hsyndicate.utils.IPUtils.java

public static String selectLocalIPAddress(String[] addresses) {
    Collection<String> localhostAddress = IPUtils.getHostAddress();
    Set<String> localhostAddrSet = new HashSet<String>();
    localhostAddrSet.addAll(localhostAddress);

    for (String addr : addresses) {
        String hostname = addr;/*  www . j a  v a 2  s. c  om*/
        int pos = hostname.indexOf(":");
        if (pos > 0) {
            hostname = hostname.substring(0, pos);
        }

        if (hostname.equalsIgnoreCase("localhost") || hostname.equals("127.0.0.1")) {
            // localloop
            return addr;
        }

        if (localhostAddrSet.contains(hostname)) {
            return addr;
        }
    }

    return null;
}

From source file:de.ingrid.admin.Utils.java

public static Set<String> getUnionOfDatatypes(Map<String, String[]> datatypesOfIndex) {
    Set<String> allUniqueTypes = new LinkedHashSet<>();
    if (datatypesOfIndex != null) {
        Set<String> indices = datatypesOfIndex.keySet();
        for (String index : indices) {
            allUniqueTypes.addAll(Arrays.asList(datatypesOfIndex.get(index)));
        }/* w w w.j  a v a  2 s .  c  om*/
    }
    return allUniqueTypes;
}

From source file:com.cassius.spring.assembly.test.common.toolbox.ContextUtil.java

/**
 * Get spring context locations.//from ww w  .  j  a  va2 s  .  co  m
 *
 * @param testClass the test class
 * @return the string [ ]
 */
public static Set<String> getSpringContextLocations(Class<?> testClass) {
    Set<String> files = new HashSet<String>();
    while (testClass != null) {
        SpringContextConfigure configure = testClass.getAnnotation(SpringContextConfigure.class);
        if (configure != null) {
            files.addAll(Arrays.asList(configure.value()));
        }
        testClass = testClass.getSuperclass();
    }
    return files;
}

From source file:com.yahoo.research.scoring.classifier.NutchOnlineClassifier.java

/**
 * Converts an {@link AnthURL} into an {@link Instance} which can be handled
 * by the {@link Classifier}.// w  w w . ja v a2s.c o  m
 * 
 * @param url
 *            the {@link AnthURL} which should be transformed/converted.
 * @return the resulting {@link Instance}.
 */
private static Instance convert(AnthURL url) {
    if (url != null) {

        Instance inst = new SparseInstance(dimension);
        inst.replaceMissingValues(replaceMissingValues);

        inst.setDataset(instances);
        inst.setValue(attributesIndex.get("class"), (url.sem ? "sem" : "nonsem"));
        inst.setValue(attributesIndex.get("sempar"), (url.semFather ? 1 : 0));
        inst.setValue(attributesIndex.get("nonsempar"), (url.nonSemFather ? 1 : 0));
        inst.setValue(attributesIndex.get("semsib"), (url.semSibling ? 1 : 0));
        inst.setValue(attributesIndex.get("nonsempar"), (url.nonSemFather ? 1 : 0));
        inst.setValue(attributesIndex.get("domain"), url.uri.getHost());
        Set<String> tokens = new HashSet<String>();

        tokens.addAll(tokenizer(url.uri.getPath()));
        tokens.addAll(tokenizer(url.uri.getQuery()));
        tokens.addAll(tokenizer(url.uri.getFragment()));
        for (String tok : tokens) {
            inst.setValue(attributesIndex.get(getAttributeNameOfHash(getHash(tok, hashTrickSize))), 1);
        }
        return inst;

    } else {
        System.out.println("Input AnthURL for convertion into instance was null.");
        return null;
    }
}

From source file:io.seldon.clustering.recommender.RecommendationContext.java

public static RecommendationContext buildContext(String client, AlgorithmStrategy strategy, Long user,
        String clientUserId, Long currentItem, Set<Integer> dimensions, String lastRecListUUID,
        int numRecommendations, DefaultOptions defaultOptions, FilteredItems includedItems) {

    OptionsHolder optsHolder = new OptionsHolder(defaultOptions, strategy.config);
    List<String> inclusionKeys = new ArrayList<String>();
    Set<Long> contextItems = new HashSet<>();

    if (includedItems != null) {
        contextItems.addAll(includedItems.getItems());
        inclusionKeys.add(includedItems.getCachingKey());
        return new RecommendationContext(MODE.INCLUSION, contextItems, Collections.<Long>emptySet(),
                inclusionKeys, currentItem, lastRecListUUID, optsHolder);
    }/*  w w  w . ja  v  a  2 s.c  o  m*/

    Set<ItemIncluder> inclusionProducers = strategy.includers;
    Set<ItemFilter> itemFilters = strategy.filters;
    if (inclusionProducers == null || inclusionProducers.size() == 0) {
        if (itemFilters == null || itemFilters.size() == 0) {
            logger.warn("No filters or includers present in strategy");
            return new RecommendationContext(MODE.NONE, Collections.<Long>emptySet(),
                    Collections.<Long>emptySet(), Collections.<String>emptyList(), currentItem, lastRecListUUID,
                    optsHolder);
        }
        for (ItemFilter filter : itemFilters) {
            contextItems.addAll(filter.produceExcludedItems(client, user, clientUserId, optsHolder, currentItem,
                    lastRecListUUID, numRecommendations));
        }
        return new RecommendationContext(MODE.EXCLUSION, contextItems, contextItems, inclusionKeys, currentItem,
                lastRecListUUID, optsHolder);
    }

    Integer itemsPerIncluder = optsHolder.getIntegerOption(ITEMS_PER_INCLUDER_OPTION_NAME);
    if (itemFilters == null || itemFilters.size() == 0) {
        for (ItemIncluder producer : inclusionProducers) {
            FilteredItems filteredItems = producer.generateIncludedItems(client, dimensions, itemsPerIncluder);
            contextItems.addAll(filteredItems.getItems());
            inclusionKeys.add(filteredItems.getCachingKey());
        }
        return new RecommendationContext(MODE.INCLUSION, contextItems, Collections.<Long>emptySet(),
                inclusionKeys, currentItem, lastRecListUUID, optsHolder);
    }

    Set<Long> included = new HashSet<>();
    Set<Long> excluded = new HashSet<>();
    for (ItemFilter filter : itemFilters) {
        excluded.addAll(filter.produceExcludedItems(client, user, clientUserId, optsHolder, currentItem,
                lastRecListUUID, numRecommendations));
    }
    for (ItemIncluder producer : inclusionProducers) {
        FilteredItems filteredItems = producer.generateIncludedItems(client, dimensions, itemsPerIncluder);
        included.addAll(filteredItems.getItems());
        inclusionKeys.add(filteredItems.getCachingKey());
    }
    included.removeAll(excluded); // ok to do this as the excluded items that weren't in "included" will never
                                  // be recommended

    return new RecommendationContext(MODE.INCLUSION, included, excluded, inclusionKeys, currentItem,
            lastRecListUUID, optsHolder);
}

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

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

    int score = 0;
    for (String field : allFields) {
        Optional<String> stringOne = one.getFieldOptional(field);
        Optional<String> stringTwo = two.getFieldOptional(field);
        if (stringOne.equals(stringTwo)) {
            score++;//  w w  w .  ja v  a  2s  .c om
        }
    }
    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:com.hurence.logisland.classloading.PluginLoader.java

/**
 * Scan for plugins.//from  w  w  w  .  ja  v a  2 s.  c  o m
 */
private static void scanAndRegisterPlugins() {
    Set<URL> urls = new HashSet<>();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    while (cl != null) {
        if (cl instanceof URLClassLoader) {
            urls.addAll(Arrays.asList(((URLClassLoader) cl).getURLs()));
            cl = cl.getParent();
        }
    }

    for (URL url : urls) {
        try {
            Archive archive = null;
            try {
                archive = new JarFileArchive(
                        new File(URLDecoder.decode(url.getFile(), Charset.defaultCharset().name())), url);
            } catch (Exception e) {
                //silently swallowing exception. just skip the archive since not an archive
            }
            if (archive == null) {
                continue;
            }
            Manifest manifest = archive.getManifest();
            if (manifest != null) {
                String exportedPlugins = manifest.getMainAttributes()
                        .getValue(ManifestAttributes.MODULE_EXPORTS);
                if (exportedPlugins != null) {
                    String version = StringUtils.defaultIfEmpty(
                            manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION),
                            "UNKNOWN");

                    logger.info("Loading components from module {}", archive.getUrl().toExternalForm());

                    final Archive arc = archive;

                    if (StringUtils.isNotBlank(exportedPlugins)) {
                        Arrays.stream(exportedPlugins.split(",")).map(String::trim).forEach(s -> {
                            if (registry.putIfAbsent(s, PluginClassloaderBuilder.build(arc)) == null) {
                                logger.info("Registered component '{}' version '{}'", s, version);
                            }

                        });
                    }
                }
            }

        } catch (Exception e) {
            logger.error("Unable to load components from " + url.toExternalForm(), e);
        }
    }
}