@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class) public void testheadSetRanges(String description, NavigableSet navigableSet) { NavigableSet subSet = navigableSet.headSet(BigInteger.ONE, true); // same subset subSet.headSet(BigInteger.ONE, true); // slightly smaller NavigableSet ns = subSet.headSet(BigInteger.ONE, false); // slight expansion assertThrowsIAE(() -> { ns.headSet(BigInteger.ONE, true); }, description + ": Expansion should not be allowed"); // much smaller subSet.headSet(isDescending(subSet) ? BigInteger.TEN : BigInteger.ZERO, true); }
/** * descending iterator of descendingKeySet is ordered */ public void testDescendingKeySetDescendingIteratorOrder() { TreeMap map = map5(); NavigableSet s = map.descendingKeySet(); Iterator i = s.descendingIterator(); Integer last = (Integer)i.next(); assertEquals(last, one); int count = 1; while (i.hasNext()) { Integer k = (Integer)i.next(); assertTrue(last.compareTo(k) < 0); last = k; ++count; } assertEquals(5, count); }
public void testNavigableSubSet() { for (List<Integer> contents : SAMPLE_INPUTS) { for (int i = 0; i < 10; i++) { for (int j = i + 1; j < 10; j++) { for (boolean fromInclusive : ImmutableList.of(true, false)) { for (boolean toInclusive : ImmutableList.of(true, false)) { NavigableSet<Integer> filterSubset = filter( createUnfiltered(contents).subSet(i, fromInclusive, j, toInclusive), EVEN); NavigableSet<Integer> subsetFilter = filter(createUnfiltered(contents), EVEN) .subSet(i, fromInclusive, j, toInclusive); assertEquals(filterSubset, subsetFilter); } } } } } }
/** * iterator.remove removes current element */ public void testIteratorRemove() { final NavigableSet q = set0(); 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()); }
/** * iterator iterates through all elements */ public void testDescendingIterator() { NavigableSet q = populatedSet(SIZE); int i = 0; Iterator it = q.iterator(); while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } assertEquals(i, SIZE); }
/** * Get the column from the specified family with the specified qualifier. * <p> * Overrides previous calls to addFamily for this family. * @param family family name * @param qualifier column qualifier * @return this */ public Scan addColumn(byte [] family, byte [] qualifier) { NavigableSet<byte []> set = familyMap.get(family); if(set == null) { set = new TreeSet<byte []>(Bytes.BYTES_COMPARATOR); } if (qualifier == null) { qualifier = HConstants.EMPTY_BYTE_ARRAY; } set.add(qualifier); familyMap.put(family, set); return this; }
/** * containsAll(c) is true when c contains a subset of elements */ public void testContainsAll() { NavigableSet q = populatedSet(SIZE); NavigableSet p = set0(); for (int i = 0; i < SIZE; ++i) { assertTrue(q.containsAll(p)); assertFalse(p.containsAll(q)); p.add(new Integer(i)); } assertTrue(p.containsAll(q)); }
public void testPollFirst() { for (List<Integer> contents : SAMPLE_INPUTS) { NavigableSet<Integer> filtered = filter(createUnfiltered(contents), EVEN); NavigableSet<Integer> unfiltered = createUnfiltered(filtered); assertEquals(unfiltered.pollFirst(), filtered.pollFirst()); assertEquals(unfiltered, filtered); } }
/** * A sensible definition of {@link #subSet(Object, boolean, Object, boolean)} in terms of the * {@code headSet} and {@code tailSet} methods. In many cases, you may wish to override * {@link #subSet(Object, boolean, Object, boolean)} to forward to this implementation. */ @Beta protected NavigableSet<E> standardSubSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return tailSet(fromElement, fromInclusive).headSet(toElement, toInclusive); }
private static void demoNavigableSetRemove(NavigableSet<Integer> set) { System.out.println("set: " + set); try { for (int i : set) { System.out.println(i); System.out.println("Calling set.remove(2)..."); set.remove(2); } } catch (Exception ex) { System.out.println(ex.getClass().getName()); } System.out.println("set: " + set); }
private void removeMonitors(long limit) { Consumer<ClusterAddress> doRemove = node -> { if (DEBUG) { log.debug("Stopped monitoring [node={}]", node); } monitors.remove(node); }; NavigableSet<ClusterAddress> allSorted = new TreeSet<>(allNodes); // Nodes that are before the local node in the ring. List<ClusterAddress> toRemove = allSorted.headSet(localNode, false).stream() .filter(monitors::containsKey) .limit(limit) .collect(toList()); toRemove.forEach(doRemove); long removeMore = limit - toRemove.size(); if (removeMore > 0) { allSorted.tailSet(localNode, false).stream() .filter(monitors::containsKey) .limit(limit) .forEach(doRemove); } }
@Test public void testToSubchartsDeep() throws IOException { final String input = "wordpress/charts/mariadb/charts/frobnicator/templates/foo.yaml"; final NavigableSet<String> output = StreamOrientedChartLoader.toSubcharts(input); assertNotNull(output); assertEquals(2, output.size()); assertEquals("wordpress/charts/mariadb", output.first()); assertEquals("wordpress/charts/mariadb/charts/frobnicator", output.last()); }
@SuppressWarnings("unchecked") protected <E> NavigableSet<E> create() { TestSet<E> inner = new TestSet<E>(new TreeSet<E>((Comparator<E>) Ordering.natural().nullsFirst()), null); NavigableSet<E> outer = Synchronized.navigableSet(inner, null); inner.mutex = outer; return outer; }
@Override public NavigableSet<E> subSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return unmodifiableNavigableSet(delegate.subSet( fromElement, fromInclusive, toElement, toInclusive)); }
private Cell getNextRow(final Cell key, final NavigableSet<Cell> set) { Cell result = null; SortedSet<Cell> tail = key == null? set: set.tailSet(key); // Iterate until we fall into the next row; i.e. move off current row for (Cell cell: tail) { if (comparator.compareRows(cell, key) <= 0) continue; // Note: Not suppressing deletes or expired cells. Needs to be handled // by higher up functions. result = cell; break; } return result; }
/** * Add of non-Comparable throws CCE */ public void testDescendingAddNonComparable() { NavigableSet q = dset0(); try { q.add(new Object()); q.add(new Object()); shouldThrow(); } catch (ClassCastException success) {} }
/** * Returns a new set of first 5 negative ints. */ private static NavigableSet dset5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); q.add(m1); q.add(m2); q.add(m3); q.add(m4); q.add(m5); NavigableSet s = q.descendingSet(); assertEquals(5, s.size()); return s; }
/** * toString contains toStrings of elements */ public void testDescendingToString() { NavigableSet q = populatedSet(SIZE); String s = q.toString(); for (int i = 0; i < SIZE; ++i) { assertTrue(s.contains(String.valueOf(i))); } }
@Override public NavigableSet<E> subSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return forward.subSet(toElement, toInclusive, fromElement, fromInclusive).descendingSet(); }
@Override public synchronized NavigableSet<CacheSpan> addListener(String key, Listener listener) { ArrayList<Listener> listenersForKey = listeners.get(key); if (listenersForKey == null) { listenersForKey = new ArrayList<>(); listeners.put(key, listenersForKey); } listenersForKey.add(listener); return getCachedSpans(key); }
/** * ceiling returns next element */ public void testDescendingCeiling() { NavigableSet q = dset5(); Object e1 = q.ceiling(m3); assertEquals(m3, e1); Object e2 = q.ceiling(zero); assertEquals(m1, e2); Object e3 = q.ceiling(m5); assertEquals(m5, e3); Object e4 = q.ceiling(m6); assertNull(e4); }
private static <T> NavigableSet<T> wrap(final NavigableSet<T> delegate) { return new ForwardingNavigableSet<T>() { @Override protected NavigableSet<T> delegate() { return delegate; } }; }
@Override public NavigableSet<E> descendingSet() { synchronized (mutex) { if (descendingSet == null) { NavigableSet<E> dS = Synchronized.navigableSet(delegate().descendingSet(), mutex); descendingSet = dS; return dS; } return descendingSet; } }
/** * @param filename * @param blocks * @return A JSON String of <code>filename</code> and counts of <code>blocks</code> * @throws JsonGenerationException * @throws JsonMappingException * @throws IOException */ public static String toJSON(final String filename, final NavigableSet<CachedBlock> blocks) throws JsonGenerationException, JsonMappingException, IOException { CachedBlockCountsPerFile counts = new CachedBlockCountsPerFile(filename); for (CachedBlock cb: blocks) { counts.count++; counts.size += cb.getSize(); BlockType bt = cb.getBlockType(); if (bt != null && bt.isData()) { counts.countData++; counts.sizeData += cb.getSize(); } } return MAPPER.writeValueAsString(counts); }
/** * clear removes all elements */ public void testClear() { NavigableSet q = populatedSet(SIZE); q.clear(); assertTrue(q.isEmpty()); assertEquals(0, q.size()); q.add(new Integer(1)); assertFalse(q.isEmpty()); q.clear(); assertTrue(q.isEmpty()); }
/** * add(null) throws NPE */ public void testAddNull() { NavigableSet q = set0(); try { q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
/** * Compile the details beyond the scope of getFingerprint (row, columns, * timestamps, etc.) into a Map along with the fingerprinted information. * Useful for debugging, logging, and administration tools. * @param maxCols a limit on the number of columns output prior to truncation * @return Map */ @Override public Map<String, Object> toMap(int maxCols) { // start with the fingerpring map and build on top of it Map<String, Object> map = getFingerprint(); // map from families to column list replaces fingerprint's list of families Map<String, List<String>> familyColumns = new HashMap<String, List<String>>(); map.put("families", familyColumns); // add scalar information first map.put("startRow", Bytes.toStringBinary(this.startRow)); map.put("stopRow", Bytes.toStringBinary(this.stopRow)); map.put("maxVersions", this.maxVersions); map.put("batch", this.batch); map.put("caching", this.caching); map.put("maxResultSize", this.maxResultSize); map.put("cacheBlocks", this.cacheBlocks); map.put("loadColumnFamiliesOnDemand", this.loadColumnFamiliesOnDemand); List<Long> timeRange = new ArrayList<Long>(); timeRange.add(this.tr.getMin()); timeRange.add(this.tr.getMax()); map.put("timeRange", timeRange); int colCount = 0; // iterate through affected families and list out up to maxCols columns for (Map.Entry<byte [], NavigableSet<byte[]>> entry : this.familyMap.entrySet()) { List<String> columns = new ArrayList<String>(); familyColumns.put(Bytes.toStringBinary(entry.getKey()), columns); if(entry.getValue() == null) { colCount++; --maxCols; columns.add("ALL"); } else { colCount += entry.getValue().size(); if (maxCols <= 0) { continue; } for (byte [] column : entry.getValue()) { if (--maxCols <= 0) { continue; } columns.add(Bytes.toStringBinary(column)); } } } map.put("totalColumns", colCount); if (this.filter != null) { map.put("filter", this.filter.toString()); } // add the id if set if (getId() != null) { map.put("id", getId()); } return map; }
public NavigableSet<K> navigableKeySet() { KeySet<K> ks = keySet; return (ks != null) ? ks : (keySet = new KeySet<K>(this)); }
DescendingSet(NavigableSet<E> forward) { this.forward = forward; }
@Override public NavigableSet<E> descendingSet() { return forward; }
@Override public NavigableSet<K> navigableKeySet() { return new StandardNavigableKeySet(); }
@Override public NavigableSet<E> headSet(E toElement, boolean inclusive) { return decorated().headSet(toElement, inclusive); }
@Value.ReverseOrder public abstract NavigableSet<String> reverse();
@Value.ReverseOrder NavigableSet<Integer> navs();
public void testTailSet_E_B() { NavigableSet<String> set = create(); NavigableSet<String> tailSet = set.tailSet("a", true); assertTrue(tailSet instanceof SynchronizedNavigableSet); assertSame(set, ((SynchronizedNavigableSet<String>) tailSet).mutex); }
SynchronizedNavigableSet(NavigableSet<E> delegate, @Nullable Object mutex) { super(delegate, mutex); }
@Override public NavigableSet<E> descendingSet() { return delegate().descendingSet(); }
@Override public NavigableSet<K> keySet() { return (NavigableSet<K>) super.keySet(); }
@Override NavigableSet<Integer> filter( NavigableSet<Integer> elements, Predicate<? super Integer> predicate) { return Sets.filter(elements, predicate); }
@Override public NavigableSet<E> descendingSet() { return Sets.filter(unfiltered().descendingSet(), predicate); }