public Test testsForCheckedNavigableMap() { return SortedMapTestSuiteBuilder.using( new TestStringSortedMapGenerator() { @Override protected NavigableMap<String, String> create(Entry<String, String>[] entries) { NavigableMap<String, String> map = populate(new TreeMap<String, String>(), entries); return Collections.checkedNavigableMap(map, String.class, String.class); } }) .named("checkedNavigableMap/TreeMap, natural") .withFeatures( MapFeature.GENERAL_PURPOSE, MapFeature.ALLOWS_NULL_VALUES, MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION, MapFeature.RESTRICTS_KEYS, MapFeature.RESTRICTS_VALUES, CollectionFeature.KNOWN_ORDER, CollectionFeature.SUPPORTS_ITERATOR_REMOVE, CollectionFeature.SERIALIZABLE, CollectionSize.ANY) .suppressing(suppressForCheckedNavigableMap()) .createTestSuite(); }
@Override public List<HRegionLocation> locateRegions(final TableName tableName, final boolean useCache, final boolean offlined) throws IOException { NavigableMap<HRegionInfo, ServerName> regions = MetaScanner.allTableRegions(this, tableName); final List<HRegionLocation> locations = new ArrayList<HRegionLocation>(); for (HRegionInfo regionInfo : regions.keySet()) { RegionLocations list = locateRegion(tableName, regionInfo.getStartKey(), useCache, true); if (list != null) { for (HRegionLocation loc : list.getRegionLocations()) { if (loc != null) { locations.add(loc); } } } } return locations; }
public void testSubMapContents2() { NavigableMap map = map5(); SortedMap sm = map.subMap(two, three); assertEquals(1, sm.size()); assertEquals(two, sm.firstKey()); assertEquals(two, sm.lastKey()); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertFalse(sm.containsKey(three)); assertFalse(sm.containsKey(four)); assertFalse(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); assertFalse(i.hasNext()); Iterator j = sm.keySet().iterator(); j.next(); j.remove(); assertFalse(map.containsKey(two)); assertEquals(4, map.size()); assertEquals(0, sm.size()); assertTrue(sm.isEmpty()); assertSame(sm.remove(three), null); assertEquals(4, map.size()); }
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class) public void testTailMapRanges(String description, NavigableMap navigableMap) { NavigableMap subMap = navigableMap.tailMap(BigInteger.ONE, true); // same subset subMap.tailMap(BigInteger.ONE, true); // slightly smaller NavigableMap ns = subMap.tailMap(BigInteger.ONE, false); // slight exapansion assertThrows(() -> { ns.tailMap(BigInteger.ONE, true); }, IllegalArgumentException.class, description + ": Expansion should not be allowed"); // much smaller subMap.tailMap(isDescending(subMap) ? BigInteger.ZERO : BigInteger.TEN, false); }
public static int getProtocolVersion() { if(WurstClient.INSTANCE.options.mc112x_compatibility == 2) return 340; else if(WurstClient.INSTANCE.options.mc112x_compatibility == 1) return 338; NavigableMap<Integer, String> protocols = WMinecraft.PROTOCOLS; // use default if using Wurst-Bot if(WurstBot.isEnabled()) return protocols.lastKey(); ServerData server = lastServer.getServerData(); // use default if ping failed if(!server.pinged || server.pingToServer < 0) return protocols.lastKey(); // use default if server protocol is not supported if(!protocols.containsKey(server.version)) return protocols.lastKey(); // use server protocol return server.version; }
public Test testsForUnmodifiableNavigableMap() { return MapTestSuiteBuilder.using( new TestStringSortedMapGenerator() { @Override protected NavigableMap<String, String> create(Entry<String, String>[] entries) { return Collections.unmodifiableNavigableMap(populate(new TreeMap<>(), entries)); } }) .named("unmodifiableNavigableMap/TreeMap, natural") .withFeatures( MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE, CollectionSize.ANY) .suppressing(suppressForUnmodifiableNavigableMap()) .createTestSuite(); }
public void testRangesByUpperBound() { for (Range<Integer> range1 : QUERY_RANGES) { for (Range<Integer> range2 : QUERY_RANGES) { TreeRangeSet<Integer> rangeSet = TreeRangeSet.create(); rangeSet.add(range1); rangeSet.add(range2); NavigableMap<Cut<Integer>, Range<Integer>> expectedRangesByUpperBound = Maps.newTreeMap(); for (Range<Integer> range : rangeSet.asRanges()) { expectedRangesByUpperBound.put(range.upperBound, range); } testNavigationAgainstExpected(expectedRangesByUpperBound, new TreeRangeSet.RangesByUpperBound<Integer>(rangeSet.rangesByLowerBound), CUTS_TO_TEST); } } }
public void testDescendingKeySet() { NavigableMap<String, Integer> map = create(); NavigableSet<String> descendingKeySet = map.descendingKeySet(); assertTrue(descendingKeySet instanceof SynchronizedNavigableSet); assertSame( mutex, ((SynchronizedNavigableSet<String>) descendingKeySet).mutex); }
public void testTailMap_K_B() { NavigableMap<String, Integer> map = create(); NavigableMap<String, Integer> subMap = map.tailMap("a", true); assertTrue(subMap instanceof SynchronizedNavigableMap); assertSame( mutex, ((SynchronizedNavigableMap<String, Integer>) subMap).mutex); }
public static <K, V, W extends Iterable<V>> Entry<K, V> pollFirstEntry(NavigableMap<K, W> map) { Entry<K, V> result = null; Iterator<Entry<K, W>> itE = map.entrySet().iterator(); // For robustness, remove entry valueX sets while(itE.hasNext()) { Entry<K, W> e = itE.next(); K k = e.getKey(); Iterable<V> vs = e.getValue(); Iterator<V> itV = vs.iterator(); if(itV.hasNext()) { V v = itV.next(); itV.remove(); if(!itV.hasNext()) { itE.remove(); } result = new SimpleEntry<>(k, v); break; } else { itE.remove(); continue; } } return result; }
/** * put(null,x) throws NPE */ public void testDescendingPut1_NullPointerException() { NavigableMap c = dmap5(); try { c.put(null, "whatever"); shouldThrow(); } catch (NullPointerException success) {} }
/** * Tests that the containsAll method returns {@code false}. */ @Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class) public void testContainsAll(String description, NavigableMap<?,?> navigableMap) { TreeMap treeMap = new TreeMap(); treeMap.put("1", 1); treeMap.put("2", 2); treeMap.put("3", 3); assertFalse(navigableMap.equals(treeMap), "Should not contain any elements."); }
@Override public String toString() { StringBuilder sb = new StringBuilder() .append("SizeConfigStrategy{groupedMap=") .append(groupedMap) .append(", sortedSizes=("); for (Map.Entry<Bitmap.Config, NavigableMap<Integer, Integer>> entry : sortedSizes.entrySet()) { sb.append(entry.getKey()).append('[').append(entry.getValue()).append("], "); } if (!sortedSizes.isEmpty()) { sb.replace(sb.length() - 2, sb.length(), ""); } return sb.append(")}").toString(); }
/** * @return Map of StoreFiles by column family */ private NavigableMap<byte[], List<Path>> getStoreFiles() { NavigableMap<byte[], List<Path>> allStoreFiles = new TreeMap<byte[], List<Path>>(Bytes.BYTES_COMPARATOR); for (Store store : getStores()) { Collection<StoreFile> storeFiles = store.getStorefiles(); if (storeFiles == null) continue; List<Path> storeFileNames = new ArrayList<Path>(); for (StoreFile storeFile : storeFiles) { storeFileNames.add(storeFile.getPath()); } allStoreFiles.put(store.getFamily().getName(), storeFileNames); } return allStoreFiles; }
private void decrementArrayOfSize(int size, Class<?> arrayClass) { NavigableMap<Integer, Integer> sizes = getSizesForAdapter(arrayClass); Integer current = sizes.get(size); if (current == null) { throw new NullPointerException( "Tried to decrement empty size" + ", size: " + size + ", this: " + this); } if (current == 1) { sizes.remove(size); } else { sizes.put(size, current - 1); } }
@GwtIncompatible // NavigableMap public void testNavigableMapTransformEntries() { NavigableMap<String, String> map = ImmutableSortedMap.of("a", "4", "b", "9"); EntryTransformer<String, String, String> concat = new EntryTransformer<String, String, String>() { @Override public String transformEntry(String key, String value) { return key + value; } }; NavigableMap<String, String> transformed = transformEntries(map, concat); assertEquals(ImmutableSortedMap.of("a", "a4", "b", "b9"), transformed); }
/** * Tests that contains requires Comparable */ @Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class) public void testContainsRequiresComparable(String description, NavigableMap<?,?> navigableMap) { assertThrows(() -> { navigableMap.containsKey(new Object()); }, ClassCastException.class, description + ": Compareable should be required"); }
public void testNavigableKeySet() { NavigableMap<String, Integer> map = create(); NavigableSet<String> navigableKeySet = map.navigableKeySet(); assertTrue(navigableKeySet instanceof SynchronizedNavigableSet); assertSame( mutex, ((SynchronizedNavigableSet<String>) navigableKeySet).mutex); }
private SafeTreeMap(NavigableMap<K, V> delegate) { this.delegate = delegate; if (delegate == null) { throw new NullPointerException(); } for (K k : keySet()) { checkValid(k); } }
/** * higherEntry returns next entry. */ public void testHigherEntry() { NavigableMap map = map5(); Map.Entry e1 = map.higherEntry(three); assertEquals(four, e1.getKey()); Map.Entry e2 = map.higherEntry(zero); assertEquals(one, e2.getKey()); Map.Entry e3 = map.higherEntry(five); assertNull(e3); Map.Entry e4 = map.higherEntry(six); assertNull(e4); }
public NavigableMap<K,V> descendingMap() { NavigableMap<K,V> mv = descendingMapView; return (mv != null) ? mv : (descendingMapView = new DescendingSubMap<>(m, fromStart, lo, loInclusive, toEnd, hi, hiInclusive)); }
@SuppressWarnings({"rawtypes", "unchecked"}) public void testForwarding() { new ForwardingWrapperTester() .testForwarding(NavigableMap.class, new Function<NavigableMap, NavigableMap>() { @Override public NavigableMap apply(NavigableMap delegate) { return wrap(delegate); } }); }
public void testEquals() { NavigableMap<Integer, String> map1 = ImmutableSortedMap.of(1, "one"); NavigableMap<Integer, String> map2 = ImmutableSortedMap.of(2, "two"); new EqualsTester() .addEqualityGroup(map1, wrap(map1), wrap(map1)) .addEqualityGroup(map2, wrap(map2)) .testEquals(); }
public NavigableMap<K,V> headMap(K toKey, boolean inclusive) { if (!inRange(toKey, inclusive)) throw new IllegalArgumentException("toKey out of range"); return new AscendingSubMap<>(m, fromStart, lo, loInclusive, false, toKey, inclusive); }
/** * subMap returns map with keys in requested range */ public void testSubMapContents() { ConcurrentSkipListMap map = map5(); NavigableMap sm = map.subMap(two, true, four, false); assertEquals(two, sm.firstKey()); assertEquals(three, sm.lastKey()); assertEquals(2, sm.size()); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertFalse(sm.containsKey(four)); assertFalse(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); assertFalse(i.hasNext()); Iterator r = sm.descendingKeySet().iterator(); k = (Integer)(r.next()); assertEquals(three, k); k = (Integer)(r.next()); assertEquals(two, k); assertFalse(r.hasNext()); Iterator j = sm.keySet().iterator(); j.next(); j.remove(); assertFalse(map.containsKey(two)); assertEquals(4, map.size()); assertEquals(1, sm.size()); assertEquals(three, sm.firstKey()); assertEquals(three, sm.lastKey()); assertEquals("C", sm.remove(three)); assertTrue(sm.isEmpty()); assertEquals(3, map.size()); }
/** * lowerEntry returns preceding entry. */ public void testLowerEntry() { NavigableMap map = map5(); Map.Entry e1 = map.lowerEntry(three); assertEquals(two, e1.getKey()); Map.Entry e2 = map.lowerEntry(six); assertEquals(five, e2.getKey()); Map.Entry e3 = map.lowerEntry(one); assertNull(e3); Map.Entry e4 = map.lowerEntry(zero); assertNull(e4); }
@Override public NavigableMap<K, V> descendingMap() { synchronized (mutex) { if (descendingMap == null) { return descendingMap = navigableMap(delegate().descendingMap(), mutex); } return descendingMap; } }
@Override protected <K, V> NavigableMap<K, V> create() { @SuppressWarnings("unchecked") NavigableMap<K, V> innermost = new SafeTreeMap<K, V>( (Comparator<? super K>) Ordering.natural().nullsFirst()); TestMap<K, V> inner = new TestMap<K, V>(innermost, mutex); NavigableMap<K, V> outer = Synchronized.navigableMap(inner, mutex); return outer; }
@Override public NavigableMap<Cut<C>, Range<C>> subMap( Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) { return subMap(Range.range( fromKey, BoundType.forBoolean(fromInclusive), toKey, BoundType.forBoolean(toInclusive))); }
@Test public void testDelete_CheckTimestampUpdated() throws IOException { TableName tableName = TableName.valueOf(name.getMethodName()); byte[] row1 = Bytes.toBytes("row1"); byte[] col1 = Bytes.toBytes("col1"); byte[] col2 = Bytes.toBytes("col2"); byte[] col3 = Bytes.toBytes("col3"); // Setting up region String method = this.getName(); this.region = initHRegion(tableName, method, CONF, fam1); try { // Building checkerList List<Cell> kvs = new ArrayList<Cell>(); kvs.add(new KeyValue(row1, fam1, col1, null)); kvs.add(new KeyValue(row1, fam1, col2, null)); kvs.add(new KeyValue(row1, fam1, col3, null)); NavigableMap<byte[], List<Cell>> deleteMap = new TreeMap<byte[], List<Cell>>( Bytes.BYTES_COMPARATOR); deleteMap.put(fam1, kvs); region.delete(deleteMap, Durability.SYNC_WAL); // extract the key values out the memstore: // This is kinda hacky, but better than nothing... long now = System.currentTimeMillis(); DefaultMemStore memstore = (DefaultMemStore) ((HStore) region.getStore(fam1)).memstore; Cell firstCell = memstore.cellSet.first(); assertTrue(firstCell.getTimestamp() <= now); now = firstCell.getTimestamp(); for (Cell cell : memstore.cellSet) { assertTrue(cell.getTimestamp() <= now); now = cell.getTimestamp(); } } finally { HRegion.closeHRegion(this.region); this.region = null; } }
private void transformResultAndAddToList(Result result, List<MDPoint> found) { NavigableMap<byte[], byte[]> map = result.getFamilyMap(MDHBaseAdmin.SECONDARY_FAMILY); if (map == null) return; for (Entry<byte[], byte[]> entry : map.entrySet()) { MDPoint p = toPoint(entry.getKey(), entry.getValue()); found.add(p); } }
/** * putAll adds all key-value pairs from the given map */ public void testDescendingPutAll() { NavigableMap empty = dmap0(); NavigableMap map = dmap5(); empty.putAll(map); assertEquals(5, empty.size()); assertTrue(empty.containsKey(m1)); assertTrue(empty.containsKey(m2)); assertTrue(empty.containsKey(m3)); assertTrue(empty.containsKey(m4)); assertTrue(empty.containsKey(m5)); }
/** * A deserialized/reserialized map equals original */ public void testSerialization() throws Exception { NavigableMap x = map5(); NavigableMap y = serialClone(x); assertNotSame(x, y); assertEquals(x.size(), y.size()); assertEquals(x.toString(), y.toString()); assertEquals(x, y); assertEquals(y, x); }
@Test public void testHBaseGroupScanAssignmentNoAfinity() throws Exception { NavigableMap<HRegionInfo,ServerName> regionsToScan = Maps.newTreeMap(); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[0], splits[1]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[1], splits[2]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[2], splits[3]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[3], splits[4]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[4], splits[5]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[5], splits[6]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[6], splits[7]), SERVER_X); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[7], splits[0]), SERVER_X); final List<DrillbitEndpoint> endpoints = Lists.newArrayList(); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_A).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_B).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_C).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_D).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_E).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_F).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_G).setControlPort(1234).build()); endpoints.add(DrillbitEndpoint.newBuilder().setAddress(HOST_H).setControlPort(1234).build()); HBaseGroupScan scan = new HBaseGroupScan(); scan.setRegionsToScan(regionsToScan); scan.setHBaseScanSpec(new HBaseScanSpec(TABLE_NAME_STR, splits[0], splits[0], null)); scan.applyAssignments(endpoints); int i = 0; assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'A' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'B' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'C' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'D' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'E' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'F' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'G' assertEquals(1, scan.getSpecificScan(i++).getRegionScanSpecList().size()); // 'H' testParallelizationWidth(scan, i); }
private NavigableMap<Cut<C>, Range<C>> subMap(Range<Cut<C>> subWindow) { if (!complementLowerBoundWindow.isConnected(subWindow)) { return ImmutableSortedMap.of(); } else { subWindow = subWindow.intersection(complementLowerBoundWindow); return new ComplementRangesByLowerBound<C>(positiveRangesByLowerBound, subWindow); } }
/** * isEmpty is true of empty map and false for non-empty */ public void testIsEmpty() { NavigableMap empty = map0(); NavigableMap map = map5(); assertTrue(empty.isEmpty()); assertFalse(map.isEmpty()); }
/** * Resets the contents of navigableMap to have entries a, c, for the * navigation tests. */ @SuppressWarnings("unchecked") // Needed to stop Eclipse whining private void resetWithHole() { Entry<K, V>[] entries = new Entry[] {a, c}; super.resetMap(entries); navigableMap = (NavigableMap<K, V>) getMap(); }
@Override public NavigableMap<K, V> headMap(K toKey, boolean inclusive) { return new SafeTreeMap<K, V>(delegate.headMap(checkValid(toKey), inclusive)); }
@Override public NavigableMap<K, V> subMap( K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { return forward().subMap(toKey, toInclusive, fromKey, fromInclusive).descendingMap(); }