public void testStandardLastEntry() { NavigableMap<String, Integer> forwarding = new StandardLastEntryForwardingNavigableMap<String, Integer>( new SafeTreeMap<String, Integer>()); assertNull(forwarding.lastEntry()); forwarding.put("b", 2); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); forwarding.put("c", 3); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.put("a", 1); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.remove("c"); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); }
@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; }
public void testStandardLastEntry() { NavigableMap<String, Integer> forwarding = new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>()); assertNull(forwarding.lastEntry()); forwarding.put("b", 2); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); forwarding.put("c", 3); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.put("a", 1); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.remove("c"); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); }
@Override protected <K, V> NavigableMap<K, V> create() { @SuppressWarnings("unchecked") NavigableMap<K, V> innermost = new SafeTreeMap<>((Comparator<? super K>) Ordering.natural().nullsFirst()); TestMap<K, V> inner = new TestMap<>(innermost, mutex); NavigableMap<K, V> outer = Synchronized.navigableMap(inner, mutex); return outer; }