Example usage for java.util Collection clear

List of usage examples for java.util Collection clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the elements from this collection (optional operation).

Usage

From source file:ru.asmsoft.p2p.storage.MemoryMessageRepository.java

@Override
public void syncDb(long dbVersion, Collection<P2PMessage> messages) {
    messages.clear();
    messages.addAll(messages);/*from  w  ww .ja v  a2s.c om*/
    version = dbVersion;
}

From source file:de.iew.web.isc.DSResponseCollection.java

public Collection getClearedDataStore() {
    Collection existingData = getCollectionData();
    existingData.clear();
    return existingData;
}

From source file:com.hs.mail.imap.event.EventTracker.java

private void clear(Collection<Long> uids) {
    if (uids != null) {
        uids.clear();
    }
}

From source file:org.apache.isis.core.progmodel.facets.collections.collection.JavaCollectionFacet.java

@Override
public void init(final ObjectAdapter collection, final ObjectAdapter[] initData) {
    final Collection<? super Object> javaCollection = collectionOfUnderlying(collection);
    javaCollection.clear();
    for (final ObjectAdapter element : initData) {
        final Object pojo = element.getObject();
        javaCollection.add(pojo);//from  ww  w.  j  a v  a  2 s. c o  m
    }
}

From source file:org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingViewHelperUtil.java

public static OfferingInstructorInfo findDisplayInstructor(List<OfferingInstructorInfo> instructors) {
    OfferingInstructorInfo result = null;

    if (instructors != null && !instructors.isEmpty()) {

        // Build the display name for the Instructor
        Collection<OfferingInstructorInfo> highestInstEffortInstructors = new ArrayList<OfferingInstructorInfo>();
        float highestInstEffortComparison = 0f;

        for (OfferingInstructorInfo instructor : instructors) {
            if (instructor.getPercentageEffort() != null) {
                // if this instructor has a higher percent effort than any previous instructors,
                // clear the list we are keeping track of and set the new comparison number to this instructor's percentage effort
                if (instructor.getPercentageEffort() > highestInstEffortComparison) {
                    highestInstEffortInstructors.clear();
                    highestInstEffortComparison = instructor.getPercentageEffort();
                    highestInstEffortInstructors.add(instructor);
                }/*  www  .ja  va2  s.c om*/
                // if this instructor's percent effort is tied with the comparison number,
                // add this instructor to the list of highest effort instructors
                else if (instructor.getPercentageEffort() == highestInstEffortComparison) {
                    highestInstEffortInstructors.add(instructor);
                }
            }
        }

        if (highestInstEffortInstructors.size() == 1) {
            result = highestInstEffortInstructors.iterator().next();
        } else {
            List<String> names = new ArrayList<String>(highestInstEffortInstructors.size());
            Map<String, OfferingInstructorInfo> nameMap = new HashMap<String, OfferingInstructorInfo>(
                    highestInstEffortInstructors.size());
            for (OfferingInstructorInfo oiInfo : highestInstEffortInstructors) {
                names.add(oiInfo.getPersonName());
                nameMap.put(oiInfo.getPersonName(), oiInfo);
            }

            Collections.sort(names);
            int firstName = 0;
            result = nameMap.get(names.get(firstName));
        }
    }

    return result;
}

From source file:com.sworddance.util.CUtilities.java

/**
 * conceptually equivalent to masterCollection.clear(); masterCollection.addAll(newValues);
 *
 * except that the masterCollection is only modified to the extent needed to bring it into compliance.
 * Useful for avoiding unnecessary db operations.
 * compare the values in the newValues Collection to the masterCollection.
 * @param <T>/*from ww  w  .  j a v a  2  s.c om*/
 * @param masterCollection
 * @param newValues
 * @return true if a change was made
 */
public static <T> boolean updateCollectionAsNeeded(Collection<T> masterCollection, Collection<T> newValues) {
    boolean changed = false;
    // avoid updating with self.
    if (masterCollection != newValues) {
        if (isEmpty(newValues)) {
            if (isNotEmpty(masterCollection)) {
                masterCollection.clear();
                changed = true;
            }
        } else {
            // may be copying directly from another envelope
            List<T> remainingValues = new ArrayList<T>(newValues);
            // remove topics that are no longer present.
            for (Iterator<T> iterator = masterCollection.iterator(); iterator.hasNext();) {
                T existingObjectInMasterCollection = iterator.next();
                if (!remainingValues.contains(existingObjectInMasterCollection)) {
                    iterator.remove();
                    changed = true;
                } else {
                    remainingValues.remove(existingObjectInMasterCollection);
                }
            }
            // add any remaining objects that are actually new.
            masterCollection.addAll(remainingValues);
            changed = changed || !remainingValues.isEmpty();
        }
    }
    return changed;
}

From source file:org.vulpe.commons.util.VulpeReflectUtil.java

/**
 * Copy attributes from <code>origin</code> to <code>destination</code>.
 *
 * @param destination/* w  w w .  j a  va 2 s.  c o m*/
 * @param origin
 * @param ignoreTransient
 */
public static void copy(final Object destination, final Object origin, boolean ignoreTransient) {
    final List<Field> fields = getFields(origin.getClass());
    for (final Field field : fields) {
        if (ignoreTransient && Modifier.isTransient(field.getModifiers())) {
            continue;
        }
        try {
            final Object value = PropertyUtils.getProperty(origin, field.getName());
            if (Collection.class.isAssignableFrom(field.getType())) {
                final Collection valueDes = (Collection) PropertyUtils.getProperty(destination,
                        field.getName());
                if (value == null) {
                    if (valueDes != null) {
                        valueDes.clear();
                    }
                } else {
                    if (valueDes == null) {
                        PropertyUtils.setProperty(destination, field.getName(), value);
                    } else {
                        valueDes.clear();
                        valueDes.addAll((Collection) value);
                    }
                }
            } else {
                PropertyUtils.setProperty(destination, field.getName(), value);
            }
        } catch (NoSuchMethodException e) {
            LOG.debug("Method not found.", e);
        } catch (Exception e) {
            throw new VulpeSystemException(e);
        }
    }
}

From source file:org.vulpe.commons.util.VulpeReflectUtil.java

/**
 * Copy transient attributes from <code>origin</code> to
 * <code>destination</code>.
 *
 * @param destination//from w w w  . j  a  va  2s  .  c o  m
 * @param origin
 */
public static void copyOnlyTransient(final Object destination, final Object origin) {
    final List<Field> fields = getFields(origin.getClass());
    for (final Field field : fields) {
        if (!Modifier.isTransient(field.getModifiers())) {
            continue;
        }
        try {
            final Object value = PropertyUtils.getProperty(origin, field.getName());
            if (Collection.class.isAssignableFrom(field.getType())) {
                final Collection valueDes = (Collection) PropertyUtils.getProperty(destination,
                        field.getName());
                if (value == null) {
                    if (valueDes != null) {
                        valueDes.clear();
                    }
                } else {
                    if (valueDes == null) {
                        PropertyUtils.setProperty(destination, field.getName(), value);
                    } else {
                        valueDes.clear();
                        valueDes.addAll((Collection) value);
                    }
                }
            } else {
                PropertyUtils.setProperty(destination, field.getName(), value);
            }
        } catch (NoSuchMethodException e) {
            LOG.debug("Method not found.", e);
        } catch (Exception e) {
            throw new VulpeSystemException(e);
        }
    }
}

From source file:org.vaadin.tori.util.ToriScheduler.java

private void executeCommands(final Collection<ScheduledCommand> commands) {
    final Collection<ScheduledCommand> executableCommands = new ArrayList<ScheduledCommand>(commands);
    commands.clear();

    for (ScheduledCommand command : executableCommands) {
        try {//from   ww w  .  ja  v  a 2 s.  co m
            command.execute();
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.squashtest.tm.service.internal.customfield.CustomFieldHelperImpl.java

private <Y> void retainUniques(Collection<Y> argument) {
    Set<Y> set = new LinkedHashSet<>(argument);
    argument.clear();
    argument.addAll(set);/*from  w  w  w .j  ava2 s. c o  m*/
}