List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:com.amazonaws.services.kinesis.aggregators.StreamAggregatorUtils.java
/** * Get a list of all Open shards ordered by their start hash * //w w w . j a va2 s. c om * @param streamName * @return A Map of only Open Shards indexed by the Shard ID */ public static Map<String, Shard> getOpenShards(AmazonKinesisClient kinesisClient, String streamName) throws Exception { Map<String, Shard> shardMap = new LinkedHashMap<>(); final int BACKOFF_MILLIS = 10; final int MAX_DESCRIBE_ATTEMPTS = 10; int describeAttempts = 0; StreamDescription stream = null; try { do { try { stream = kinesisClient.describeStream(streamName).getStreamDescription(); } catch (LimitExceededException e) { Thread.sleep(2 ^ describeAttempts * BACKOFF_MILLIS); describeAttempts++; } } while (stream == null && describeAttempts < MAX_DESCRIBE_ATTEMPTS); } catch (InterruptedException e) { LOG.error(e); throw e; } if (stream == null) { throw new Exception( String.format("Unable to describe Stream after %s attempts", MAX_DESCRIBE_ATTEMPTS)); } Collection<String> openShardNames = new ArrayList<String>(); // load all the shards on the stream for (Shard shard : stream.getShards()) { openShardNames.add(shard.getShardId()); shardMap.put(shard.getShardId(), shard); // remove this shard's parents from the set of active shards - // we // can't do anything to them if (shard.getParentShardId() != null) { openShardNames.remove(shard.getParentShardId()); } if (shard.getAdjacentParentShardId() != null) { openShardNames.remove(shard.getAdjacentParentShardId()); } } // create a List of Open shards for sorting List<Shard> shards = new ArrayList<Shard>(); for (String s : openShardNames) { shards.add(shardMap.get(s)); } // sort the list into lowest start hash order Collections.sort(shards, new Comparator<Shard>() { public int compare(Shard o1, Shard o2) { return new BigInteger(o1.getHashKeyRange().getStartingHashKey()) .compareTo(new BigInteger(o2.getHashKeyRange().getStartingHashKey())); } }); // rebuild the shard map into the correct order shardMap.clear(); for (Shard s : shards) { shardMap.put(s.getShardId(), s); } return shardMap; }
From source file:com.nextep.datadesigner.vcs.impl.VersionableSorter.java
private static void processItem(List<IVersionable<?>> sortedList, Map<IReference, IVersionable<?>> invRefMap, IVersionable<?> toAdd, Collection<IVersionable<?>> stack) { Collection<IReference> refs = toAdd.getReferenceDependencies(); Collection<IReference> ownReferences = toAdd.getReferenceMap().keySet(); // If the stack already contains the versionable to add, dependency deadloop ! // We stop the process here if (stack.contains(toAdd)) { log.warn("Deadloop found in schema inner dependencies: unsafe dependency resolution."); return;// w ww . j a va2s . c o m } stack.add(toAdd); for (IReference r : refs) { final IVersionable<?> v = invRefMap.get(r); if (v != null && !sortedList.contains(v) && !ownReferences.contains(r) && toAdd.getReference() != r) { processItem(sortedList, invRefMap, v, stack); } } stack.remove(toAdd); // Might have already been imported if (!sortedList.contains(toAdd)) { sortedList.add(toAdd); } }
From source file:org.apache.ode.utils.wsdl.WsdlUtils.java
@SuppressWarnings("unchecked") public static Collection<UnknownExtensibilityElement> getHttpHeaders(List extensibilityElements) { final Collection<UnknownExtensibilityElement> unknownExtElements = CollectionsX .filter(extensibilityElements, UnknownExtensibilityElement.class); for (UnknownExtensibilityElement extensibilityElement : unknownExtElements) { final Element e = extensibilityElement.getElement(); // keep only the header elements if (!Namespaces.ODE_HTTP_EXTENSION_NS.equalsIgnoreCase(e.getNamespaceURI()) || !"header".equals(extensibilityElement.getElement().getLocalName())) { unknownExtElements.remove(extensibilityElement); }//from w ww .ja va 2s . c o m } return unknownExtElements; }
From source file:org.apache.sling.testing.mock.osgi.OsgiServiceUtil.java
@SuppressWarnings("unchecked") private static void removeFromCollection(Object target, Field field, Object item) { try {/*from w ww .j a v a2s .c o m*/ field.setAccessible(true); Collection<Object> collection = (Collection<Object>) field.get(target); if (collection == null) { collection = new ArrayList<Object>(); } if (item != null) { collection.remove(item); } field.set(target, collection); } catch (IllegalAccessException ex) { throw new RuntimeException( "Unable to set field '" + field.getName() + "' for class " + target.getClass().getName(), ex); } catch (IllegalArgumentException ex) { throw new RuntimeException( "Unable to set field '" + field.getName() + "' for class " + target.getClass().getName(), ex); } }
From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java
public static <T extends Object> void realRemoveAll(Collection<T> array, Collection<T> c) { // ?removeAll for (Object obj : c) { array.remove(obj); }// w w w . j a va 2s .c o m }
From source file:org.apache.openjpa.lib.conf.Configurations.java
private static Collection<String> findOptionsFor(Class<?> cls) { Collection<String> c = Options.findOptionsFor(cls); // remove Configurable.setConfiguration() and // GenericConfigurable.setInto() from the set, if applicable. if (Configurable.class.isAssignableFrom(cls)) c.remove("Configuration"); if (GenericConfigurable.class.isAssignableFrom(cls)) c.remove("Into"); return c;/*from w ww .j av a2 s. c o m*/ }
From source file:com.android.repository.util.InstallerUtil.java
/** * Compute the complete list of packages that need to be installed to meet the dependencies of * the given list (including the requested packages themselves, if they are not already * installed). Returns {@code null} if we were unable to compute a complete list of dependencies * due to not being able to find required packages of the specified version. * * Packages are returned in install order (that is, if we request A which depends on B, the * result will be [B, A]). If a dependency cycle is encountered the order of the returned * results at or below the cycle is undefined. For example if we have A -> [B, C], B -> D, and D * -> B then the returned list will be either [B, D, C, A] or [D, B, C, A]. * * Note that we assume installed packages already have their dependencies met. */// ww w.j a v a 2 s .c o m @Nullable public static List<RemotePackage> computeRequiredPackages(@NonNull Collection<RemotePackage> requests, @NonNull RepositoryPackages packages, @NonNull ProgressIndicator logger) { Set<RemotePackage> requiredPackages = Sets.newHashSet(); Map<String, UpdatablePackage> consolidatedPackages = packages.getConsolidatedPkgs(); Set<String> seen = Sets.newHashSet(); Multimap<String, Dependency> allDependencies = HashMultimap.create(); Set<RemotePackage> roots = Sets.newHashSet(); Queue<RemotePackage> current = Lists.newLinkedList(); for (RemotePackage request : requests) { UpdatablePackage updatable = consolidatedPackages.get(request.getPath()); if (updatable == null) { logger.logWarning(String.format("No package with key %s found!", request.getPath())); return null; } if (!updatable.hasLocal() || updatable.isUpdate()) { current.add(request); roots.add(request); requiredPackages.add(request); seen.add(request.getPath()); } } while (!current.isEmpty()) { RemotePackage currentPackage = current.remove(); Collection<Dependency> currentDependencies = currentPackage.getAllDependencies(); for (Dependency d : currentDependencies) { String dependencyPath = d.getPath(); UpdatablePackage updatableDependency = consolidatedPackages.get(dependencyPath); if (updatableDependency == null) { logger.logWarning(String.format("Dependant package with key %s not found!", dependencyPath)); return null; } LocalPackage localDependency = updatableDependency.getLocal(); Revision requiredMinRevision = null; RevisionType r = d.getMinRevision(); if (r != null) { requiredMinRevision = r.toRevision(); } if (localDependency != null && (requiredMinRevision == null || requiredMinRevision.compareTo(localDependency.getVersion()) <= 0)) { continue; } if (seen.contains(dependencyPath)) { allDependencies.put(dependencyPath, d); continue; } seen.add(dependencyPath); RemotePackage remoteDependency = updatableDependency.getRemote(); if (remoteDependency == null || (requiredMinRevision != null && requiredMinRevision.compareTo(remoteDependency.getVersion()) > 0)) { logger.logWarning(String.format("Package \"%1$s\" with revision at least %2$s not available.", updatableDependency.getRepresentative().getDisplayName(), requiredMinRevision)); return null; } requiredPackages.add(remoteDependency); allDependencies.put(dependencyPath, d); current.add(remoteDependency); // We had a dependency on it, so it can't be a root. roots.remove(remoteDependency); } } List<RemotePackage> result = Lists.newArrayList(); while (!roots.isEmpty()) { RemotePackage root = roots.iterator().next(); roots.remove(root); result.add(root); for (Dependency d : root.getAllDependencies()) { Collection<Dependency> nodeDeps = allDependencies.get(d.getPath()); if (nodeDeps.size() == 1) { UpdatablePackage newRoot = consolidatedPackages.get(d.getPath()); if (newRoot == null) { logger.logWarning(String.format("Package with key %s not found!", d.getPath())); return null; } roots.add(newRoot.getRemote()); } nodeDeps.remove(d); } } if (result.size() != requiredPackages.size()) { logger.logInfo("Failed to sort dependencies, returning partially-sorted list."); for (RemotePackage p : result) { requiredPackages.remove(p); } result.addAll(requiredPackages); } return Lists.reverse(result); }
From source file:com.gm.bamboo.util.HibernateUtils.java
/** * ?ID?, ???.//from w ww . j a v a 2 s .co m * * ??????id,Hibernate??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update??. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ?,IdEntity? */ public static <T extends BaseEntity> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<Long> checkedIds, final Class<T> clazz) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.notNull(clazz, "clazz?"); //?, ???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?. //?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Long id = element.getId(); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (Long id : checkedIds) { T element = clazz.newInstance(); element.setId(id); srcObjects.add(element); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:com.gm.wine.util.HibernateUtils.java
/** * ?ID?, ???.//from w ww . j av a2 s. co m * * ??????id,Hibernate??????id?????. * ???id??,??id??. ?ID, * ??cascade-save-or-update??. * * @param srcObjects * ??,. * @param checkedIds * ?,ID. * @param clazz * ?,IdEntity? */ public static <T extends BaseEntity> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<Long> checkedIds, final Class<T> clazz) { // ? Assert.notNull(srcObjects, "scrObjects?"); Assert.notNull(clazz, "clazz?"); // ?, ???. if (checkedIds == null) { srcObjects.clear(); return; } // ????,id?ID?. // ?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Long id = element.getId(); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } // ID??id????,,id??. for (Long id : checkedIds) { T element = clazz.newInstance(); element.setId(id); srcObjects.add(element); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:doc.action.SelectedDocsUtils.java
public static Collection saveSelectedDocsIDs(HttpServletRequest request) { //System.out.println("start"); Collection documents = (Collection) request.getSession().getAttribute(Constant.SELECTED_PRESIDENTS); //System.out.println(documents); if (documents == null) { documents = new ArrayList(); request.getSession().setAttribute(Constant.SELECTED_PRESIDENTS, documents); }// ww w. ja va2s . c o m Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); if (parameterName.startsWith("chkbx_")) { String docId = StringUtils.substringAfter(parameterName, "chkbx_"); String parameterValue = request.getParameter(parameterName); if (parameterValue.equals(Constant.SELECTED)) { if (!documents.contains(docId)) { documents.add(docId); } } else { documents.remove(docId); } } } return documents; }