Java Code Examples for java.util.NavigableMap#keySet()

The following examples show how to use java.util.NavigableMap#keySet() . 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: IndexSegmentTest.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Gets some IDs for deleting. Picks alternate IDs from {@code referenceIndex} and randomly generates
 * {@code outOfSegmentIdCount} ids.
 * @param referenceIndex the index entries to pick for delete from.
 * @param outOfSegmentIdCount the number of ids to be generated that are not in {@code referenceIndex}.
 * @return a {@link Set} of IDs to create delete entries for.
 */
private Set<MockId> getIdsToDelete(NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex,
    int outOfSegmentIdCount) {
  Set<MockId> idsToDelete = new HashSet<>();
  // return every alternate id in the map
  boolean include = true;
  for (MockId id : referenceIndex.keySet()) {
    if (include) {
      idsToDelete.add(id);
    }
    include = !include;
  }
  // generate some ids for delete
  idsToDelete.addAll(generateIds(referenceIndex, outOfSegmentIdCount));
  return idsToDelete;
}
 
Example 2
Source File: MockHTable.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: AtomPositionMapTest.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Tests with no insertion codes.
 * @throws StructureException
 * @throws IOException
 */
@Test
public void testEasy() throws IOException, StructureException { // no insertion codes
	// Straightforward case. Density for residues 25-777 (743 residues)
	String pdbId = "1w0p";
	int length = 93;
	ResidueNumber start = new ResidueNumber("A", 25, null);
	ResidueNumber end = new ResidueNumber("A", 117, null);
	AtomPositionMap map = new AtomPositionMap(cache.getAtoms(pdbId));
	NavigableMap<ResidueNumber,Integer> navMap = map.getNavMap();
	for (ResidueNumber n : navMap.keySet()) {
		assertEquals("An element is missing", map.getPosition(n).intValue(), navMap.get(n).intValue());
	}
	int realLength = map.getLength(start, end);
	assertEquals("Real atom length is wrong", length, realLength);
}
 
Example 4
Source File: BaseVersionManager.java    From Hive2Hive with MIT License 6 votes vote down vote up
protected NavigableMap<Number160, Set<Number160>> buildDigest(Map<PeerAddress, DigestResult> rawDigest) {
	NavigableMap<Number160, Set<Number160>> digestMap = new TreeMap<Number160, Set<Number160>>();
	if (rawDigest == null) {
		return digestMap;
	}
	for (PeerAddress peerAddress : rawDigest.keySet()) {
		NavigableMap<Number640, Collection<Number160>> tmp = rawDigest.get(peerAddress).keyDigest();
		if (tmp == null || tmp.isEmpty()) {
			// ignore this peer
		} else {
			for (Number640 key : tmp.keySet()) {
				for (Number160 bKey : tmp.get(key)) {
					if (!digestMap.containsKey(key.versionKey())) {
						digestMap.put(key.versionKey(), new HashSet<Number160>());
					}
					digestMap.get(key.versionKey()).add(bKey);
				}
			}
		}
	}
	return digestMap;
}
 
Example 5
Source File: MockHTable.java    From metron with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source File: MockHTable.java    From kylin with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: IndexSegmentTest.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Gets some IDs for ttl update. Picks the first half of ids from {@code referenceIndex} and also randomly generates
 * {@code outOfSegmentIdCount} ids.
 * @param referenceIndex the index entries to pick for ttl update from.
 * @param outOfSegmentIdCount the number of ids to be generated that are not in {@code referenceIndex}.
 * @return a {@link Set} of IDs to create ttl update entries for.
 */
private Set<MockId> getIdsToTtlUpdate(NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex,
    int outOfSegmentIdCount) {
  Set<MockId> idsToTtlUpdate = new HashSet<>();
  // return the first half of ids in the map
  int needed = referenceIndex.size() / 2;
  int current = 0;
  for (MockId id : referenceIndex.keySet()) {
    if (current >= needed) {
      break;
    }
    idsToTtlUpdate.add(id);
    current++;
  }
  // generate some ids for ttl update
  idsToTtlUpdate.addAll(generateIds(referenceIndex, outOfSegmentIdCount));
  return idsToTtlUpdate;
}
 
Example 8
Source File: AtomPositionMapTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests with insertion codes.
 * @throws StructureException
 * @throws IOException
 */
@Test
public void testInsertionCodes() throws IOException, StructureException {
	String pdbId = "1qdm";
	// has 2 insertion code regions, lettered P and S, as well as disordered regions:
	// 6P-26P,2-163,169-247,1S-37S,65S-104S,248-338
	// Len:21,  162,     79,    37,      40,     91 = 430

	AtomPositionMap map = new AtomPositionMap(cache.getAtoms(pdbId));
	NavigableMap<ResidueNumber,Integer> navMap = map.getNavMap();

	for (ResidueNumber n : navMap.keySet()) {
		assertEquals("An element is missing", map.getPosition(n).intValue(), navMap.get(n).intValue());
	}

	int length1 = 60; // 2+37+21
	int length2 = 132;// 2+37+40+53
	ResidueNumber start = new ResidueNumber("A", 246, null);
	ResidueNumber mid = new ResidueNumber("A", 85, 'S');
	ResidueNumber end = new ResidueNumber("A", 300, null);
	int realLength1 = map.getLength(start, mid);
	assertEquals("Real atom length is wrong", length1, realLength1);
	int realLength2 = map.getLength(start, end);
	assertEquals("Real atom length is wrong", length2, realLength2);

	int realLength = map.getLength(new ResidueNumber("A",6,'P'),new ResidueNumber("A",338,null));
	assertEquals("Full length wrong",430,realLength);
}
 
Example 9
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Long> findExpiredTables(long startTime) {
    Long currentTableKey = prepMap.floorKey(startTime);
    NavigableMap<Long, Map<Integer, PreparedStatement>> expiredTempMap =
            prepMap.subMap(0L, false, currentTableKey, true);
    if(log.isDebugEnabled()) {
        log.debug(String.format("Returning expired keys from %d to %d, in total %d items",
                expiredTempMap.firstEntry().getKey(),
                expiredTempMap.lastEntry().getKey(),
                expiredTempMap.size())); // No idea why debugf throws compiler issues
    }
    return expiredTempMap.keySet();
}
 
Example 10
Source File: TestVisibilityLabelsWithCustomVisLabService.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 11
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * keySet.toArray returns contains all keys
 */
public void testDescendingAscendingKeySetToArray() {
    NavigableMap map = dmap5();
    Set s = map.keySet();
    Object[] ar = s.toArray();
    assertTrue(s.containsAll(Arrays.asList(ar)));
    assertEquals(5, ar.length);
    ar[0] = m10;
    assertFalse(s.containsAll(Arrays.asList(ar)));
}
 
Example 12
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * keySet is ordered
 */
public void testDescendingKeySetOrder() {
    NavigableMap map = dmap5();
    Set s = map.keySet();
    Iterator i = s.iterator();
    Integer last = (Integer)i.next();
    assertEquals(last, m1);
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
    }
}
 
Example 13
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * keySet returns a Set containing all the keys
 */
public void testDescendingKeySet() {
    NavigableMap map = dmap5();
    Set s = map.keySet();
    assertEquals(5, s.size());
    assertTrue(s.contains(m1));
    assertTrue(s.contains(m2));
    assertTrue(s.contains(m3));
    assertTrue(s.contains(m4));
    assertTrue(s.contains(m5));
}
 
Example 14
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * keySet returns a Set containing all the keys
 */
public void testKeySet() {
    NavigableMap map = map5();
    Set s = map.keySet();
    assertEquals(5, s.size());
    assertTrue(s.contains(one));
    assertTrue(s.contains(two));
    assertTrue(s.contains(three));
    assertTrue(s.contains(four));
    assertTrue(s.contains(five));
}
 
Example 15
Source File: CollectionsTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_synchronizedNavigableMap_keySet() {
    NavigableMap<String, Integer> map = synchronizedNavigableMap(
            new TreeMap<>(createMap("key3", 3, "key1", 1, "key4", 4, "key2", 2)));
    // Note: keySet() returns a Collections$UnmodifiableSet (not instanceof NavigableSet)
    Set<String> set = map.keySet();
    check_orderedSet(set, Arrays.asList("key1", "key2", "key3", "key4"));
}
 
Example 16
Source File: BaseFT.java    From aliyun-tablestore-java-sdk with Apache License 2.0 5 votes vote down vote up
public static void checkColumns(
		NavigableMap<String, NavigableMap<Long, ColumnValue>> expect,
		NavigableMap<String, NavigableMap<Long, ColumnValue>> actual) {
    assertEquals(expect.size(), actual.size());
    for (Map.Entry<String, NavigableMap<Long, ColumnValue>> entry : expect.entrySet()) {
    	NavigableMap<Long, ColumnValue> expectValueList = entry.getValue();
    	NavigableMap<Long, ColumnValue> actualValueList = actual.get(entry.getKey());
        assertEquals(expectValueList.size(), actualValueList.size());
        for (Long ts : expectValueList.keySet()) {
            assertEquals(expectValueList.get(ts), actualValueList.get(ts));
        }
    }
}
 
Example 17
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * keySet.toArray returns contains all keys
 */
public void testDescendingAscendingKeySetToArray() {
    NavigableMap map = dmap5();
    Set s = map.keySet();
    Object[] ar = s.toArray();
    assertTrue(s.containsAll(Arrays.asList(ar)));
    assertEquals(5, ar.length);
    ar[0] = m10;
    assertFalse(s.containsAll(Arrays.asList(ar)));
}
 
Example 18
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * keySet is ordered
 */
public void testDescendingKeySetOrder() {
    NavigableMap map = dmap5();
    Set s = map.keySet();
    Iterator i = s.iterator();
    Integer last = (Integer)i.next();
    assertEquals(last, m1);
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
    }
}
 
Example 19
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * keySet returns a Set containing all the keys
 */
public void testDescendingKeySet() {
    NavigableMap map = dmap5();
    Set s = map.keySet();
    assertEquals(5, s.size());
    assertTrue(s.contains(m1));
    assertTrue(s.contains(m2));
    assertTrue(s.contains(m3));
    assertTrue(s.contains(m4));
    assertTrue(s.contains(m5));
}
 
Example 20
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * keySet is ordered
 */
public void testKeySetOrder() {
    NavigableMap map = map5();
    Set s = map.keySet();
    Iterator i = s.iterator();
    Integer last = (Integer)i.next();
    assertEquals(last, one);
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) < 0);
        last = k;
    }
}