Java Code Examples for java.util.NavigableSet#retainAll()
The following examples show how to use
java.util.NavigableSet#retainAll() .
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 File: TreeSubSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 2
Source File: ConcurrentSkipListSubSetTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 File: ConcurrentSkipListSubSetTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 4
Source File: TreeSubSetTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 File: TreeSubSetTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 6
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 7
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 8
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 9
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 10
Source File: BTreeMapSubSetTest.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 11
Source File: BTreeMapSubSetTest.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 12
Source File: BTreeSet2Test.java From scava with Eclipse Public License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 13
Source File: ConcurrentSkipListSubSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testDescendingRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 14
Source File: ConcurrentSkipListSubSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 15
Source File: TreeSubSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { NavigableSet q = populatedSet(SIZE); NavigableSet 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 16
Source File: IntersectionInt.java From opennars with MIT License | 4 votes |
/** * Try to make a new compound from two term. Called by the inference rules. * @param term1 The first component * @param term2 The second component * @return A compound generated or a term it reduced to */ public static Term make(final Term term1, final Term term2) { if ((term1 instanceof SetExt) && (term2 instanceof SetExt)) { // set union final Term[] both = ObjectArrays.concat( ((CompoundTerm) term1).term, ((CompoundTerm) term2).term, Term.class); return SetExt.make(both); } if ((term1 instanceof SetInt) && (term2 instanceof SetInt)) { // set intersection final NavigableSet<Term> set = Term.toSortedSet(((CompoundTerm) term1).term); set.retainAll(((CompoundTerm) term2).asTermList()); //technically this can be used directly if it can be converted to array //but wait until we can verify that NavigableSet.toarray does it or write a helper function like existed previously return SetInt.make(set.toArray(new Term[0])); } final List<Term> se = new ArrayList(); if (term1 instanceof IntersectionInt) { ((CompoundTerm) term1).addTermsTo(se); if (term2 instanceof IntersectionInt) { // (&,(&,P,Q),(&,R,S)) = (&,P,Q,R,S) ((CompoundTerm) term2).addTermsTo(se); } else { // (&,(&,P,Q),R) = (&,P,Q,R) se.add(term2); } } else if (term2 instanceof IntersectionInt) { // (&,R,(&,P,Q)) = (&,P,Q,R) ((CompoundTerm) term2).addTermsTo(se); se.add(term1); } else { se.add(term1); se.add(term2); } return make(se.toArray(new Term[0])); }
Example 17
Source File: IntersectionExt.java From opennars with MIT License | 4 votes |
/** * Try to make a new compound from two term. Called by the inference rules. * @param term1 The first component * @param term2 The first component * @return A compound generated or a term it reduced to */ public static Term make(final Term term1, final Term term2) { if ((term1 instanceof SetInt) && (term2 instanceof SetInt)) { // set union final Term[] both = ObjectArrays.concat( ((CompoundTerm) term1).term, ((CompoundTerm) term2).term, Term.class); return SetInt.make(both); } if ((term1 instanceof SetExt) && (term2 instanceof SetExt)) { // set intersection final NavigableSet<Term> set = Term.toSortedSet(((CompoundTerm) term1).term); set.retainAll(((CompoundTerm) term2).asTermList()); //technically this can be used directly if it can be converted to array //but wait until we can verify that NavigableSet.toarray does it or write a helper function like existed previously return SetExt.make(set.toArray(new Term[0])); } final List<Term> se = new ArrayList(); if (term1 instanceof IntersectionExt) { ((CompoundTerm) term1).addTermsTo(se); if (term2 instanceof IntersectionExt) { // (&,(&,P,Q),(&,R,S)) = (&,P,Q,R,S) ((CompoundTerm) term2).addTermsTo(se); } else { // (&,(&,P,Q),R) = (&,P,Q,R) se.add(term2); } } else if (term2 instanceof IntersectionExt) { // (&,R,(&,P,Q)) = (&,P,Q,R) ((CompoundTerm) term2).addTermsTo(se); se.add(term1); } else { se.add(term1); se.add(term2); } return make(se.toArray(new Term[0])); }
Example 18
Source File: AggregationPipelineQueryNode.java From rya with Apache License 2.0 | votes |
/** * Add a join with an individual {@link StatementPattern} to the pipeline. * @param sp The statement pattern to join with * @return true if the join was successfully added to the pipeline. */ public boolean joinWith(final StatementPattern sp) { Preconditions.checkNotNull(sp); // 1. Determine shared variables and new variables final StatementVarMapping spMap = new StatementVarMapping(sp, varToOriginalName); final NavigableSet<String> sharedVars = new ConcurrentSkipListSet<>(spMap.varNames()); sharedVars.retainAll(assuredBindingNames); // 2. Join on one shared variable final String joinKey = sharedVars.pollFirst(); final String collectionName = collection.getNamespace().getCollectionName(); Bson join; if (joinKey == null) { return false; } else { join = Aggregates.lookup(collectionName, HASHES + "." + joinKey, spMap.hashField(joinKey), JOINED_TRIPLE); } pipeline.add(join); // 3. Unwind the joined triples so each document represents a binding // set (solution) from the base branch and a triple that may match. pipeline.add(Aggregates.unwind("$" + JOINED_TRIPLE)); // 4. (Optional) If there are any shared variables that weren't used as // the join key, project all existing fields plus a new field that // tests the equality of those shared variables. final Document matchOpts = getMatchExpression(sp, JOINED_TRIPLE); if (!sharedVars.isEmpty()) { final List<Bson> eqTests = new LinkedList<>(); for (final String varName : sharedVars) { final String oldField = valueFieldExpr(varName); final String newField = joinFieldExpr(spMap.valueField(varName)); final Bson eqTest = new Document("$eq", Arrays.asList(oldField, newField)); eqTests.add(eqTest); } final Bson eqProjectOpts = Projections.fields( Projections.computed(FIELDS_MATCH, Filters.and(eqTests)), Projections.include(JOINED_TRIPLE, VALUES, HASHES, TYPES, LEVEL, TIMESTAMP)); pipeline.add(Aggregates.project(eqProjectOpts)); matchOpts.put(FIELDS_MATCH, true); } // 5. Filter for solutions whose triples match the joined statement // pattern, and, if applicable, whose additional shared variables // match the current solution. pipeline.add(Aggregates.match(matchOpts)); // 6. Project the results to include variables from the new SP (with // appropriate renaming) and variables referenced only in the base // pipeline (with previous names). final Bson finalProjectOpts = new StatementVarMapping(sp, varToOriginalName) .getProjectExpression(assuredBindingNames, str -> joinFieldExpr(str)); assuredBindingNames.addAll(spMap.varNames()); bindingNames.addAll(spMap.varNames()); pipeline.add(Aggregates.project(finalProjectOpts)); return true; }