List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:edu.stanford.muse.groups.Grouper.java
private Node<SimilarGroup<T>> doBinaryMove(GroupsGraph<T> graph, SimilarGroup<T> newGroup, Node<SimilarGroup<T>> n1, Node<SimilarGroup<T>> n2, BestMoveTracker bmt, float newNodeValue) { // 1. first figure out which nodes are being invalidated... w/o updating the graph Collection<Node<SimilarGroup<T>>> invalidatedNodes = computeInvalidatedNodes(n1, n2, bmt); // what elements are we losing? add invalidated nodes based on those Collection<T> lostElements = n1.payload.minus(newGroup).union(n2.payload.minus(newGroup)).elements(); if (lostElements != null) invalidatedNodes.addAll(computeInvalidatedDueToLostElements(graph, lostElements, bmt)); bmt.removeBestMovesFor(invalidatedNodes); // 2. then update the graph. Node<SimilarGroup<T>> resultingNode = updateGraph(graph, n1, n2, newGroup, newNodeValue); // 3. then recompute moves for invalidated nodes // we don't want to recalculate for the nodes we're dropping; just for the one we're adding invalidatedNodes.remove(n1); invalidatedNodes.remove(n2);//from w w w .jav a2s . com invalidatedNodes.add(resultingNode); for (Node<SimilarGroup<T>> affected : invalidatedNodes) bmt.refreshBestMoveForNode(affected); return resultingNode; }
From source file:ubic.gemma.analysis.service.ArrayDesignAnnotationServiceImpl.java
/** * @param gene/*from ww w . j ava 2 s . com*/ * @param ty Configures which GO terms to return: With all parents, biological process only, or direct annotations * only. * @return the goTerms for a given gene, as configured */ private Collection<OntologyTerm> getGoTerms(Gene gene, Collection<VocabCharacteristic> ontos, OutputType ty) { Collection<OntologyTerm> results = new HashSet<OntologyTerm>(); if (ontos == null || ontos.size() == 0) return results; for (VocabCharacteristic vc : ontos) { results.add(GeneOntologyServiceImpl.getTermForId(vc.getValue())); } if (ty.equals(OutputType.SHORT)) return results; if (ty.equals(OutputType.LONG)) { Collection<OntologyTerm> oes = goService.getAllParents(results); results.addAll(oes); } else if (ty.equals(OutputType.BIOPROCESS)) { Collection<OntologyTerm> toRemove = new HashSet<OntologyTerm>(); for (OntologyTerm ont : results) { if ((ont == null)) { continue; // / shouldn't happen! } if (!goService.isBiologicalProcess(ont)) { toRemove.add(ont); } } for (OntologyTerm toRemoveOnto : toRemove) { results.remove(toRemoveOnto); } } return results; }
From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.FactRuleEvaluator.java
public void validateFact(Collection<AbstractFact> facts) { KieSession ksession = null;// ww w . ja v a 2 s . c om try { KieContainer container = KieServices.Factory.get() .newKieContainer(KieServices.Factory.get().getRepository().getDefaultReleaseId()); ksession = container.newKieSession(); ksession.setGlobal("salesService", salesRulesService); ksession.setGlobal("mdrService", mdrCacheRuleService); ksession.setGlobal("exchangeService", exchangeRuleService); for (AbstractFact fact : facts) { // Insert All the facts ksession.insert(fact); } ksession.fireAllRules(); ksession.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); Collection<?> objects = null; if (ksession != null) { objects = ksession.getObjects(); } if (CollectionUtils.isNotEmpty(objects)) { Collection<AbstractFact> failedFacts = (Collection<AbstractFact>) objects; AbstractFact next = failedFacts.iterator().next(); String message = e.getMessage(); String brId = message.substring(message.indexOf('/') + 1, message.indexOf(".drl")); next.addWarningOrError("WARNING", message, brId, "L099", StringUtils.EMPTY); next.setOk(false); facts.remove(next); // remove fact with exception and re-validate the other facts exceptionsList.add(next); validateFact(facts); } } }
From source file:org.kitodo.dataaccess.storage.memory.MemoryNode.java
@Override public boolean matches(ObjectType condition) { if (condition == null) { return true; }/*from www . j a va 2 s .c om*/ if (!(condition instanceof Node)) { return false; } for (String relation : ((Node) condition).getRelations()) { Iterator<ObjectType> candidates; if (relation.equals(GraphPath.ANY_PREDICATE.getIdentifier())) { candidates = iterator(); } else { Collection<ObjectType> related = edges.get(relation); if (related == null) { return false; } candidates = related.iterator(); } Collection<ObjectType> conditions = new LinkedList<>(); ((Node) condition).get(relation).forEach(conditions::add); while (candidates.hasNext() && !conditions.isEmpty()) { ObjectType candidate = candidates.next(); if (candidate instanceof AccessibleObject) { for (Iterator<ObjectType> i = conditions.iterator(); i.hasNext();) { ObjectType currentCondition = i.next(); if (((AccessibleObject) candidate).matches(currentCondition)) { i.remove(); } } } else { conditions.remove(candidate); } } if (!conditions.isEmpty()) { return false; } } return true; }
From source file:de.juwimm.cms.remote.UserServiceSpringImpl.java
/** * Removes some ViewComponents from this Task. * /*from ww w. j a v a2 s . com*/ * @param taskId * TaskId of the related Task * @param vcIds * Integer Array of ViewComponents to remove. * * @see de.juwimm.cms.remote.UserServiceSpring#removeViewComponentsFromTask(java.lang.Integer, * java.lang.Integer[]) */ @Override protected void handleRemoveViewComponentsFromTask(Integer taskId, Integer[] vcIds) throws Exception { UserHbm user = null; TaskHbm task = null; try { user = super.getUserHbmDao().load(AuthenticationHelper.getUserName()); task = super.getTaskHbmDao().load(taskId); if (task != null) { if (!!getUserHbmDao().isInRole(user, UserRights.SITE_ROOT, user.getActiveSite()) && !user.equals(task.getReceiver()) && !user.equals(task.getSender()) && !!getUserHbmDao().isInRole(user, task.getReceiverRole(), user.getActiveSite())) { throw new SecurityException("User is not responsible to change this Task. RECEIVER:" + task.getReceiver() + " SENDER:" + task.getSender() + " RECEIVERROLE:" + task.getReceiverRole() + " THIS USER:" + user.getUserId()); } try { Collection<ViewComponentHbm> coll = task.getViewComponents(); for (int i = 0; i < vcIds.length; i++) { ViewComponentHbm vc = super.getViewComponentHbmDao().load(vcIds[i]); coll.remove(vc); } task.setViewComponents(coll); } catch (Exception exe) { log.error("Error occured", exe); } } else { log.warn("Task with Id " + taskId + " was not found"); } } catch (Exception e) { throw new UserException(e.getMessage()); } }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java
@Override public void remove(PersistencePackage persistencePackage) throws ServiceException { Entity entity = persistencePackage.getEntity(); PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems() .get(PersistencePerspectiveItemType.FOREIGNKEY); if (foreignKey != null && !foreignKey.getMutable()) { throw new SecurityServiceException("Entity not mutable"); }//from ww w . j a v a 2 s .co m try { Class<?>[] entities = persistenceManager .getPolymorphicEntities(persistencePackage.getCeilingEntityFullyQualifiedClassname()); Map<String, FieldMetadata> mergedUnfilteredProperties = persistenceManager.getDynamicEntityDao() .getMergedProperties(persistencePackage.getCeilingEntityFullyQualifiedClassname(), entities, foreignKey, persistencePerspective.getAdditionalNonPersistentProperties(), persistencePerspective.getAdditionalForeignKeys(), MergedPropertyType.PRIMARY, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), ""); Map<String, FieldMetadata> mergedProperties = filterOutCollectionMetadata(mergedUnfilteredProperties); Object primaryKey = getPrimaryKey(entity, mergedProperties); Serializable instance = persistenceManager.getDynamicEntityDao() .retrieve(Class.forName(entity.getType()[0]), primaryKey); Assert.isTrue(instance != null, "Entity not found"); switch (persistencePerspective.getOperationTypes().getRemoveType()) { case NONDESTRUCTIVEREMOVE: FieldManager fieldManager = getFieldManager(); FieldMetadata manyToFieldMetadata = mergedUnfilteredProperties.get(foreignKey.getManyToField()); Object foreignKeyValue = entity.getPMap().get(foreignKey.getManyToField()).getValue(); try { foreignKeyValue = Long.valueOf((String) foreignKeyValue); } catch (NumberFormatException e) { LOG.warn("Foreign primary key is not of type Long, assuming String for remove lookup"); } Serializable foreignInstance = persistenceManager.getDynamicEntityDao() .retrieve(Class.forName(foreignKey.getForeignKeyClass()), foreignKeyValue); Collection collection = (Collection) fieldManager.getFieldValue(foreignInstance, foreignKey.getOriginatingField()); collection.remove(instance); // if this is a bi-directional @OneToMany/@ManyToOne and there is no @JoinTable (just a foreign key on // the @ManyToOne side) then it will not be updated. In that instance, we have to explicitly // set the manyTo field to null so that subsequent lookups will not find it if (manyToFieldMetadata instanceof BasicFieldMetadata) { if (BooleanUtils.isTrue(((BasicFieldMetadata) manyToFieldMetadata).getRequired())) { throw new ServiceException("Could not remove from the collection as the ManyToOne side is a" + " non-optional relationship. Consider changing 'optional=true' in the @ManyToOne annotation" + " or nullable=true within the @JoinColumn annotation"); } //Since this is occuring on a remove persistence package, merge up-front (before making a change) for proper operation in the presence of the enterprise module instance = persistenceManager.getDynamicEntityDao().merge(instance); Field manyToField = fieldManager.getField(instance.getClass(), foreignKey.getManyToField()); Object manyToObject = manyToField.get(instance); if (manyToObject != null && !(manyToObject instanceof Collection) && !(manyToObject instanceof Map)) { manyToField.set(instance, null); instance = persistenceManager.getDynamicEntityDao().merge(instance); } } break; case BASIC: persistenceManager.getDynamicEntityDao().remove(instance); break; } } catch (Exception e) { throw new ServiceException("Problem removing entity : " + e.getMessage(), e); } }
From source file:com.yahoo.elide.core.PersistentResource.java
/** * Deletes an existing element in a collection and tests update and delete permissions. * @param collection the collection/* ww w. j a v a 2s .com*/ * @param collectionName the collection name * @param toDelete the to delete */ protected void delFromCollection(Collection collection, String collectionName, PersistentResource toDelete) { if (collection == null) { return; } collection.remove(toDelete.getObject()); }
From source file:org.apache.cayenne.map.ObjEntity.java
/** * Returns an ObjEntity stripped of any server-side information, such as * DbEntity mapping. "clientClassName" property of this entity is used to * initialize "className" property of returned entity. * /*from w w w.ja v a 2 s . c om*/ * @since 1.2 */ public ObjEntity getClientEntity() { ClientObjEntity entity = new ClientObjEntity(getName()); entity.setClassName(getClientClassName()); entity.setSuperClassName(getClientSuperClassName()); entity.setSuperEntityName(getSuperEntityName()); entity.setDeclaredQualifier(getDeclaredQualifier()); // TODO: should we also copy lock type? Collection<ObjAttribute> primaryKeys = getMutablePrimaryKeys(); Collection<ObjAttribute> clientPK = new ArrayList<>(primaryKeys.size()); for (ObjAttribute attribute : getDeclaredAttributes()) { ObjAttribute clientAttribute = attribute.getClientAttribute(); entity.addAttribute(clientAttribute); if (primaryKeys.remove(attribute)) { clientPK.add(clientAttribute); } } // after all meaningful pks got removed, here we only have synthetic pks // left... for (ObjAttribute attribute : primaryKeys) { ObjAttribute clientAttribute = attribute.getClientAttribute(); clientPK.add(clientAttribute); } entity.setPrimaryKeys(clientPK); // copy relationships; skip runtime generated relationships for (ObjRelationship relationship : getDeclaredRelationships()) { if (relationship.isRuntime()) { continue; } ObjEntity targetEntity = relationship.getTargetEntity(); // note that 'isClientAllowed' also checks parent DataMap client // policy // that can be handy in case of cross-map relationships if (targetEntity == null || !targetEntity.isClientAllowed()) { continue; } entity.addRelationship(relationship.getClientRelationship()); } // TODO: andrus 2/5/2007 - copy embeddables // TODO: andrus 2/5/2007 - copy callback methods return entity; }
From source file:org.limewire.mojito.routing.impl.RouteTableImpl.java
private synchronized void mergeBuckets() { // Get the active Contacts Collection<Contact> activeNodes = getActiveContacts(); activeNodes = ContactUtils.sortAliveToFailed(activeNodes); // Get the cached Contacts Collection<Contact> cachedNodes = getCachedContacts(); cachedNodes = ContactUtils.sort(cachedNodes); // We count on the fact that getActiveContacts() and // getCachedContacts() return copies! clear();/*ww w . ja va 2s . co m*/ // Remove the local Node from the List. Shouldn't fail as // activeNodes is a copy! boolean removed = activeNodes.remove(localNode); assert (removed); // Re-add the active Contacts for (Contact node : activeNodes) { add(node); } // And re-add the cached Contacts for (Contact node : cachedNodes) { add(node); } }
From source file:org.lilyproject.repository.impl.HBaseTypeManager.java
private boolean updateFieldTypeEntries(Put put, Long newRecordTypeVersion, RecordType recordType, RecordType latestRecordType) throws FieldTypeNotFoundException, TypeException { boolean changed = false; Collection<FieldTypeEntry> latestFieldTypeEntries = latestRecordType.getFieldTypeEntries(); // Update FieldTypeEntries for (FieldTypeEntry fieldTypeEntry : recordType.getFieldTypeEntries()) { FieldTypeEntry latestFieldTypeEntry = latestRecordType .getFieldTypeEntry(fieldTypeEntry.getFieldTypeId()); if (!fieldTypeEntry.equals(latestFieldTypeEntry)) { putFieldTypeEntry(newRecordTypeVersion, put, fieldTypeEntry); changed = true;//from w w w . ja v a2 s . c o m } latestFieldTypeEntries.remove(latestFieldTypeEntry); } // Remove remaining FieldTypeEntries for (FieldTypeEntry fieldTypeEntry : latestFieldTypeEntries) { put.add(TypeCf.FIELDTYPE_ENTRY.bytes, fieldTypeEntry.getFieldTypeId().getBytes(), newRecordTypeVersion, DELETE_MARKER); changed = true; } return changed; }