/** @return keys (all caches partitions) */ public Set<GroupPartitionId> keySet() { return readMap.keySet(); }
/** * Returns an Iterator on the elements of this {@code TreeSet}. * * @return an Iterator on the elements of this {@code TreeSet}. * @see Iterator */ @Override public Iterator<E> iterator() { return backingMap.keySet().iterator(); }
int getCurrentSize() { int currentSize = 0; for (Class<?> type : sortedSizes.keySet()) { for (Integer size : sortedSizes.get(type).keySet()) { ArrayAdapterInterface<?> adapter = getAdapterFromType(type); currentSize += size * sortedSizes.get(type).get(size) * adapter.getElementSizeInBytes(); } } return currentSize; }
/** * @return Collection of checkpoint timestamps. */ public Collection<Long> checkpoints(boolean descending) { if (descending) return histMap.descendingKeySet(); return histMap.keySet(); }
private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeObject(backingMap.comparator()); int size = backingMap.size(); stream.writeInt(size); if (size > 0) { Iterator<E> it = backingMap.keySet().iterator(); while (it.hasNext()) { stream.writeObject(it.next()); } } }
private ArrayList<ExecutorDetails> getSortedExecs(HashSet<String> spreadComps, Map<String, Map<String, Integer>> constraintMatrix, Map<String, Set<ExecutorDetails>> compToExecs) { ArrayList<ExecutorDetails> retList = new ArrayList<>(); //find number of constraints per component //Key->Comp Value-># of constraints Map<String, Integer> compConstraintCountMap = new HashMap<>(); constraintMatrix.forEach((comp, subMatrix) -> { int count = subMatrix.values().stream().mapToInt(Number::intValue).sum(); //check component is declared for spreading if (spreadComps.contains(comp)) { count++; } compConstraintCountMap.put(comp, count); }); //Sort comps by number of constraints NavigableMap<String, Integer> sortedCompConstraintCountMap = sortByValues(compConstraintCountMap); //sort executors based on component constraints for (String comp : sortedCompConstraintCountMap.keySet()) { retList.addAll(compToExecs.get(comp)); } return retList; }
@Override void dump( Logger logger ) { Map<String,Integer> versions = new HashMap<>(); for ( String tz : ZoneRulesProvider.getAvailableZoneIds() ) { for ( String version : ZoneRulesProvider.getVersions( tz ).keySet() ) { versions.compute( version, ( key, value ) -> value == null ? 1 : (value + 1) ); } } String[] sorted = versions.keySet().toArray( new String[0] ); Arrays.sort( sorted ); for ( String tz : sorted ) { logger.log( " TimeZone version: %s (available for %d zone identifiers)", tz, versions.get( tz ) ); } } },
private static List<KeyValue> toKeyValue(byte[] row, NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowdata, long timestampStart, long timestampEnd, int maxVersions) { List<KeyValue> ret = new ArrayList<KeyValue>(); for (byte[] family : rowdata.keySet()) for (byte[] qualifier : rowdata.get(family).keySet()) { int versionsAdded = 0; for (Map.Entry<Long, byte[]> tsToVal : rowdata.get(family).get(qualifier).descendingMap().entrySet()) { if (versionsAdded++ == maxVersions) break; Long timestamp = tsToVal.getKey(); if (timestamp < timestampStart) continue; if (timestamp > timestampEnd) continue; byte[] value = tsToVal.getValue(); ret.add(new KeyValue(row, family, qualifier, timestamp, value)); } } return ret; }
@Override public void checkAndPreparePut(Put p) throws IOException { region.checkFamilies(p.getFamilyCellMap().keySet(), p.getDurability()); }
public void collectMetadata(JSONObject metadata) { int hits = 0; int count = 0; Set<Object> scrapers = new HashSet<>(); List<String> listKeys = new ArrayList<String>(this.posts.keySet()); int n = listKeys.size(); for (int i = 0; i < n; i++) { Post postMetadata = (Post) this.posts.get(listKeys.get(i)).get("metadata"); hits = hits + Integer.parseInt(String.valueOf(postMetadata.get("hits"))); count = count + Integer.parseInt(String.valueOf(postMetadata.get("count"))); scrapers.add(postMetadata.get("scraper")); } metadata.put("hits", hits); metadata.put("count", count); metadata.put("scraper_count", scrapers.size()); metadata.put("scrapers", scrapers); }
/** * {@inheritDoc} */ @Override public void put(Put put) throws IOException { byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()) { if (columnFamilies.contains(new String(family, StandardCharsets.UTF_8)) == false) { throw new RuntimeException("Not Exists columnFamily : " + new String(family, StandardCharsets.UTF_8)); } NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)) { kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
@Override protected List<String> extractAuths(String user, List<Result> results) { List<String> auths = new ArrayList<>(); for (Result result : results) { if (Bytes.equals(result.getRow(), Bytes.toBytes(user))) { NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(LABELS_TABLE_FAMILY); for (byte[] q : familyMap.keySet()) { auths.add(Bytes.toString(q, 0, q.length)); } } } return auths; } }
@GwtIncompatible // NavigableMap public void testAsMapNavigableSubViewKeySetsDoNotSupportAdd() { NavigableMap<String, Integer> map = Maps.asMap(Sets.<String>newTreeSet(), LENGTH_FUNCTION); try { map.descendingKeySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.subMap("a", true, "z", false).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.tailMap("a", true).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.headMap("r", true).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.headMap("r", false).tailMap("m", true).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } }
/** * Prepare a delete for a row mutation processor * @param delete The passed delete is modified by this method. WARNING! * @throws IOException */ public void prepareDelete(Delete delete) throws IOException { // Check to see if this is a deleteRow insert if(delete.getFamilyCellMap().isEmpty()){ for(byte [] family : this.htableDescriptor.getColumnFamilyNames()){ // Don't eat the timestamp delete.addFamily(family, delete.getTimestamp()); } } else { for(byte [] family : delete.getFamilyCellMap().keySet()) { if(family == null) { throw new NoSuchColumnFamilyException("Empty family is invalid"); } checkFamily(family, delete.getDurability()); } } }
long cols = 0; for (byte[] cf : result.getMap().keySet()) { cols += result.getFamilyMap(cf).size();
@Test public void testPut() throws Exception { byte[] row = Bytes.toBytes("test-row"); // Initialize a result KeyValue[] kvs = new KeyValue[] { new KeyValue(row, Bytes.toBytes("cfa"), Bytes.toBytes("col1"), Bytes.toBytes("cfacol1")), new KeyValue(row, Bytes.toBytes("cfa"), Bytes.toBytes("col2"), Bytes.toBytes("cfacol2")) }; Put expected = new Put(row); for (int i = 0; i < kvs.length; i++) { expected.add(kvs[i]); } PutWritable actual = copy(new PutWritable(expected), new PutWritable()); Assert.assertArrayEquals(expected.getRow(), actual.getPut().getRow()); Assert.assertEquals(expected.getFamilyCellMap().keySet(), actual.getPut().getFamilyCellMap().keySet()); }
@Test public void shouldComputeSortedIndexUpdatesOnTxStateWithAddedNodes() { // GIVEN addNodesToIndex( indexOn_1_1 ).withDefaultStringProperties( 42L ); addNodesToIndex( indexOn_1_1 ).withDefaultStringProperties( 43L ); addNodesToIndex( indexOn_1_1 ).withDefaultStringProperties( 41L ); // WHEN NavigableMap<ValueTuple,? extends LongDiffSets> diffSets = state.getSortedIndexUpdates( indexOn_1_1.schema() ); TreeMap<ValueTuple,LongDiffSets> expected = sortedAddedNodesDiffSets( 42, 41, 43 ); // THEN assertEquals( expected.keySet(), diffSets.keySet() ); for ( final ValueTuple key : expected.keySet() ) { assertEqualDiffSets( expected.get( key ), diffSets.get( key ) ); } }
private void assertEquals(Mutation origin, Mutation clone) { Assert.assertEquals(origin.getFamilyCellMap().size(), clone.getFamilyCellMap().size()); for (byte[] family : origin.getFamilyCellMap().keySet()) { List<Cell> originCells = origin.getCellList(family); List<Cell> cloneCells = clone.getCellList(family); Assert.assertEquals(originCells.size(), cloneCells.size()); for (int i = 0; i != cloneCells.size(); ++i) { Cell originCell = originCells.get(i); Cell cloneCell = cloneCells.get(i); assertTrue(CellUtil.equals(originCell, cloneCell)); assertTrue(CellUtil.matchingValue(originCell, cloneCell)); } } Assert.assertEquals(origin.getAttributesMap().size(), clone.getAttributesMap().size()); for (String name : origin.getAttributesMap().keySet()) { byte[] originValue = origin.getAttributesMap().get(name); byte[] cloneValue = clone.getAttributesMap().get(name); assertTrue(Bytes.equals(originValue, cloneValue)); } Assert.assertEquals(origin.getTimestamp(), clone.getTimestamp()); Assert.assertEquals(origin.getPriority(), clone.getPriority()); if (origin instanceof Append) { assertEquals(((Append)origin).getTimeRange(), ((Append)clone).getTimeRange()); } if (origin instanceof Increment) { assertEquals(((Increment)origin).getTimeRange(), ((Increment)clone).getTimeRange()); } }
@Test public void maps() { JdkMaps maps = new JdkMapsBuilder() .putJust(1, -1) .putJust(2, -2) .putNavs("22", 2) .putNavs("33", 3) .putAllOrds(ImmutableMap.of(2, "2", 1, "1")) .build(); check(maps.navs().keySet()).isOf("33", "22"); check(maps.just().keySet()).isOf(1L, 2L); check(maps.ords().keySet()).isOf(1, 2); }
@Test public void ordering() { OrderAttributeValue value = ImmutableOrderAttributeValue.builder() .addNatural(3, 2, 4, 1) .addReverse("a", "z", "b", "y") .putNavigableMap(2, "2") .putNavigableMap(1, "1") .putReverseMap("a", "a") .putReverseMap("b", "b") .addNaturalMultiset(20, 13, 20) .addReverseMultiset("w", "z", "z") .build(); check(value.natural()).isOf(1, 2, 3, 4); check(value.reverse()).isOf("z", "y", "b", "a"); check(value.navigableMap().keySet()).isOf(1, 2); check(value.reverseMap().keySet()).isOf("b", "a"); check(value.naturalMultiset()).isOf(13, 20, 20); check(value.reverseMultiset()).isOf("z", "z", "w"); }