Example usage for java.util Collection addAll

List of usage examples for java.util Collection addAll

Introduction

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

Prototype

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

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:it.geosolutions.geoserver.jms.impl.utils.BeanUtils.java

/**
 * This is a 'smart' (perform checks for some special cases) update function which should be used to copy of the properties for objects
 * of the catalog and configuration.//  w w  w .j a  va  2  s .c om
 * 
 * @param <T> the type of the bean to update
 * @param info the bean instance to update
 * @param properties the list of string of properties to update
 * @param values the list of new values to update
 * 
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
public static <T> void smartUpdate(final T info, final List<String> properties, final List<Object> values)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    final Iterator<String> itPropertyName = properties.iterator();
    final Iterator<Object> itValue = values.iterator();
    while (itPropertyName.hasNext() && itValue.hasNext()) {
        String propertyName = itPropertyName.next();
        final Object value = itValue.next();

        PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(info, propertyName);
        // return null if there is no such descriptor
        if (pd == null) {
            // this is a special case used by the NamespaceInfoImpl setURI
            // the propertyName coming from the ModificationProxy is set to 'uRI'
            // lets set it to uri
            propertyName = propertyName.toUpperCase();
            pd = PropertyUtils.getPropertyDescriptor(info, propertyName);
            if (pd == null) {
                return;
            }
        }
        if (pd.getWriteMethod() != null) {
            PropertyUtils.setProperty(info, propertyName, value);
        } else {
            // T interface do not declare setter method for this property
            // lets use getter methods to get the property reference
            final Object property = PropertyUtils.getProperty(info, propertyName);

            // check type of property to apply new value
            if (Collection.class.isAssignableFrom(pd.getPropertyType())) {
                final Collection<?> liveCollection = (Collection<?>) property;
                liveCollection.clear();
                liveCollection.addAll((Collection) value);
            } else if (Map.class.isAssignableFrom(pd.getPropertyType())) {
                final Map<?, ?> liveMap = (Map<?, ?>) property;
                liveMap.clear();
                liveMap.putAll((Map) value);
            } else {
                if (CatalogUtils.LOGGER.isLoggable(java.util.logging.Level.SEVERE))
                    CatalogUtils.LOGGER.severe("Skipping unwritable property " + propertyName
                            + " with property type " + pd.getPropertyType());
            }
        }
    }
}

From source file:net.sourceforge.floggy.maven.ZipUtils.java

/**
 * DOCUMENT ME!/*from  w  w  w  .  j  a v  a 2 s. c  o m*/
*
* @param directories DOCUMENT ME!
* @param output DOCUMENT ME!
*
* @throws IOException DOCUMENT ME!
*/
public static void zip(File[] directories, File output) throws IOException {
    FileInputStream in = null;
    ZipOutputStream out = null;
    ZipEntry entry = null;

    Collection allFiles = new LinkedList();

    for (int i = 0; i < directories.length; i++) {
        allFiles.addAll(FileUtils.listFiles(directories[i], null, true));
    }

    out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(output)));

    for (Iterator iter = allFiles.iterator(); iter.hasNext();) {
        File temp = (File) iter.next();
        String name = getEntryName(directories, temp.getAbsolutePath());
        entry = new ZipEntry(name);
        out.putNextEntry(entry);

        if (!temp.isDirectory()) {
            in = new FileInputStream(temp);
            IOUtils.copy(in, out);
            in.close();
        }
    }

    out.close();
}

From source file:org.openscore.lang.compiler.scorecompiler.ScoreCompilerImpl.java

private static Collection<Input> getSystemProperties(Collection<Executable> executables) {
    Collection<Input> result = new ArrayList<>();
    for (Executable executable : executables) {
        result.addAll(getSystemProperties(executable.getInputs()));
        if (executable instanceof Flow) {
            for (Task task : ((Flow) executable).getWorkflow().getTasks()) {
                result.addAll(getSystemProperties(task.getInputs()));
            }/*from  w w  w . j  a  va 2  s  .com*/
        }
    }
    return result;
}

From source file:de.thischwa.pmcms.gui.dialog.DialogManager.java

/**
 * Open the dialog for choosing which unused image files should delete and delete those.
 * /*w w  w.  ja v a  2s  .co  m*/
 * @param parentShell
 * @param site
 *            Current {@link Site}
 * @param usedCkResources
 *            Unused images of the last export.
 */
public static void startDialogUnusedImages(final Shell parentShell, final Site site,
        Collection<File> usedCkResources, final Collection<String> allowedExtensions) {
    File galleryDir = PoPathInfo.getSiteResourceGalleryDirectory(site);
    File imageDir = PoPathInfo.getSiteResourceImageDirectory(site);
    File otherDir = PoPathInfo.getSiteResourceOtherDirectory(site);

    Collection<File> unusedCkResources = new HashSet<File>();
    if (galleryDir.exists())
        unusedCkResources.addAll(FileTool.collectFiles(galleryDir, usedCkResources));
    if (imageDir.exists())
        unusedCkResources.addAll(FileTool.collectFiles(imageDir, usedCkResources));
    if (otherDir.exists())
        unusedCkResources.addAll(FileTool.collectFiles(otherDir, usedCkResources));
    if (CollectionUtils.isEmpty(unusedCkResources)) {
        logger.info("No unused resources found.");
        return;
    }

    final Shell shell = new Shell(parentShell, SWT.APPLICATION_MODAL | SWT.TITLE);
    shell.setImages(new Image[] { ImageHolder.SHELL_ICON_SMALL, ImageHolder.SHELL_ICON_BIG });
    shell.setLayout(new GridLayout());

    new UnusedImageComp(shell, SWT.NONE, site, unusedCkResources, allowedExtensions);

    shell.pack();
    shell.open();
    SWTUtils.center(shell, parentShell.getBounds());

    Display display = shell.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (CollectionUtils.isNotEmpty(unusedCkResources))
        FileTool.deleteFiles(unusedCkResources);
    shell.dispose();
}

From source file:Main.java

public static <T> void rotate(Collection<T> collection, int rotateStep) {
    List<T> list = new LinkedList<T>();
    list.addAll(collection);/*from w  w w . ja  v a 2s  .  c  o  m*/
    collection.clear();
    if (rotateStep > 0) {
        if (rotateStep > list.size())
            rotateStep %= list.size();
        collection.addAll(list.subList(list.size() - rotateStep, list.size()));
        collection.addAll(list.subList(0, list.size() - rotateStep));
    } else {
        if (Math.abs(rotateStep) > list.size())
            rotateStep %= list.size();
        rotateStep = Math.abs(rotateStep);
        collection.addAll(list.subList(rotateStep, list.size()));
        collection.addAll(list.subList(0, rotateStep));
    }
}

From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java

private static void parseInputList(Object target, String[] values, Field field)
        throws ReflectiveOperationException, ParseException {
    List convertedValues = new ArrayList();
    Class type = getCollectionComponentType(field);
    for (String value : values) {
        Object val = convertValue(value, type);
        convertedValues.add(val);
    }/*w w  w  . j a v a 2 s .c  om*/
    if (field.getType().isArray()) {
        Object array = Array.newInstance(field.getType().getComponentType(), convertedValues.size());
        for (int i = 0; i < convertedValues.size(); i++) {
            Array.set(array, i, convertedValues.get(i));
        }
        FieldUtils.writeField(field, target, array, true);
    } else {
        Collection c = (Collection) getInstantiatableListType(field.getType()).newInstance();
        c.addAll(convertedValues);
        FieldUtils.writeField(field, target, c, true);
    }
}

From source file:net.roboconf.dm.templating.internal.helpers.AllHelper.java

/**
 * Returns all the descendant instances of the given instance.
 * @param instance the instance which descendants must be retrieved.
 * @return the descendants of the given instance.
 *//*www .  j  a  v a 2 s . c o m*/
private static Collection<InstanceContextBean> descendantInstances(final InstanceContextBean instance) {

    final Collection<InstanceContextBean> result = new ArrayList<InstanceContextBean>();
    for (final InstanceContextBean child : instance.getChildren()) {
        result.add(child);
        result.addAll(descendantInstances(child));
    }

    return result;
}

From source file:com.sun.socialsite.web.listeners.SessionListener.java

/**
 * Returns all listeners which have registered to receive events
 * for the specified HttpSession.//from  ww  w  .  j a v a  2  s  . c  o m
 * @param session the HttpSession for which listeners are sought.
 */
private static Collection<Object> getListeners(HttpSession session) {
    Collection<Object> results = new ArrayList<Object>();
    Collection<Object> listenersForSession = listenersMap.get(session);
    if (listenersForSession != null) {
        results.addAll(listenersForSession);
    }
    log.debug(String.format("getListeners(%s): results.size=%d", session, results.size()));
    return results;
}

From source file:Main.java

public static Collection asTargetTypeCollection(Collection c, Class targetCollectionClass) {
    if (targetCollectionClass == null)
        throw new IllegalArgumentException("'targetCollectionClass' must be not null");
    if (c == null)
        return null;
    if (targetCollectionClass.isInstance(c))
        return c;

    Collection result = null;

    try {//  w  w  w .j av a 2  s .  co m
        result = (Collection) targetCollectionClass.newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "targetCollectionClass=" + targetCollectionClass.getName() + " is not correct!", e);
    }

    result.addAll(c);
    return result;
}

From source file:com.imaginary.home.cloud.device.Light.java

static public void findLightssForRelayWithChildren(@Nonnull ControllerRelay relay,
        @Nonnull Collection<Device> devices) throws PersistenceException {
    devices.addAll(findLightsForRelay(relay));
}