Java Code Examples for java.util.TreeSet#retainAll()
The following examples show how to use
java.util.TreeSet#retainAll() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Drop-seq File: SequenceDictionaryIntersection.java License: MIT License | 6 votes |
/** * Compare sequence dictionaries of 2 objects containing SDs * @param o1 * @param description1 For including in messages * @param o2 * @param description2 For including in messages */ public SequenceDictionaryIntersection(final Object o1, final String description1, final Object o2, final String description2) { final ObjectType type1 = getObjectType(o1, description1); final ObjectType type2 = getObjectType(o2, description2); this.description1 = (description1 != null? description1: type1.name()); this.description2 = (description2 != null? description2: type2.name());; sequences1 = Collections.unmodifiableSet(getSequenceSet(getSequenceDictionary(o1, type1))); sequences2 = Collections.unmodifiableSet(getSequenceSet(getSequenceDictionary(o2, type2))); final TreeSet<String> intersection = new TreeSet<>(sequences1); intersection.retainAll(sequences2); this.intersection = Collections.unmodifiableSet(intersection); final TreeSet<String> onlyIn1 = new TreeSet<>(sequences1); onlyIn1.removeAll(sequences2); this.sequencesOnlyIn1 = Collections.unmodifiableSet(onlyIn1); final TreeSet<String> onlyIn2 = new TreeSet<>(sequences2); onlyIn1.removeAll(sequences1); this.sequencesOnlyIn2 = Collections.unmodifiableSet(onlyIn2); }
Example 2
Source Project: openjdk-jdk9 File: TreeSetTest.java License: GNU General Public License v2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { TreeSet q = populatedSet(SIZE); TreeSet p = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { boolean changed = q.retainAll(p); if (i == 0) assertFalse(changed); else assertTrue(changed); assertTrue(q.containsAll(p)); assertEquals(SIZE - i, q.size()); p.pollFirst(); } }
Example 3
Source Project: ck File: LCOM.java License: Apache License 2.0 | 6 votes |
@Override public void setResult(CKClassResult result) { /* * LCOM = |P| - |Q| if |P| - |Q| > 0 * where * P = set of all empty set intersections * Q = set of all nonempty set intersections */ // extracted from https://github.com/dspinellis/ckjm int lcom = 0; for (int i = 0; i < methods.size(); i++) for (int j = i + 1; j < methods.size(); j++) { TreeSet<?> intersection = (TreeSet<?>)methods.get(i).clone(); intersection.retainAll(methods.get(j)); if (intersection.size() == 0) lcom++; else lcom--; } result.setLcom(lcom > 0 ? lcom : 0); }
Example 4
Source Project: j2objc File: TreeSetTest.java License: Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { TreeSet q = populatedSet(SIZE); TreeSet p = populatedSet(SIZE); for (int i = 0; i < SIZE; ++i) { boolean changed = q.retainAll(p); if (i == 0) assertFalse(changed); else assertTrue(changed); assertTrue(q.containsAll(p)); assertEquals(SIZE - i, q.size()); p.pollFirst(); } }
Example 5
Source Project: archiva File: Maven2RepositoryMerger.java License: Apache License 2.0 | 6 votes |
@Override public List<ArtifactMetadata> getConflictingArtifacts( MetadataRepository metadataRepository, String sourceRepo, String targetRepo ) throws RepositoryMergerException { try(RepositorySession session = repositorySessionFactory.createSession()) { TreeSet<ArtifactMetadata> targetArtifacts = new TreeSet<>(META_COMPARATOR); targetArtifacts.addAll(metadataRepository.getArtifacts(session , targetRepo )); TreeSet<ArtifactMetadata> sourceArtifacts = new TreeSet<>(META_COMPARATOR); sourceArtifacts.addAll(metadataRepository.getArtifacts(session , sourceRepo )); sourceArtifacts.retainAll(targetArtifacts); return new ArrayList<>(sourceArtifacts); } catch ( MetadataRepositoryException e ) { throw new RepositoryMergerException( e.getMessage(), e ); } }
Example 6
Source Project: Heracles File: Dataset.java License: GNU General Public License v3.0 | 5 votes |
/** * * @param textualUnit * @param spanType * @return A new <code>TreeSet</code> with the selected Spans */ public TreeSet<Span> getSpans(Span textualUnit, String spanType){ TreeSet<Span> spans = new TreeSet<>(); spans.addAll(getSpans(textualUnit)); spans.retainAll(getSpans(spanType)); return spans; }
Example 7
Source Project: UVA File: 12504 Updating a Dictionary.java License: GNU General Public License v3.0 | 5 votes |
public static void main (String [] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int testCaseCount=Integer.parseInt(br.readLine()); for (int i=0;i<testCaseCount;i++) { TreeMap<String,String> oldDict=new TreeMap<>(); TreeMap<String,String> newDict=new TreeMap<>(); updateDict(oldDict,br.readLine()); updateDict(newDict,br.readLine()); TreeSet<String> newKeys=new TreeSet<>(); newKeys.addAll(newDict.keySet()); newKeys.removeAll(oldDict.keySet()); TreeSet<String> removedKeys=new TreeSet<>(); removedKeys.addAll(oldDict.keySet()); removedKeys.removeAll(newDict.keySet()); TreeSet<String> changedKeys=new TreeSet<>(); changedKeys.addAll(oldDict.keySet()); changedKeys.retainAll(newDict.keySet()); String [] changedKeysAry=changedKeys.toArray(new String [changedKeys.size()]); for (String s : changedKeysAry) if (oldDict.get(s).equals(newDict.get(s))) changedKeys.remove(s); StringBuilder sb=new StringBuilder(); sb.append(toStr("+",newKeys)); sb.append(toStr("-",removedKeys)); sb.append(toStr("*",changedKeys)); if (sb.length()==0) sb.append("No changes\n"); System.out.println(sb.toString()); } }
Example 8
Source Project: picard File: PerTilePerCycleFileUtil.java License: MIT License | 5 votes |
private Set<Integer> removeNonExistentCycles(final int[] cycles) { final TreeSet<Integer> inputCyclesSet = new TreeSet<Integer>(); for (final Integer inputCycle : cycles) { inputCyclesSet.add(inputCycle); } inputCyclesSet.retainAll(detectedCycles); return inputCyclesSet; }