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

The following examples show how to use java.util.NavigableMap#clear() . 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: ConcurrentSkipListMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * headMap returns map with keys in requested range
 */
public void testHeadMapContents() {
    ConcurrentSkipListMap map = map5();
    NavigableMap sm = map.headMap(four, false);
    assertTrue(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(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(four, map.firstKey());
}
 
Example 2
Source File: TreeMapTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * headMap returns map with keys in requested range
 */
public void testHeadMapContents() {
    TreeMap map = map5();
    NavigableMap sm = map.headMap(four, false);
    assertTrue(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(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(four, map.firstKey());
}
 
Example 3
Source File: FileLogReader.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void removeStaleKeyFrames() {
    Logger.trace("Removing stale key frames");
    int size = keyFrames.size();
    if (size < KEY_FRAME_BUFFER_MAX_SIZE) {
        Logger.trace("Key frame buffer is not full: " + size + (size == 1 ? " entry" : " entries"));
        return;
    }
    // Try to balance the number of key frames.
    int window = maxTime / KEY_FRAME_BUFFER_MAX_SIZE;
    for (int i = 0; i < maxTime; i += window) {
        NavigableMap<Integer, WorldModel<? extends Entity>> next = keyFrames.subMap(i, false, i + window, true);
        Logger.trace("Window " + i + " -> " + (i + window) + " has " + next.size() + " entries");
        if (next.size() > 1) {
            // Remove all but the last entry in this window
            Map.Entry<Integer, WorldModel<? extends Entity>> last = next.lastEntry();
            next.clear();
            next.put(last.getKey(), last.getValue());
            Logger.trace("Retained entry " + last);
        }
    }
    Logger.trace("New key frame set: " + keyFrames);
}
 
Example 4
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps with same contents are equal
 */
public void testEquals() {
    NavigableMap map1 = map5();
    NavigableMap map2 = map5();
    assertEquals(map1, map2);
    assertEquals(map2, map1);
    map1.clear();
    assertFalse(map1.equals(map2));
    assertFalse(map2.equals(map1));
}
 
Example 5
Source File: TCKZoneRulesProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 6
Source File: BTreeMapNavigable2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void testClearSubmap()
{
	NavigableMap<Integer, String> subMap = map.subMap(7, true, 9, true);
	subMap.clear();
	assertEquals(subMap.size(), 0);
	assertTrue(map.size()==5);
	assertNull(map.get(7));
	assertNull(map.get(8));
	assertNull(map.get(9));
}
 
Example 7
Source File: TCKZoneRulesProvider.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 8
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps with same contents are equal
 */
public void testDescendingEquals() {
    NavigableMap map1 = dmap5();
    NavigableMap map2 = dmap5();
    assertEquals(map1, map2);
    assertEquals(map2, map1);
    map1.clear();
    assertFalse(map1.equals(map2));
    assertFalse(map2.equals(map1));
}
 
Example 9
Source File: MapPoll.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private void selectMaps() {
  // Sorting beforehand, saves future key remaps, as bigger values are placed at the end
  List<MapInfo> sortedDist =
      mapScores.entrySet().stream()
          .sorted(Comparator.comparingDouble(Map.Entry::getValue))
          .map(Map.Entry::getKey)
          .collect(Collectors.toList());

  NavigableMap<Double, MapInfo> cumulativeScores = new TreeMap<>();
  double maxWeight = cummulativeMap(0, sortedDist, cumulativeScores);

  for (int i = 0; i < voteSize; i++) {
    NavigableMap<Double, MapInfo> subMap =
        cumulativeScores.tailMap(Math.random() * maxWeight, true);
    Map.Entry<Double, MapInfo> selected = subMap.pollFirstEntry();

    if (selected == null) break; // No more maps to poll
    votes.put(selected.getValue(), new HashSet<>()); // Add map to votes
    if (votes.size() >= voteSize) break; // Skip replace logic after all maps have been selected

    // Remove map from pool, updating cumulative scores
    double selectedWeight = getWeight(selected.getValue());
    maxWeight -= selectedWeight;

    NavigableMap<Double, MapInfo> temp = new TreeMap<>();
    cummulativeMap(selected.getKey() - selectedWeight, subMap.values(), temp);

    subMap.clear();
    cumulativeScores.putAll(temp);
  }
}
 
Example 10
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Maps with same contents are equal
 */
public void testDescendingEquals() {
    NavigableMap map1 = dmap5();
    NavigableMap map2 = dmap5();
    assertEquals(map1, map2);
    assertEquals(map2, map1);
    map1.clear();
    assertFalse(map1.equals(map2));
    assertFalse(map2.equals(map1));
}
 
Example 11
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Maps with same contents are equal
 */
public void testEquals() {
    NavigableMap map1 = map5();
    NavigableMap map2 = map5();
    assertEquals(map1, map2);
    assertEquals(map2, map1);
    map1.clear();
    assertFalse(map1.equals(map2));
    assertFalse(map2.equals(map1));
}
 
Example 12
Source File: TestZoneRulesProvider.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<String, ZoneRules>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 13
Source File: TCKZoneRulesProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 14
Source File: TCKZoneRulesProvider.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 15
Source File: TCKZoneRulesProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 16
Source File: TCKZoneRulesProvider.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_getVersions_String() {
    NavigableMap<String, ZoneRules> versions = ZoneRulesProvider.getVersions("Europe/London");
    assertTrue(versions.size() >= 1);
    ZoneRules rules = ZoneRulesProvider.getRules("Europe/London", false);
    assertEquals(versions.lastEntry().getValue(), rules);

    NavigableMap<String, ZoneRules> copy = new TreeMap<>(versions);
    versions.clear();
    assertEquals(versions.size(), 0);
    NavigableMap<String, ZoneRules> versions2 = ZoneRulesProvider.getVersions("Europe/London");
    assertEquals(versions2, copy);
}
 
Example 17
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * clear removes all pairs
 */
public void testClear() {
    NavigableMap map = map5();
    map.clear();
    assertEquals(0, map.size());
}
 
Example 18
Source File: TreeSubMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * clear removes all pairs
 */
public void testDescendingClear() {
    NavigableMap map = dmap5();
    map.clear();
    assertEquals(0, map.size());
}
 
Example 19
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * clear removes all pairs
 */
public void testClear() {
    NavigableMap map = map5();
    map.clear();
    assertEquals(0, map.size());
}
 
Example 20
Source File: TreeSubMapTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * clear removes all pairs
 */
public void testDescendingClear() {
    NavigableMap map = dmap5();
    map.clear();
    assertEquals(0, map.size());
}