List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:edu.uci.ics.jung.io.PajekNetWriter.java
/** * Writes <code>graph</code> to <code>w</code>. Labels for vertices may * be supplied by <code>vs</code> (defaults to no labels if null), * edge weights may be specified by <code>nev</code> * (defaults to weights of 1.0 if null), * and vertex locations may be specified by <code>vld</code> (defaults * to no locations if null). /* w ww. j a va 2s . c o m*/ */ public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev, Transformer<V, Point2D> vld) throws IOException { /* * TODO: Changes we might want to make: * - optionally writing out in list form */ BufferedWriter writer = new BufferedWriter(w); if (nev == null) nev = new Transformer<E, Number>() { public Number transform(E e) { return 1; } }; writer.write("*Vertices " + graph.getVertexCount()); writer.newLine(); List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph); for (V currentVertex : graph.getVertices()) { // convert from 0-based to 1-based index int v_id = id.indexOf(currentVertex) + 1; writer.write("" + v_id); if (vs != null) { String label = vs.transform(currentVertex); if (label != null) writer.write(" \"" + label + "\""); } if (vld != null) { Point2D location = vld.transform(currentVertex); if (location != null) writer.write(" " + location.getX() + " " + location.getY() + " 0.0"); } writer.newLine(); } Collection<E> d_set = new HashSet<E>(); Collection<E> u_set = new HashSet<E>(); boolean directed = graph instanceof DirectedGraph; boolean undirected = graph instanceof UndirectedGraph; // if it's strictly one or the other, no need to create extra sets if (directed) d_set.addAll(graph.getEdges()); if (undirected) u_set.addAll(graph.getEdges()); if (!directed && !undirected) // mixed-mode graph { u_set.addAll(graph.getEdges()); d_set.addAll(graph.getEdges()); for (E e : graph.getEdges()) { if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) { d_set.remove(e); } else { u_set.remove(e); } } } // write out directed edges if (!d_set.isEmpty()) { writer.write("*Arcs"); writer.newLine(); } for (E e : d_set) { int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1; int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1; float weight = nev.transform(e).floatValue(); writer.write(source_id + " " + target_id + " " + weight); writer.newLine(); } // write out undirected edges if (!u_set.isEmpty()) { writer.write("*Edges"); writer.newLine(); } for (E e : u_set) { Pair<V> endpoints = graph.getEndpoints(e); int v1_id = id.indexOf(endpoints.getFirst()) + 1; int v2_id = id.indexOf(endpoints.getSecond()) + 1; float weight = nev.transform(e).floatValue(); writer.write(v1_id + " " + v2_id + " " + weight); writer.newLine(); } writer.close(); }
From source file:chibi.gemmaanalysis.cli.deprecated.BioSequenceCleanupCli.java
/** * @param bioSequences/*ww w . ja v a2 s.com*/ */ private void processSequences(Collection<BioSequence> bioSequences) { // /////////////////////////////// // First stage: fix biosequences that lack database entries, when there is one for another essentially // identical sequence (and the name is the same as the accession) for (BioSequence sequence : bioSequences) { Collection<BioSequence> reps = bss.findByName(sequence.getName()); if (reps.size() == 1) continue; reps = bss.thaw(reps); // pass 1: find an anchor. BioSequence anchor = null; for (BioSequence possibleAnchor : reps) { if (possibleAnchor.getSequenceDatabaseEntry() != null && possibleAnchor.getSequenceDatabaseEntry() .getAccession().equals(possibleAnchor.getName())) { anchor = possibleAnchor; } } if (anchor == null) continue; reps.remove(anchor); log.info("Examining duplicates of " + anchor); for (BioSequence rep : reps) { if (rep.getSequenceDatabaseEntry() != null) { if (rep.getSequenceDatabaseEntry().getAccession() .equals(anchor.getSequenceDatabaseEntry().getAccession())) { log.warn(anchor + " and " + rep + " have equivalent database entries for accession"); // they might have different names, but we don't care. One of them has to go. } else { log.warn( anchor + " and " + rep + " have distinct database entries for accession: skipping"); continue; } } log.info(sequence + " has a potential replica: " + rep); switchAndDeleteExtra(anchor, rep); } } }
From source file:org.commonjava.sjbi.sant.mapping.AntMappingReader.java
private void removeCommentedEntries(final AntMapping mapping) { if (isComment(mapping.getBuildFile())) { mapping.setBuildFile(null);/* w w w . ja v a2 s .c o m*/ } final Map<BuildPhase, String> phaseMap = mapping.getPhaseMappings(); for (final Map.Entry<BuildPhase, String> entry : new HashMap<BuildPhase, String>(phaseMap).entrySet()) { if (isComment(entry.getValue())) { phaseMap.remove(entry.getKey()); } } mapping.setPhaseMappings(phaseMap); final Collection<AntProjectMetadata> projects = mapping.getProjects(); for (final AntProjectMetadata project : new ArrayList<AntProjectMetadata>(projects)) { boolean remove = false; if (isComment(project.getPom()) || isComment(project.getCoord())) { remove = true; } else { final Map<String, String> artifacts = project.getArtifacts(); for (final Map.Entry<String, String> entry : new HashMap<String, String>(artifacts).entrySet()) { if (isComment(entry.getKey()) || isComment(entry.getValue())) { artifacts.remove(entry.getKey()); } } if (artifacts.isEmpty()) { remove = true; } } if (remove) { projects.remove(project); } } mapping.setProjects(projects); }
From source file:org.zephyrsoft.trackworktime.timer.TimerManager.java
public void deactivateTrackingMethod(TrackingMethod method) { Collection<TrackingMethod> activeMethods = readCurrentlyActiveTrackingMethods(); if (activeMethods.contains(method)) { activeMethods.remove(method); writeCurrentlyActiveTrackingMethods(activeMethods); }/*w ww .j a va 2 s .c o m*/ }
From source file:org.projectforge.core.AbstractBaseDO.java
/** * // w w w . j av a 2 s . c om * @param srcClazz * @param src * @param dest * @param ignoreFields * @return true, if any modifications are detected, otherwise false; */ @SuppressWarnings("unchecked") private static ModificationStatus copyDeclaredFields(final Class<?> srcClazz, final BaseDO<?> src, final BaseDO<?> dest, final String... ignoreFields) { final Field[] fields = srcClazz.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); ModificationStatus modificationStatus = null; for (final Field field : fields) { final String fieldName = field.getName(); if ((ignoreFields != null && ArrayUtils.contains(ignoreFields, fieldName) == true) || accept(field) == false) { continue; } try { final Object srcFieldValue = field.get(src); final Object destFieldValue = field.get(dest); if (field.getType().isPrimitive() == true) { if (ObjectUtils.equals(destFieldValue, srcFieldValue) == false) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } continue; } else if (srcFieldValue == null) { if (field.getType() == String.class) { if (StringUtils.isNotEmpty((String) destFieldValue) == true) { field.set(dest, null); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else if (destFieldValue != null) { field.set(dest, null); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } else { // dest was already null } } else if (srcFieldValue instanceof Collection) { Collection<Object> destColl = (Collection<Object>) destFieldValue; final Collection<Object> srcColl = (Collection<Object>) srcFieldValue; final Collection<Object> toRemove = new ArrayList<Object>(); if (srcColl != null && destColl == null) { if (srcColl instanceof TreeSet) { destColl = new TreeSet<Object>(); } else if (srcColl instanceof HashSet) { destColl = new HashSet<Object>(); } else if (srcColl instanceof List) { destColl = new ArrayList<Object>(); } else if (srcColl instanceof PersistentSet) { destColl = new HashSet<Object>(); } else { log.error("Unsupported collection type: " + srcColl.getClass().getName()); } field.set(dest, destColl); } for (final Object o : destColl) { if (srcColl.contains(o) == false) { toRemove.add(o); } } for (final Object o : toRemove) { if (log.isDebugEnabled() == true) { log.debug("Removing collection entry: " + o); } destColl.remove(o); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } for (final Object srcEntry : srcColl) { if (destColl.contains(srcEntry) == false) { if (log.isDebugEnabled() == true) { log.debug("Adding new collection entry: " + srcEntry); } destColl.add(srcEntry); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } else if (srcEntry instanceof BaseDO) { final PFPersistancyBehavior behavior = field.getAnnotation(PFPersistancyBehavior.class); if (behavior != null && behavior.autoUpdateCollectionEntries() == true) { BaseDO<?> destEntry = null; for (final Object entry : destColl) { if (entry.equals(srcEntry) == true) { destEntry = (BaseDO<?>) entry; break; } } Validate.notNull(destEntry); final ModificationStatus st = destEntry.copyValuesFrom((BaseDO<?>) srcEntry); modificationStatus = getModificationStatus(modificationStatus, st); } } } } else if (srcFieldValue instanceof BaseDO) { final Serializable srcFieldValueId = HibernateUtils.getIdentifier((BaseDO<?>) srcFieldValue); if (srcFieldValueId != null) { if (destFieldValue == null || ObjectUtils.equals(srcFieldValueId, ((BaseDO<?>) destFieldValue).getId()) == false) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else { log.error( "Can't get id though can't copy the BaseDO (see error message above about HHH-3502)."); } } else if (srcFieldValue instanceof java.sql.Date) { if (destFieldValue == null) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } else { final DayHolder srcDay = new DayHolder((Date) srcFieldValue); final DayHolder destDay = new DayHolder((Date) destFieldValue); if (srcDay.isSameDay(destDay) == false) { field.set(dest, srcDay.getSQLDate()); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } } else if (srcFieldValue instanceof Date) { if (destFieldValue == null || ((Date) srcFieldValue).getTime() != ((Date) destFieldValue).getTime()) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else if (srcFieldValue instanceof BigDecimal) { if (destFieldValue == null || ((BigDecimal) srcFieldValue).compareTo((BigDecimal) destFieldValue) != 0) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } else if (ObjectUtils.equals(destFieldValue, srcFieldValue) == false) { field.set(dest, srcFieldValue); modificationStatus = getModificationStatus(modificationStatus, src, fieldName); } } catch (final IllegalAccessException ex) { throw new InternalError("Unexpected IllegalAccessException: " + ex.getMessage()); } } final Class<?> superClazz = srcClazz.getSuperclass(); if (superClazz != null) { final ModificationStatus st = copyDeclaredFields(superClazz, src, dest, ignoreFields); modificationStatus = getModificationStatus(modificationStatus, st); } return modificationStatus; }
From source file:cl.b9.socialNetwork.jung.SNPajekNetWriter.java
/** * Writes <code>graph</code> to <code>w</code>. Labels for vertices may * be supplied by <code>vs</code> (defaults to no labels if null), * edge weights may be specified by <code>nev</code> * (defaults to weights of 1.0 if null), * and vertex locations may be specified by <code>vld</code> (defaults * to no locations if null). //ww w .j av a 2 s . com */ @SuppressWarnings("unchecked") public void save(Graph<V, E> graph, Writer w, Transformer<V, String> vs, Transformer<E, Number> nev, Transformer<V, Point2D> vld, Transformer<V, String> shape) throws IOException { /* * TODO: Changes we might want to make: * - optionally writing out in list form */ BufferedWriter writer = new BufferedWriter(w); if (nev == null) nev = new Transformer<E, Number>() { public Number transform(E e) { return 1; } }; writer.write("*Vertices " + graph.getVertexCount()); writer.newLine(); List<V> id = new ArrayList<V>(graph.getVertices());//Indexer.getIndexer(graph); for (V currentVertex : graph.getVertices()) { // convert from 0-based to 1-based index int v_id = id.indexOf(currentVertex) + 1; writer.write("" + v_id); if (vs != null) { String label = vs.transform(currentVertex); if (label != null) writer.write(" \"" + label + "\""); } if (vld != null) { Point2D location = vld.transform(currentVertex); if (location != null) writer.write(" " + location.getX() + " " + location.getY()); } if (shape != null) { writer.write(" " + shape.transform(currentVertex) + " x_fact 1"); } writer.newLine(); } Collection<E> d_set = new HashSet<E>(); Collection<E> u_set = new HashSet<E>(); boolean directed = graph instanceof DirectedGraph; boolean undirected = graph instanceof UndirectedGraph; // if it's strictly one or the other, no need to create extra sets if (directed) d_set.addAll(graph.getEdges()); if (undirected) u_set.addAll(graph.getEdges()); if (!directed && !undirected) // mixed-mode graph { u_set.addAll(graph.getEdges()); d_set.addAll(graph.getEdges()); for (E e : graph.getEdges()) { if (graph.getEdgeType(e) == EdgeType.UNDIRECTED) { d_set.remove(e); } else { u_set.remove(e); } } } // write out directed edges if (!d_set.isEmpty()) { writer.write("*Arcs"); writer.newLine(); } for (E e : d_set) { int source_id = id.indexOf(graph.getEndpoints(e).getFirst()) + 1; int target_id = id.indexOf(graph.getEndpoints(e).getSecond()) + 1; // float weight = nev.get(e).floatValue(); float weight = nev.transform(e).floatValue(); writer.write(source_id + " " + target_id + " " + weight); writer.newLine(); } // write out undirected edges if (!u_set.isEmpty()) { writer.write("*Edges"); writer.newLine(); } for (E e : u_set) { Pair<V> endpoints = graph.getEndpoints(e); int v1_id = id.indexOf(endpoints.getFirst()) + 1; int v2_id = id.indexOf(endpoints.getSecond()) + 1; // float weight = nev.get(e).floatValue(); float weight = nev.transform(e).floatValue(); writer.write(v1_id + " " + v2_id + " " + weight); writer.newLine(); } writer.close(); }
From source file:org.marketcetera.marketdata.core.provider.AbstractMarketDataProvider.java
@Override public void cancelMarketDataRequest(MarketDataRequestToken inRequestToken) { // TODO re-exploding the request might cause problems if the request itself changed, better to associate the token ID // with a set of atoms Lock cancelLock = marketdataLock.writeLock(); try {// w w w .j a va2 s . c o m cancelLock.lockInterruptibly(); Set<MarketDataRequestAtom> atoms = explodeRequest(inRequestToken.getRequest()); for (MarketDataRequestAtom atom : atoms) { Collection<MarketDataRequestToken> symbolRequests = requestsByAtom.get(atom); if (symbolRequests != null) { symbolRequests.remove(inRequestToken); if (symbolRequests.isEmpty()) { doCancel(atom); } } Collection<MarketDataRequestToken> requests = requestsBySymbol.get(atom.getSymbol()); if (requests != null) { requests.remove(inRequestToken); } Instrument mappedInstrument = instrumentsBySymbol.get(atom.getSymbol()); if (mappedInstrument != null) { Collection<MarketDataRequestToken> instrumentRequests = requestsByInstrument .get(mappedInstrument); if (instrumentRequests != null) { instrumentRequests.remove(inRequestToken); if (instrumentRequests.isEmpty()) { // no more requests for this instrument, which means this instrument will no longer be updated - clear the cache for it cachedMarketdata.remove(mappedInstrument); } } } } } catch (InterruptedException e) { org.marketcetera.marketdata.core.Messages.UNABLE_TO_ACQUIRE_LOCK.error(this); stop(); } finally { cancelLock.unlock(); } }
From source file:de.hybris.platform.acceleratorstorefrontcommons.breadcrumb.impl.SearchBreadcrumbBuilder.java
protected void createBreadcrumbCategoryHierarchyPath(final String categoryCode, final boolean emptyBreadcrumbs, final List<Breadcrumb> breadcrumbs) { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<>(); final Collection<CategoryModel> categoryModels = new ArrayList<>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs.add(getCategoryBreadcrumb(lastCategoryModel, !emptyBreadcrumbs ? LAST_LINK_CLASS : "")); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear();//from w ww .j a va 2 s. c o m categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); }
From source file:uk.ac.ebi.intact.editor.services.curate.experiment.ExperimentEditorService.java
private void initialiseEvidences(IntactExperiment parent, Collection<InteractionEvidence> evidences) { Collection<InteractionEvidence> originalInteractions = new ArrayList<InteractionEvidence>(evidences); InteractionEvidenceCloner cloner = new InteractionEvidenceCloner(); for (InteractionEvidence ev : originalInteractions) { if (ev instanceof IntactInteractionEvidence && !isInteractionEvidenceInitialised((IntactInteractionEvidence) ev)) { InteractionEvidence reloaded = initialiseInteraction(ev, cloner); if (reloaded != ev) { evidences.remove(ev); parent.addInteractionEvidence(reloaded); }/* w w w . ja v a2 s . c om*/ } } }
From source file:org.kitodo.dataaccess.storage.memory.MemoryNode.java
@Override public boolean removeFirstOccurrence(Object object) { Pair<Long, Long> range = range(); if (range == null) { return false; }/* w ww . j av a 2 s .c om*/ for (long i = range.getKey(); i <= range.getValue(); i++) { String current = RDF.toURL(i); Collection<ObjectType> objects = edges.get(current); if (objects.remove(object)) { if (objects.isEmpty()) { edges.remove(current); long pos = i; String next; while (edges.containsKey(next = RDF.toURL(++pos))) { edges.put(current, edges.remove(next)); current = next; } } return true; } } return false; }