@Immutable public class KeyedObjectMap<T> extends AbstractLong2ObjectSortedMap<T> implements Serializable, Iterable<T>
A map that allows objects with long keys to be looked up by key. This structure works on objects that have an associated key, such as recommendation results or ratings (keyed by user or item ID). The key is extracted from an object by means of a KeyExtractor
. This allows the objects to be stored directly, without separate storage for keys. This map stores objects in a list sorted by key, and looks them up with binary search. Therefore, the key extractor should generally be fast (e.g. just calling a getter), in order for this class to be performant.
AbstractLong2ObjectSortedMap.KeySetIterator<V>, AbstractLong2ObjectSortedMap.ValuesCollection, AbstractLong2ObjectSortedMap.ValuesIterator<V>
AbstractLong2ObjectMap.BasicEntry<V>
Long2ObjectSortedMap.FastSortedEntrySet<V>
Long2ObjectMap.Entry<V>, Long2ObjectMap.FastEntrySet<V>
defRetValue
Constructor and Description |
---|
KeyedObjectMap(Iterable<? extends T> objs,
KeyExtractor<? super T> ex)
Create a new keyed object map from a collection of data.
|
Modifier and Type | Method and Description |
---|---|
LongComparator |
comparator() |
boolean |
containsKey(long k) |
boolean |
containsValue(Object v) |
static <T extends KeyedObject> |
create(Collection<? extends T> objs)
Create a new keyed object map.
|
static <T> KeyedObjectMap<T> |
create(Iterable<? extends T> objs,
KeyExtractor<? super T> ex)
Create a new keyed object map.
|
long |
firstLongKey() |
T |
get(long k) |
KeyedObjectMap<T> |
headMap(long l) |
ObjectBidirectionalIterator<T> |
iterator() |
LongSortedSet |
keySet() |
long |
lastLongKey() |
ObjectSortedSet<Long2ObjectMap.Entry<T>> |
long2ObjectEntrySet() |
static <T extends KeyedObject> |
newBuilder()
Create a new builder for a keyed object map over a self-keying type.
|
static <T> KeyedObjectMapBuilder<T> |
newBuilder(KeyExtractor<? super T> ex)
Create a new builder for a keyed object map.
|
int |
size() |
KeyedObjectMap<T> |
subMap(long from,
long to) |
KeyedObjectMap<T> |
tailMap(long l) |
ObjectCollection<T> |
values() |
entrySet, firstKey, headMap, lastKey, subMap, tailMap
equals, hashCode, isEmpty, putAll, toString
clear, containsKey, defaultReturnValue, defaultReturnValue, get, put, put, remove, remove
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
defaultReturnValue, defaultReturnValue, put, remove
clear, containsKey, get, put, remove
clear, compute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
public KeyedObjectMap(Iterable<? extends T> objs, KeyExtractor<? super T> ex)
Create a new keyed object map from a collection of data.
objs
- The input data.public static <T> KeyedObjectMapBuilder<T> newBuilder(KeyExtractor<? super T> ex)
Create a new builder for a keyed object map.
ex
- The key extractor.T
- The keyed object type.public static <T extends KeyedObject> KeyedObjectMapBuilder<T> newBuilder()
Create a new builder for a keyed object map over a self-keying type.
T
- The keyed object type.public static <T extends KeyedObject> KeyedObjectMap<T> create(Collection<? extends T> objs)
Create a new keyed object map.
objs
- A collection of objects to put in the map.T
- The keyed object type.objs
.public static <T> KeyedObjectMap<T> create(Iterable<? extends T> objs, KeyExtractor<? super T> ex)
Create a new keyed object map.
objs
- A collection of objects to put in the map.ex
- The key extractor.T
- The keyed object type.objs
.public ObjectSortedSet<Long2ObjectMap.Entry<T>> long2ObjectEntrySet()
long2ObjectEntrySet
in interface Long2ObjectMap<T>
long2ObjectEntrySet
in interface Long2ObjectSortedMap<T>
public LongSortedSet keySet()
public ObjectCollection<T> values()
public ObjectBidirectionalIterator<T> iterator()
public LongComparator comparator()
comparator
in interface Long2ObjectSortedMap<T>
comparator
in interface SortedMap<Long,T>
public KeyedObjectMap<T> subMap(long from, long to)
subMap
in interface Long2ObjectSortedMap<T>
public KeyedObjectMap<T> headMap(long l)
headMap
in interface Long2ObjectSortedMap<T>
public KeyedObjectMap<T> tailMap(long l)
tailMap
in interface Long2ObjectSortedMap<T>
public long firstLongKey()
firstLongKey
in interface Long2ObjectSortedMap<T>
public long lastLongKey()
lastLongKey
in interface Long2ObjectSortedMap<T>
public T get(long k)
get
in interface Long2ObjectFunction<T>
public boolean containsKey(long k)
containsKey
in interface Long2ObjectFunction<T>
containsKey
in class AbstractLong2ObjectMap<T>
public boolean containsValue(Object v)
containsValue
in interface Map<Long,T>
containsValue
in class AbstractLong2ObjectMap<T>