Java Code Examples for java.util.NavigableSet#add()
The following examples show how to use
java.util.NavigableSet#add() .
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: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * iterator.remove removes current element */ public void testDescendingIteratorRemove() { final NavigableSet q = dset0(); q.add(new Integer(2)); q.add(new Integer(1)); q.add(new Integer(3)); Iterator it = q.iterator(); it.next(); it.remove(); it = q.iterator(); assertEquals(it.next(), new Integer(2)); assertEquals(it.next(), new Integer(3)); assertFalse(it.hasNext()); }
Example 2
Source File: ConcurrentSkipListSubSetTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * iterator.remove removes current element */ public void testDescendingIteratorRemove() { final NavigableSet q = dset0(); q.add(new Integer(2)); q.add(new Integer(1)); q.add(new Integer(3)); Iterator it = q.iterator(); it.next(); it.remove(); it = q.iterator(); assertEquals(it.next(), new Integer(2)); assertEquals(it.next(), new Integer(3)); assertFalse(it.hasNext()); }
Example 3
Source File: CollectionsTest.java From j2objc with Apache License 2.0 | 6 votes |
public void test_checkedNavigableSet() { NavigableSet set = Collections.checkedNavigableSet(new TreeSet<>(), String.class); check_navigableSet(set, Arrays.asList(), "absent element"); set.add("element 1"); set.add("element 2"); List<String> elementsInOrder = Arrays.asList("element 1", "element 2"); check_navigableSet(set, elementsInOrder, "absent element"); assertEquals(set, new HashSet<>(elementsInOrder)); assertEquals(new HashSet<>(elementsInOrder), set); assertEquals(2, set.size()); assertTrue(set.contains("element 1")); assertTrue(set.contains("element 2")); assertFalse(set.contains("absent element")); }
Example 4
Source File: StringTrimmingConverterTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testTrimming() throws IOException { final NavigableSet<String> tags = new TreeSet<>(); tags.add(""); tags.add(" tag"); tags.add("\tTaggy McTagface\t"); final Integration original = new Integration.Builder() .id("test") .name(" some-name\t").description("") .tags(tags) .build(); final String source = JsonUtils.writer().writeValueAsString(original); final Integration created = JsonUtils.reader().forType(Integration.class).readValue(source); assertThat(created.getName()).isEqualTo("some-name"); assertThat(created.getDescription()).isNotPresent(); assertThat(created.getTags()).containsExactly("Taggy McTagface", "tag"); }
Example 5
Source File: Chapter07Concurrency02.java From Java-9-Cookbook with MIT License | 6 votes |
private static void demoNavigableSetAdd(NavigableSet<Integer> set) { System.out.println("set: " + set); try { int m = set.stream().max(Comparator.naturalOrder()).get() + 1; for (int i : set) { System.out.println(i); System.out.println("Calling set.add(" + m + ")"); set.add(m++); if (m > 6) { break; } } } catch (Exception ex) { System.out.println(ex.getClass().getName()); } System.out.println("set: " + set); }
Example 6
Source File: SampleSourceImportItem.java From alfresco-bulk-import with Apache License 2.0 | 6 votes |
private final static NavigableSet<SampleSourceImportItemVersion> synthesiseVersions(final String name, final boolean isDirectory, final int numVersions) { NavigableSet<SampleSourceImportItemVersion> result = new TreeSet<>(); // Add at least one version result.add(new SampleSourceImportItemVersion(name, isDirectory, BigDecimal.ONE)); if (!isDirectory && numVersions > 1) { for (int i = 1; i < numVersions; i++) { result.add(new SampleSourceImportItemVersion(name, isDirectory, BigDecimal.valueOf(i + 1))); } } return(result); }
Example 7
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * add(null) throws NPE */ public void testAddNull() { try { NavigableSet q = set0(); q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
Example 8
Source File: BTreeMapSubSetTest.java From scava with Eclipse Public License 2.0 | 5 votes |
/** * containsAll(c) is true when c contains a subset of elements */ public void testDescendingContainsAll() { NavigableSet q = populatedSet(SIZE); NavigableSet p = dset0(); for (int i = 0; i < SIZE; ++i) { assertTrue(q.containsAll(p)); assertFalse(p.containsAll(q)); p.add(new Integer(i)); } assertTrue(p.containsAll(q)); }
Example 9
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * containsAll(c) is true when c contains a subset of elements */ public void testDescendingContainsAll() { NavigableSet q = populatedSet(SIZE); NavigableSet p = dset0(); for (int i = 0; i < SIZE; ++i) { assertTrue(q.containsAll(p)); assertFalse(p.containsAll(q)); p.add(new Integer(i)); } assertTrue(p.containsAll(q)); }
Example 10
Source File: DatabaseValueTest.java From claudb with MIT License | 5 votes |
@Test(expected = UnsupportedOperationException.class) public void testSortedSetUnmodifiable() { DatabaseValue value = zset(score(1.0, safeString("a")), score(2.0, safeString("b")), score(3.0, safeString("c"))); NavigableSet<Map.Entry<Double, SafeString>> sortedSet = value.getSortedSet(); sortedSet.add(score(1.0, safeString("d"))); }
Example 11
Source File: BTreeMapSubSetTest.java From scava with Eclipse Public License 2.0 | 5 votes |
/** * add(null) throws NPE */ public void testAddNull() { try { NavigableSet q = set0(); q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
Example 12
Source File: BTreeSet2Test.java From scava with Eclipse Public License 2.0 | 5 votes |
/** * Returns a new set of first 5 ints. */ private NavigableSet set5() { NavigableSet q = newNavigableSet(); assertTrue(q.isEmpty()); q.add(one); q.add(two); q.add(three); q.add(four); q.add(five); assertEquals(5, q.size()); return q; }
Example 13
Source File: TestStoreScanner.java From hbase with Apache License 2.0 | 5 votes |
NavigableSet<byte[]> getCols(String ...strCols) { NavigableSet<byte[]> cols = new TreeSet<>(Bytes.BYTES_COMPARATOR); for (String col : strCols) { byte[] bytes = Bytes.toBytes(col); cols.add(bytes); } return cols; }
Example 14
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Add of non-Comparable throws CCE */ public void testDescendingAddNonComparable() { try { NavigableSet q = dset0(); q.add(new Object()); q.add(new Object()); q.add(new Object()); shouldThrow(); } catch (ClassCastException success) {} }
Example 15
Source File: ColumnProjectionFilter.java From phoenix with Apache License 2.0 | 5 votes |
public void addTrackedColumn(ImmutableBytesPtr cf, ImmutableBytesPtr cq) { NavigableSet<ImmutableBytesPtr> columns = columnsTracker.get(cf); if (columns == null) { columns = new TreeSet<>(); columnsTracker.put(cf, columns); } columns.add(cq); }
Example 16
Source File: ConcurrentSkipListSubSetJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Add of non-Comparable throws CCE */ public void testAddNonComparable() { try { NavigableSet q = set0(); q.add(new Object()); q.add(new Object()); q.add(new Object()); shouldThrow(); } catch (ClassCastException success) {} }
Example 17
Source File: TreeSubSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * add(null) throws NPE */ public void testAddNull() { NavigableSet q = set0(); try { q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
Example 18
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
void put(NavigableSet<Integer> set, int element, BitSet bs) { if (set.add(element)) bs.set(element); }
Example 19
Source File: CollectionsUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenSetCreatedInDB_whenMultipleElementsAdded_checkOnlyOneExists() { DB db = DBMaker.memoryDB().make(); NavigableSet<String> set = db. treeSet("mySet") .serializer(Serializer.STRING) .createOrOpen(); String myString = "Baeldung!"; set.add(myString); set.add(myString); assertEquals(1, set.size()); db.close(); }
Example 20
Source File: GrammarConstraintProvider.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * Computing the lower bound for a given feature is equivalent to the shortest path problem in the * corresponding automaton graph. Dijkstra's algorithm solves this in quadratic time to the number * of nodes. */ private int computeLowerBound(int featureId) { ISemState currentNode = nfa.getStart(); final ISemState stopNode = nfa.getStop(); final Map<ISemState, DijkstraNode> idAndDistance = Maps.newHashMap(); idAndDistance.put(currentNode, new DijkstraNode()); // The unvisited nodes are sorted by their tentative distance. // Nodes with equal distance still have to be separated, which is achieved with the id value. NavigableSet<ISemState> unvisited = new TreeSet<>(Comparator.comparing((s) -> { return idAndDistance.get(s).distance; }).thenComparing((s) -> { return idAndDistance.get(s).id; })); int nextStateId = 1; do { int currentDistance = idAndDistance.get(currentNode).distance; if (currentNode == stopNode) { // We have reached the stop node and thus know the shortest path from start to stop. return currentDistance; } for (ISemState follower : currentNode.getFollowers()) { DijkstraNode fdn = idAndDistance.get(follower); // The cost of proceeding to this follower is 1 iff it has the correct feature id. int increment = follower.getFeatureID() == featureId ? 1 : 0; if (fdn == null) { // We haven't reached this node before. Assign a new id and distance and mark as unvisited. fdn = new DijkstraNode(); fdn.id = nextStateId++; fdn.distance = currentDistance + increment; idAndDistance.put(follower, fdn); unvisited.add(follower); } else { // This follower node has already been reached. fdn.distance = Math.min(fdn.distance, currentDistance + increment); if (unvisited.remove(follower)) { // The position of the follower in the sorted set must be updated. unvisited.add(follower); } } } unvisited.remove(currentNode); // Choose the unvisited node with the lowest tentative distance. currentNode = unvisited.pollFirst(); } while (currentNode != null); // If we get to this point, the stop state is not reachable from the start. throw new AssertionError("Stop state is not reachable."); }