@Override public K last() { synchronized (sync) { return sortedSet.last(); } } }
@Override public K last() { return sortedSet.last(); } }
public ErrorRecord last() { return queue.last(); }
@Test public void testSingletonMap() { Long2DoubleSortedMap map = new Long2DoubleSortedArrayMap(SortedKeyIndex.create(42), new double[]{3.5}); assertThat(map.get(42L), equalTo(3.5)); assertThat(map.size(), equalTo(1)); assertThat(map.isEmpty(), equalTo(false)); assertThat(map.keySet(), contains(42L)); assertThat(map.values(), contains(3.5)); assertThat(map.entrySet(), hasSize(1)); assertThat(map.firstLongKey(), equalTo(42L)); assertThat(map.lastLongKey(), equalTo(42L)); Map.Entry<Long, Double> ent = map.entrySet().first(); assertThat(ent, notNullValue()); assertThat(ent.getKey(), equalTo(42L)); assertThat(ent.getValue(), equalTo(3.5)); assertThat(map.entrySet().contains(Pair.of(42L, 3.5)), equalTo(true)); assertThat(map.entrySet().contains(Pair.of(42L, 3.7)), equalTo(false)); assertThat(map.entrySet().contains(Pair.of(41L, 3.5)), equalTo(false)); assertThat(map.entrySet().first(), equalTo((Object) Pair.of(42L, 3.5))); assertThat(map.entrySet().last(), equalTo((Object) Pair.of(42L, 3.5))); }
@Test public void testEmptyMap() { Long2DoubleSortedMap map = new Long2DoubleSortedArrayMap(SortedKeyIndex.empty(), new double[0]); assertThat(map.size(), equalTo(0)); assertThat(map.isEmpty(), equalTo(true)); assertThat(map.keySet(), hasSize(0)); assertThat(map.entrySet(), hasSize(0)); assertThat(map.values(), hasSize(0)); assertThat(map.long2DoubleEntrySet(), hasSize(0)); assertThat(map.get(42L), equalTo(0.0)); assertThat(map.get((Long) 42L), nullValue()); try { map.entrySet().first(); fail("entrySet.first should fail"); } catch (NoSuchElementException e) { /* expected */ } try { map.entrySet().last(); fail("entrySet.last should fail"); } catch (NoSuchElementException e) { /* expected */ } }
@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)); } } }
@Override public double getMaxTimestamp() { if (mainIndex) { Double2IntSortedMap sortedMap = (Double2IntSortedMap) timestampIndexStore.timeSortedMap; if (!sortedMap.isEmpty()) { return sortedMap.lastDoubleKey(); } } else { Double2IntSortedMap sortedMap = (Double2IntSortedMap) timestampIndexStore.timeSortedMap; if (!sortedMap.isEmpty()) { ObjectBidirectionalIterator<Double2IntMap.Entry> bi = sortedMap.double2IntEntrySet().iterator(sortedMap .double2IntEntrySet().last()); while (bi.hasPrevious()) { Double2IntMap.Entry entry = bi.previous(); double timestamp = entry.getDoubleKey(); int index = entry.getIntValue(); if (index < timestamps.length) { TimeIndexEntry timestampEntry = timestamps[index]; if (timestampEntry != null) { return timestamp; } } } } } return Double.POSITIVE_INFINITY; }
@Override public double getMaxTimestamp() { if (mainIndex) { Double2IntSortedMap sortedMap = (Double2IntSortedMap) timestampIndexStore.timeSortedMap; if (!sortedMap.isEmpty()) { return sortedMap.lastDoubleKey(); } } else { Double2IntSortedMap sortedMap = (Double2IntSortedMap) timestampIndexStore.timeSortedMap; if (!sortedMap.isEmpty()) { ObjectBidirectionalIterator<Double2IntMap.Entry> bi = sortedMap.double2IntEntrySet().iterator(sortedMap .double2IntEntrySet().last()); while (bi.hasPrevious()) { Double2IntMap.Entry entry = bi.previous(); double timestamp = entry.getDoubleKey(); int index = entry.getIntValue(); if (index < timestamps.length) { TimeIndexEntry timestampEntry = timestamps[index]; if (timestampEntry != null) { return timestamp; } } } } } return Double.POSITIVE_INFINITY; }