@Override public long lastLong() { return sortedSet.lastLong(); } /**
@Override public long lastLong() { synchronized (sync) { return sortedSet.lastLong(); } } /**
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override default Long last() { return Long.valueOf(lastLong()); } }
@Test public void testCreateWithLists() { for (Set<Long> keys: someSets(longs(), integers(0, 500))) { LongSortedSet sorted = LongUtils.packedSet(keys); SortedKeyIndex dom = SortedKeyIndex.fromCollection(keys); double[] values = new double[dom.size()]; for (int i = 0; i < dom.size(); i++) { values[i] = doubles().next(); } Long2DoubleSortedMap map = new Long2DoubleSortedArrayMap(dom, values); assertThat(map.size(), equalTo(dom.size())); assertThat(map.size(), equalTo(keys.size())); if (map.size() > 0) { assertThat(map.entrySet().first().getKey(), equalTo(sorted.firstLong())); assertThat(map.entrySet().last().getKey(), equalTo(sorted.lastLong())); assertThat(map.firstLongKey(), equalTo(sorted.firstLong())); assertThat(map.lastLongKey(), equalTo(sorted.lastLong())); } assertThat(map.keySet(), equalTo(sorted)); for (Long k: keys) { assertThat(map.containsKey(k), equalTo(true)); } } }
/** * Run a battery of tests on a standard set. Used to test a variety of * construction scenarios with less code duplication. * * @param set The set {2, 5, 6}. */ private void testSetSimple(LongSortedSet set) { assertFalse(set.isEmpty()); assertEquals(3, set.size()); assertEquals(2, set.firstLong()); assertEquals(6, set.lastLong()); assertEquals(Long.valueOf(2), set.first()); assertEquals(Long.valueOf(6), set.last()); assertTrue(set.contains(2)); assertTrue(set.contains(5)); assertTrue(set.contains(6)); assertFalse(set.contains(0)); assertFalse(set.contains(42)); assertFalse(set.iterator().hasPrevious()); long[] items = LongIterators.unwrap(set.iterator()); assertEquals(2, items[0]); assertEquals(5, items[1]); assertEquals(6, items[2]); }