@ThreadSafe public interface UserHistory<E extends Event> extends List<E>
Represents a user profile, associating an immutable list of events with a user. The events are in timestamp order. Histories also can memoize summaries and other computed properties of themselves.
Modifier and Type | Method and Description |
---|---|
<T extends Event> |
filter(Class<T> type)
Filter the user history to only contain elements of a particular type.
|
UserHistory<E> |
filter(Predicate<? super E> pred)
Filter the user history with a predicate.
|
long |
getUserId()
Retrieve the user ID.
|
LongSet |
itemSet()
Get the set of items touched by events in this history.
|
<T> T |
memoize(Function<? super UserHistory<E>,? extends T> func)
Apply a function to this history, memoizing its return value.
|
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
parallelStream, removeIf, stream
long getUserId()
Retrieve the user ID.
<T extends Event> UserHistory<T> filter(Class<T> type)
Filter the user history to only contain elements of a particular type.
T
- The type of element to include.type
- The type of elements to include.UserHistory<E> filter(Predicate<? super E> pred)
Filter the user history with a predicate.
pred
- The predicate to with which to filter the history.LongSet itemSet()
Get the set of items touched by events in this history. Only nonnegative item IDs are considered.
<T> T memoize(Function<? super UserHistory<E>,? extends T> func)
Apply a function to this history, memoizing its return value. Used for caching things like summaries. The function should appropriately define its Function.equals(Object)
and Object.hashCode()
methods in order for memoization to work well.
This method is not guaranteed to be synchronized. It is safe to memoize distinct functions in parallel, but potentially-parallel use of the same function must be synchronized by client code or the function may be called twice. The implementation in AbstractUserHistory
uses a ConcurrentHashMap
. Multiple calls are therefore safe, but may result in extra work. All implementations must maintain this safety guarantee, although they may do so by synchronizing this method.
T
- The return type of the function.func
- The function to call and memoize.