List of usage examples for java.util Collection removeAll
boolean removeAll(Collection<?> c);
From source file:org.orcas.commons.collections.CollectionUtils.java
public static <E> Collection<E> reject(Collection<E> collection, String iteratorName, String expression) throws Exception { Collection<E> selected = select(collection, iteratorName, expression); collection.removeAll(selected); return collection; }
From source file:com.puppycrawl.tools.checkstyle.filters.SuppressionCommentFilterTest.java
private static String[] removeSuppressed(String[] from, String... remove) { final Collection<String> coll = Lists.newArrayList(Arrays.asList(from)); coll.removeAll(Arrays.asList(remove)); return coll.toArray(new String[coll.size()]); }
From source file:Main.java
public static <T> boolean retainAllByValue(Collection<T> c1, Collection<? extends T> c2) { if (c1 == null || c2 == null || c1.isEmpty() || c2.isEmpty()) return false; List<T> itemsToRemove = new ArrayList<T>(); for (T item : c1) { if (!containsByValue(c2, item)) itemsToRemove.add(item);// w w w . j av a2s .c om } c1.removeAll(itemsToRemove); return (!itemsToRemove.isEmpty()); }
From source file:org.mitre.mpf.wfm.service.component.StartupComponentRegistrationServiceImpl.java
private static void logDescriptorsWithNoMatchingPackages(Collection<Path> allDeployedDescriptors, Collection<Path> mappedDescriptors) { Collection<Path> descriptorsWithNoMatchingPackages = new HashSet<>(allDeployedDescriptors); descriptorsWithNoMatchingPackages.removeAll(mappedDescriptors); if (descriptorsWithNoMatchingPackages.isEmpty()) { return;/*from w w w. ja va 2 s . c om*/ } _log.error( "The following descriptors do not have a matching component package and can not be registered: "); descriptorsWithNoMatchingPackages.forEach(d -> _log.error(d.toString())); }
From source file:Main.java
public static <T> Collection<T> subtract(Collection<T> list1, Collection<T> list2, Comparator<? super T> comp) { Collection<T> removedList = new ArrayList<T>(); for (T item1 : list1) { for (T item2 : list2) { if (comp.compare(item1, item2) == 0) { removedList.add(item1);/*from www. j av a 2 s. c o m*/ } } } list1.removeAll(removedList); return list1; }
From source file:com.comphenix.protocol.injector.EntityUtilities.java
public static void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException { if (entity == null || !entity.isValid()) { return;//from w w w .j av a 2 s . c om } try { Object trackerEntry = getEntityTrackerEntry(entity.getWorld(), entity.getEntityId()); if (trackerEntry == null) { throw new IllegalArgumentException("Cannot find entity trackers for " + entity + "."); } if (trackedPlayersField == null) { trackedPlayersField = FuzzyReflection.fromObject(trackerEntry).getFieldByType("java\\.util\\..*"); } // Phew, finally there. Collection<?> trackedPlayers = getTrackedPlayers(trackedPlayersField, trackerEntry); List<Object> nmsPlayers = unwrapBukkit(observers); trackedPlayers.removeAll(nmsPlayers); // We have to rely on a NAME once again. Damn it. // TODO: Make sure this stays up to date with version changes - 1.8 - 1.10 if (scanPlayersMethod == null) { scanPlayersMethod = trackerEntry.getClass().getMethod("scanPlayers", List.class); } scanPlayersMethod.invoke(trackerEntry, nmsPlayers); } catch (IllegalArgumentException e) { throw e; } catch (IllegalAccessException e) { throw new FieldAccessException("Security limitation prevents access to 'get' method in IntHashMap", e); } catch (InvocationTargetException e) { throw new RuntimeException("Exception occurred in Minecraft.", e); } catch (SecurityException e) { throw new FieldAccessException( "Security limitation prevents access to 'scanPlayers' method in trackerEntry.", e); } catch (NoSuchMethodException e) { throw new FieldAccessException("Cannot find 'scanPlayers' method. Is ProtocolLib up to date?", e); } }
From source file:org.apache.axis2.clustering.zookeeper.ZooKeeperUtils.java
/** * calculates the new members in the list when old and new list of members * are given/* w ww. ja v a 2 s. c om*/ * * @param existingMembers - the old set of members * @param currentMembers - new set of members * @return a list of members */ public static List<ZkMember> getNewMembers(List<ZkMember> existingMembers, List<ZkMember> currentMembers) { Collection<ZkMember> oldList = new ArrayList<ZkMember>(existingMembers); Collection<ZkMember> newList = new ArrayList<ZkMember>(currentMembers); newList.removeAll(oldList); return (List<ZkMember>) newList; }
From source file:de.cubeisland.engine.core.util.McUUID.java
public static Map<String, UUID> getUUIDForNames(Collection<String> playerNames) { Map<String, UUID> map = new HashMap<>(); for (Profile profile : getUUIDForNames0(playerNames)) { try {/* w ww. j a va2 s .co m*/ map.put(profile.name, getUUIDFromString(profile.id)); } catch (Exception e) { CubeEngine.getLog().error("Could not convert UUID of: {} ({})", profile.name, profile.id); } } playerNames = new HashSet<>(playerNames); playerNames.removeAll(map.keySet()); for (String playerName : playerNames) { CubeEngine.getLog().error("Missing UUID for {}", playerName); map.put(playerName, null); } return map; }
From source file:org.jaffa.soa.dataaccess.MappingFilter.java
/** Returns a Map of all the possible objects and fields that are being excluded from this domain object graph, * based on the declared scope in the mapping files. * For each object, the Map will contain the Class and the associated Collection of Fields. * If an object is being completely excluded, the associated Collection will be null. * @param gdo the Class for a graph data object. * @return a Map of all the possible objects and fields that are being excluded from this domain object graph. *///ww w .j a va2 s .c o m public static Map<Class, Collection<String>> getExcludedFieldMap(Class<? extends GraphDataObject> gdo) { //classes+fields in the default scope Map<Class, Collection<String>> allFields = new LinkedHashMap<Class, Collection<String>>(); getFieldList(gdo, null, allFields, null, true, null, true, true); //classes+fields in the declared scope Map<Class, Collection<String>> includedFields = new LinkedHashMap<Class, Collection<String>>(); getFieldList(gdo, null, includedFields, null, true, null, false, true); //Create the Map of excluded fields from the above 2 maps Map<Class, Collection<String>> excludedFields = new LinkedHashMap<Class, Collection<String>>(); for (Map.Entry<Class, Collection<String>> me : allFields.entrySet()) { if (includedFields.containsKey(me.getKey())) { Collection<String> all = me.getValue(); all.removeAll(includedFields.get(me.getKey())); if (!all.isEmpty()) excludedFields.put(me.getKey(), all); } else { excludedFields.put(me.getKey(), null); } } return excludedFields; }
From source file:org.eclipse.skalli.core.persistence.EntityHelper.java
private static void doNormalize(EntityBase entity) { if (entity == null) { return;/*w w w . j av a 2s .c om*/ } Class<?> currentClass = entity.getClass(); while (currentClass != null) { for (Field field : currentClass.getDeclaredFields()) { try { // do not try to change constants or transient fields int modifiers = field.getModifiers(); if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) { continue; } field.setAccessible(true); // ensure, thet the value is non null Object value = field.get(entity); if (value == null) { instantiateField(entity, field); } else { // for non-null collections or maps, ensure that there // are no null entries or empty strings Class<?> type = field.getType(); if (Collection.class.isAssignableFrom(type)) { Collection<?> collection = (Collection<?>) value; ArrayList<Object> remove = new ArrayList<Object>(); for (Object entry : collection) { if (entry instanceof String && StringUtils.isBlank((String) entry)) { remove.add(entry); } } collection.removeAll(remove); field.set(entity, collection); } else if (Map.class.isAssignableFrom(type)) { Map<?, ?> map = (Map<?, ?>) value; ArrayList<Object> remove = new ArrayList<Object>(); for (Entry<?, ?> entry : map.entrySet()) { if (entry.getValue() instanceof String && StringUtils.isBlank((String) entry.getValue())) { remove.add(entry.getKey()); } } for (Object key : remove) { map.remove(key); } field.set(entity, map); } } } catch (UnsupportedOperationException e) { // TODO exception handling/logging // some collections/map may not support remove throw new RuntimeException(e); } catch (IllegalArgumentException e) { //TODO exception handling/logging throw new RuntimeException(e); } catch (IllegalAccessException e) { //TODO exception handling/logging throw new RuntimeException(e); } } currentClass = currentClass.getSuperclass(); } }