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.net2plan.utils.CollectionUtils.java

/**
 * Returns the intersection set of a series of input collections. There is no order guarantee.
 *
 * @param <A> Key type//from   ww  w  . j a v a2 s  . com
 * @param collections Series of input collections
 * @return Intersection set of input collections
 */
public static <A> Set<A> intersect(Collection<A>... collections) {
    if (collections.length == 0)
        return new LinkedHashSet<A>();

    Set<A> intersectionSet = new LinkedHashSet<A>();
    intersectionSet.addAll(collections[0]);

    for (int i = 1; i < collections.length; i++) {
        intersectionSet.retainAll(collections[i]);
    }

    return intersectionSet;
}

From source file:co.paralleluniverse.common.spring.SpringContainerHelper.java

public static Collection<String> getBeanDependencies(BeanDefinition beanDefinition) {
    Set<String> dependencies = new HashSet<String>();
    if (beanDefinition.getDependsOn() != null)
        dependencies.addAll(Arrays.asList(beanDefinition.getDependsOn()));

    for (ValueHolder value : beanDefinition.getConstructorArgumentValues().getGenericArgumentValues()) {
        if (value.getValue() instanceof BeanReference)
            dependencies.add(((BeanReference) value.getValue()).getBeanName());
    }/*  w ww . j a  va  2s . co m*/
    for (ValueHolder value : beanDefinition.getConstructorArgumentValues().getIndexedArgumentValues()
            .values()) {
        if (value.getValue() instanceof BeanReference)
            dependencies.add(((BeanReference) value.getValue()).getBeanName());
    }
    for (PropertyValue value : beanDefinition.getPropertyValues().getPropertyValueList()) {
        if (value.getValue() instanceof BeanReference)
            dependencies.add(((BeanReference) value.getValue()).getBeanName());
    }
    return dependencies;
}

From source file:gaffer.rest.service.SimpleGraphConfigurationService.java

private static Set<Class> getSubClasses(final Class<?> clazz) {
    final Set<URL> urls = new HashSet<>();
    for (final String packagePrefix : System
            .getProperty(SystemProperty.PACKAGE_PREFIXES, SystemProperty.PACKAGE_PREFIXES_DEFAULT).split(",")) {
        urls.addAll(ClasspathHelper.forPackage(packagePrefix));
    }//from   w  w w  . j  a va 2  s.  c o  m

    Set<Class> classes = new HashSet<>();
    classes.addAll(new Reflections(urls).getSubTypesOf(clazz));
    keepPublicConcreteClasses(classes);
    return classes;
}

From source file:jfix.util.Reflections.java

/**
 * Returns all interfaces and superclasses implemented by a given class.
 *//*from  ww w . j  a va  2 s  .c  om*/
public static Set<Class<?>> getSuperClassesAndInterfaces(Class<?> clazz) {
    Set<Class<?>> result = new HashSet<>();
    if (clazz != null) {
        result.add(clazz);
        for (Class<?> interfaceClass : clazz.getInterfaces()) {
            result.addAll(getSuperClassesAndInterfaces(interfaceClass));
        }
        result.addAll(getSuperClassesAndInterfaces(clazz.getSuperclass()));
    }
    return result;
}

From source file:fr.openwide.nuxeo.utils.document.DocumentUtils.java

/**
 * Returns the properties that differ between two versions of a document.
 * - If a schema is missing from a model, all of its properties will be returned
 * - Only basic types and string arrays as supported. More complex properties will always be considered modified. 
 * /*from   w  w  w  . ja v a  2  s. c o m*/
 * @param m1
 * @param m2
 * @return A list of xpaths
 * @throws ClientException
 */
public static List<String> getDifferingProperties(DocumentModel m1, DocumentModel m2) throws ClientException {
    List<String> differingProperties = new ArrayList<String>();

    Set<String> schemas = new HashSet<String>();
    schemas.addAll(Arrays.asList(m1.getSchemas()));
    schemas.addAll(Arrays.asList(m2.getSchemas()));

    for (String schema : schemas) {
        if (m1.hasSchema(schema)) {
            if (m2.hasSchema(schema)) {
                Map<String, Object> p1 = m1.getProperties(schema);
                Map<String, Object> p2 = m2.getProperties(schema);
                for (Entry<String, Object> property : p1.entrySet()) {
                    boolean differs = false;
                    Object value1 = property.getValue();
                    Object value2 = p2.get(property.getKey());
                    if (value1 == null) {
                        differs = value2 != null;
                    } else {
                        if (value1 instanceof String[]) {
                            differs = !Arrays.equals((String[]) value1, (String[]) value2);
                        } else {
                            differs = !value1.equals(value2);
                        }
                    }
                    if (differs) {
                        differingProperties.add(property.getKey());
                    }
                }
            } else {
                differingProperties.addAll(m1.getProperties(schema).keySet());
            }
        } else {
            differingProperties.addAll(m2.getProperties(schema).keySet());
        }
    }

    return differingProperties;
}

From source file:Main.java

/**
 * Reorder a list of elements by another list. Trying to keep absolute order of initial list in alphabetical order
 * but reorder regarding to provided relative order list.
 * E.g. initial was [1, 2, 3, 4, 5] - calling reorder with list [2, 5, 4] will generate list
 * [1, 2, 3, 5, 4]//from w w w .j  av a 2  s.  c  o  m
 * @param elements - initial list
 * @param order - list describing relative order
 * @param <T> - Class of comparable object
 * @return - new reordered list
 */
public static <T extends Comparable> List<T> mergeReorder(List<T> elements, List<T> order) {
    if (order.size() == 0) {
        return elements;
    }
    if (elements.size() == 0) {
        return order;
    }
    Set<T> merged = new LinkedHashSet<>();
    Set<T> elementsSet = new HashSet<>(elements);
    int i = 0;
    int j = 0;
    T currElement = elements.get(i);
    T currOrder = order.get(j);
    while (i < elements.size() || j < order.size()) {
        if (j >= order.size()) {
            merged.addAll(elements.subList(i, elements.size()));
            break;
        }
        currElement = i < elements.size() ? elements.get(i) : currElement;
        currOrder = j < order.size() ? order.get(j) : currOrder;
        if (currElement.compareTo(currOrder) < 0) {
            merged.add(currElement);
            i++;
        }
        if (currOrder.compareTo(currElement) < 0 || i >= elements.size()) {
            if (merged.contains(currOrder)) {
                merged.remove(currOrder);
            }
            if (elementsSet.contains(currOrder)) {
                merged.add(currOrder);
            }
            j++;
        }
        if (currElement.compareTo(currOrder) == 0) {
            merged.add(currElement);
            i++;
            j++;
        }
    }
    return new ArrayList<>(merged);
}

From source file:de.alpharogroup.io.annotations.ImportResourcesExtensions.java

/**
 * Gets a {@link Map} with {@link ImportResource} objects and the corresponding to the found
 * class from the given package Name. The search is made recursive. The key from an entry of the
 * map is the class where the {@link ImportResource} objects found and the value is an Array of
 * the {@link ImportResource} objects that contains in the class.
 *
 * @param packageName/*from   w w w . j av a 2s  .c om*/
 *            the package name
 * @return the import resources
 * @throws ClassNotFoundException
 *             occurs if a given class cannot be located by the specified class loader
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static Map<Class<?>, ImportResource[]> getImportResources(final String packageName)
        throws ClassNotFoundException, IOException {
    final Map<Class<?>, ImportResource[]> resourcesMap = new LinkedHashMap<>();

    final Class<ImportResources> importResourcesClass = ImportResources.class;
    final Class<ImportResource> importResourceClass = ImportResource.class;
    final Set<Class<?>> importResourcesClasses = AnnotationExtensions.getAllAnnotatedClasses(packageName,
            importResourcesClass);
    final Set<Class<?>> importResourceClasses = AnnotationExtensions.getAllAnnotatedClasses(packageName,
            importResourceClass);
    importResourcesClasses.addAll(importResourceClasses);
    for (final Class<?> annotatedClass : importResourcesClasses) {
        final ImportResources importResources = annotatedClass.getAnnotation(ImportResources.class);
        ImportResource[] importResourcesArray = null;
        ImportResource[] importResourceArray = null;
        if (importResources != null) {
            importResourcesArray = importResources.resources();
        }

        final ImportResource importResource = annotatedClass.getAnnotation(ImportResource.class);
        if (importResource != null) {
            importResourceArray = new ImportResource[1];
            importResourceArray[0] = importResource;
        }
        final ImportResource[] array = (ImportResource[]) ArrayUtils.addAll(importResourceArray,
                importResourcesArray);
        Arrays.sort(array, new ImportResourceComparator());
        resourcesMap.put(annotatedClass, array);

    }
    return resourcesMap;
}

From source file:net.sourceforge.vulcan.web.JstlFunctions.java

private static List<String> getProjectNamesByLabels(StateManager mgr, Iterable<String> itr) {
    final Set<String> set = new HashSet<String>();
    boolean empty = true;

    for (String label : itr) {
        set.addAll(mgr.getProjectConfigNamesByLabel(label));
        empty = false;//from   w  w w .  ja va2 s.  c  om
    }

    if (empty) {
        return mgr.getProjectConfigNames();
    }

    final ArrayList<String> list = new ArrayList<String>(set);
    Collections.sort(list);
    return list;
}

From source file:org.spring.springxdcloudInstaller.MainApp.java

private static RunningInstance findInstanceByKeyName(EC2Client client, final String keyName) {
    // search my account for the instance I just created
    Set<? extends Reservation<? extends RunningInstance>> reservations = client.getInstanceServices()
            .describeInstancesInRegion(null);

    // extract all the instances from all reservations
    Set<RunningInstance> allInstances = Sets.newHashSet();
    for (Reservation<? extends RunningInstance> reservation : reservations) {
        allInstances.addAll(reservation);
    }/* w  w w.  j  av  a  2s.com*/

    // get the first one that has a keyname matching what I just created
    return Iterables.find(allInstances, new Predicate<RunningInstance>() {

        public boolean apply(RunningInstance input) {
            return input.getKeyName().equals(keyName) && input.getInstanceState() != InstanceState.TERMINATED;
        }

    });
}

From source file:core.datapoint.DataPoint.java

/**
 * Filter collection using the business entities equals method.
 **///ww  w. j a  v  a  2  s  . c o m
private static Collection<DataPoint> filterUnique(Collection<DataPoint> objects) {
    Set<DataPoint> uniqueObjects = new LinkedHashSet<DataPoint>();
    uniqueObjects.addAll(objects);
    return uniqueObjects;
}