public void testTailMapClearThrough() { final SortedMap<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } int oldSize = map.size(); if (map.size() < 2 || !supportsClear) { return; } Iterator<Entry<K, V>> iterator = map.entrySet().iterator(); iterator.next(); // advance Entry<K, V> secondEntry = iterator.next(); K key = secondEntry.getKey(); SortedMap<K, V> subMap = map.tailMap(key); int subMapSize = subMap.size(); subMap.clear(); assertEquals(map.size(), oldSize - subMapSize); assertTrue(subMap.isEmpty()); } }
public void testTailMapWriteThrough() { final SortedMap<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } if (map.size() < 2 || !supportsPut) { return; } Iterator<Entry<K, V>> iterator = map.entrySet().iterator(); Entry<K, V> firstEntry = iterator.next(); Entry<K, V> secondEntry = iterator.next(); K key = secondEntry.getKey(); SortedMap<K, V> subMap = map.tailMap(key); V value = getValueNotInPopulatedMap(); subMap.put(key, value); assertEquals(secondEntry.getValue(), value); assertEquals(map.get(key), value); try { subMap.put(firstEntry.getKey(), value); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
if(other.typeDefVersions != null) return false; } else if(typeDefVersions.size() != other.typeDefVersions.size()) { return false; } else { for(Map.Entry<Integer, String> versionedSchema: typeDefVersions.entrySet()) { Schema schema = Schema.parse(versionedSchema.getValue()); String otherTypeDef = other.typeDefVersions.get(versionedSchema.getKey()); if(otherTypeDef == null) {
public ConsistentRoutingStrategy(HashFunction hash, Collection<Node> nodes, int numReplicas) { this.numReplicas = numReplicas; this.hash = hash; // sanity check that we don't assign the same partition to multiple nodes SortedMap<Integer, Node> m = new TreeMap<Integer, Node>(); for(Node n: nodes) { for(Integer partition: n.getPartitionIds()) { if(m.containsKey(partition)) throw new IllegalArgumentException("Duplicate partition id " + partition + " in cluster configuration " + nodes); m.put(partition, n); } } this.partitionToNode = new Node[m.size()]; for(int i = 0; i < m.size(); i++) { if(!m.containsKey(i)) throw new IllegalArgumentException("Invalid configuration, missing partition " + i); this.partitionToNode[i] = m.get(i); } }
for (Path entry : stream) { if (Files.isRegularFile(entry.resolve(GameManifest.DEFAULT_FILE_NAME))) { savedGamePaths.put(Files.getLastModifiedTime(entry.resolve(GameManifest.DEFAULT_FILE_NAME)), entry); List<GameInfo> result = Lists.newArrayListWithCapacity(savedGamePaths.size()); for (Map.Entry<FileTime, Path> world : savedGamePaths.entrySet()) { Path gameManifest = world.getValue().resolve(GameManifest.DEFAULT_FILE_NAME); try { if (!info.getTitle().isEmpty()) { Date date = new Date(world.getKey().toMillis()); result.add(new GameInfo(info, date, world.getValue()));
/** * Update topology history with new topology snapshots. * * @param topVer Topology version. * @param top Topology snapshot. * @return Copy of updated topology history. */ @Nullable private Map<Long, Collection<ClusterNode>> updateTopologyHistory(long topVer, Collection<ClusterNode> top) { synchronized (mux) { if (topHist.containsKey(topVer)) return null; topHist.put(topVer, top); while (topHist.size() > spi.topHistSize) topHist.remove(topHist.firstKey()); if (log.isDebugEnabled()) log.debug("Added topology snapshot to history, topVer=" + topVer + ", historySize=" + topHist.size()); return new TreeMap<>(topHist); } }
void applyFont(TreeMap<Integer, CTRPrElt> formats, int startIndex, int endIndex, CTRPrElt fmt) { // delete format runs that fit between startIndex and endIndex // runs intersecting startIndex and endIndex remain int runStartIdx = 0; for (Iterator<Integer> it = formats.keySet().iterator(); it.hasNext();) { int runEndIdx = it.next(); if (runStartIdx >= startIndex && runEndIdx < endIndex) { it.remove(); } runStartIdx = runEndIdx; } if(startIndex > 0 && !formats.containsKey(startIndex)) { // If there's a format that starts later in the string, make it start now for(Map.Entry<Integer, CTRPrElt> entry : formats.entrySet()) { if(entry.getKey() > startIndex) { formats.put(startIndex, entry.getValue()); break; } } } formats.put(endIndex, fmt); // assure that the range [startIndex, endIndex] consists if a single run // there can be two or three runs depending whether startIndex or endIndex // intersected existing format runs SortedMap<Integer, CTRPrElt> sub = formats.subMap(startIndex, endIndex); while(sub.size() > 1) sub.remove(sub.lastKey()); }
@Override public List<HotspottyDataStreamMetadataNamedColumnValue<?>> getRowColumns(HotspottyDataStreamMetadataRow row, ColumnSelection columns) { byte[] bytes = row.persistToBytes(); RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), columns).get(bytes); if (rowResult == null) { return ImmutableList.of(); } else { List<HotspottyDataStreamMetadataNamedColumnValue<?>> ret = Lists.newArrayListWithCapacity(rowResult.getColumns().size()); for (Entry<byte[], byte[]> e : rowResult.getColumns().entrySet()) { ret.add(shortNameToHydrator.get(PtBytes.toString(e.getKey())).hydrateFromBytes(e.getValue())); } return ret; } }
private static int getStartValue(RocksDB db, ColumnFamilyHandle handler) { int startValue = 0; SortedMap<Integer, Integer> values = new TreeMap<Integer, Integer>(); RocksIterator itr = db.newIterator(handler); itr.seekToFirst(); while(itr.isValid()) { Integer key = Integer.valueOf(new String(itr.key())); Integer value = Integer.valueOf(new String(itr.value())); values.put(key, value); itr.next(); } LOG.info("Load previous db: size={}, values={}", values.size(), values); if (!values.isEmpty()) { Integer key = values.lastKey(); startValue = values.get(key); startValue++; } LOG.info("Start value={}", startValue); return startValue; }
public void testTailMapRemoveThrough() { final SortedMap<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } int oldSize = map.size(); if (map.size() < 2 || !supportsRemove) { return; } Iterator<Entry<K, V>> iterator = map.entrySet().iterator(); Entry<K, V> firstEntry = iterator.next(); Entry<K, V> secondEntry = iterator.next(); K key = secondEntry.getKey(); SortedMap<K, V> subMap = map.tailMap(key); subMap.remove(key); assertNull(subMap.remove(firstEntry.getKey())); assertEquals(map.size(), oldSize - 1); assertFalse(map.containsKey(key)); assertEquals(subMap.size(), oldSize - 2); }
continue; Method old = getterMap.put(OpenTypeUtil.decapitalize(propertyName), method); if (old != null) { final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() final int nitems = getterMap.size(); final OpenType[] openTypes = new OpenType[nitems]; int i = 0; for (Map.Entry<String, Method> entry : getterMap.entrySet()) { itemNames[i] = entry.getKey(); final Method getter = entry.getValue(); getters[i] = getter; final Type retType = getter.getGenericReturnType();
private OperationsNodeInfo getNearest(byte[] hash) { if (circle.isEmpty()) { return null; } if (circle.size() == 1) { return circle.get(circle.firstKey()); } SortedMap<byte[], OperationsNodeInfo> tailMap = circle.tailMap(hash); hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); return circle.get(hash); }
/** * Returns a boolean indicating whether a segment can be removed from the journal prior to the given index. * * @param index the index from which to remove segments * @return indicates whether a segment can be removed from the journal */ public boolean isCompactable(long index) { Map.Entry<Long, JournalSegment<E>> segmentEntry = segments.floorEntry(index); return segmentEntry != null && segments.headMap(segmentEntry.getValue().index()).size() > 0; }
@Override public List<DataStreamMetadataNamedColumnValue<?>> getRowColumns(DataStreamMetadataRow row, ColumnSelection columns) { byte[] bytes = row.persistToBytes(); RowResult<byte[]> rowResult = t.getRows(tableRef, ImmutableSet.of(bytes), columns).get(bytes); if (rowResult == null) { return ImmutableList.of(); } else { List<DataStreamMetadataNamedColumnValue<?>> ret = Lists.newArrayListWithCapacity(rowResult.getColumns().size()); for (Entry<byte[], byte[]> e : rowResult.getColumns().entrySet()) { ret.add(shortNameToHydrator.get(PtBytes.toString(e.getKey())).hydrateFromBytes(e.getValue())); } return ret; } }
bucketData.put(i, new ArrayList<>()); bucketData.get(i).add(value); break; for (int i = 0; i < bucketData.size() - 1; i++) { System.out.printf("%8s - %8s : (%5s values) %s\n", keyFormatter.apply(buckets.get(i)), keyFormatter.apply(buckets.get(i + 1)), bucketData.get(i).size(), valueFormatter.apply(bucketData.get(i))); for (int i = 0; i < bucketData.size(); i++) { System.out.printf("%19s : (%5s values) %s\n", keyFormatter.apply(buckets.get(i)),
public ImmutableTreeMap(SortedMap<K, V> sortedMap) { if (sortedMap == null) { throw new NullPointerException("Cannot convert null to ImmutableSortedMap"); } this.comparator = sortedMap.comparator(); K[] keysCopy = (K[]) new Object[sortedMap.size()]; V[] valuesCopy = (V[]) new Object[sortedMap.size()]; int index = 0; for (Entry<K, V> entry : sortedMap.entrySet()) { keysCopy[index] = entry.getKey(); valuesCopy[index] = entry.getValue(); index++; } this.keys = keysCopy; this.values = valuesCopy; }