Class AbstractReplicaCollection<C extends AbstractReplicaCollection<C>>
- java.lang.Object
-
- org.apache.cassandra.locator.AbstractReplicaCollection<C>
-
- All Implemented Interfaces:
java.lang.Iterable<Replica>
,ReplicaCollection<C>
- Direct Known Subclasses:
Endpoints
,RangesAtEndpoint
public abstract class AbstractReplicaCollection<C extends AbstractReplicaCollection<C>> extends java.lang.Object implements ReplicaCollection<C>
A collection like class for Replica objects. Since the Replica class contains inetaddress, range, and transient replication status, basic contains and remove methods can be ambiguous. Replicas forces you to be explicit about what you're checking the container for, or removing from it. TODO: there's nothing about this collection that's unique to Replicas, and the implementation could make a useful general purpose immutable list<->set
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractReplicaCollection.ReplicaList
A simple list with no comodification checks and immutability by default (only append permitted, and only one initial copy) this permits us to reduce the amount of garbage generated, by not wrapping iterators or unnecessarily copying and reduces the amount of indirection necessary, as well as ensuring monomorphic callsites TODO flatten into AbstractReplicaCollection?protected static class
AbstractReplicaCollection.ReplicaMap<K>
A simple map that ensures the underlying list's iteration order is maintained, and can be shared with subLists (either produced via subList, or via filter that naturally produced a subList).-
Nested classes/interfaces inherited from interface org.apache.cassandra.locator.ReplicaCollection
ReplicaCollection.Builder<C extends ReplicaCollection<C>>
-
-
Field Summary
Fields Modifier and Type Field Description protected static AbstractReplicaCollection.ReplicaList
EMPTY_LIST
protected AbstractReplicaCollection.ReplicaList
list
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
anyMatch(java.util.function.Predicate<? super Replica> test)
<T> java.util.List<T>
asList(java.util.function.Function<Replica,T> view)
static <C extends ReplicaCollection<C>,B extends ReplicaCollection.Builder<C>>
java.util.stream.Collector<Replica,B,C>collector(java.util.Set<java.util.stream.Collector.Characteristics> characteristics, java.util.function.Supplier<B> supplier)
int
count(java.util.function.Predicate<? super Replica> test)
boolean
equals(java.lang.Object o)
It's not clear whetherAbstractReplicaCollection
should implement the order sensitiveequals
ofList
or the order obliviousequals
ofSet
.C
filter(java.util.function.Predicate<? super Replica> predicate)
C
filter(java.util.function.Predicate<? super Replica> predicate, int limit)
java.lang.Iterable<Replica>
filterLazily(java.util.function.Predicate<? super Replica> predicate)
java.lang.Iterable<Replica>
filterLazily(java.util.function.Predicate<? super Replica> predicate, int limit)
void
forEach(java.util.function.Consumer<? super Replica> forEach)
Replica
get(int i)
int
hashCode()
It's not clear whetherAbstractReplicaCollection
should implement the order sensitivehashCode
ofList
or the order obliviousequals
ofSet
.boolean
isEmpty()
java.util.Iterator<Replica>
iterator()
abstract ReplicaCollection.Builder<C>
newBuilder(int initialCapacity)
construct a new Builder of our own type, so that we can concatenate TODO: this isn't terribly pretty, but we need sometimes to select / merge two Endpoints of unknown type;int
size()
abstract C
snapshot()
C
sorted(java.util.Comparator<? super Replica> comparator)
java.util.stream.Stream<Replica>
stream()
C
subList(int start, int end)
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.locator.ReplicaCollection
contains, endpoints
-
-
-
-
Field Detail
-
EMPTY_LIST
protected static final AbstractReplicaCollection.ReplicaList EMPTY_LIST
-
list
protected final AbstractReplicaCollection.ReplicaList list
-
-
Method Detail
-
collector
public static <C extends ReplicaCollection<C>,B extends ReplicaCollection.Builder<C>> java.util.stream.Collector<Replica,B,C> collector(java.util.Set<java.util.stream.Collector.Characteristics> characteristics, java.util.function.Supplier<B> supplier)
-
newBuilder
public abstract ReplicaCollection.Builder<C> newBuilder(int initialCapacity)
construct a new Builder of our own type, so that we can concatenate TODO: this isn't terribly pretty, but we need sometimes to select / merge two Endpoints of unknown type;
-
snapshot
public abstract C snapshot()
-
subList
public final C subList(int start, int end)
- Specified by:
subList
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- an *eagerly constructed* copy of this collection containing the Replica at positions [start..end); An effort will be made to either return ourself, or a subList, where possible. It is guaranteed that no changes to any upstream Builder will affect the state of the result.
-
asList
public final <T> java.util.List<T> asList(java.util.function.Function<Replica,T> view)
-
count
public final int count(java.util.function.Predicate<? super Replica> test)
- Specified by:
count
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- the number of replicas that match the predicate
-
anyMatch
public final boolean anyMatch(java.util.function.Predicate<? super Replica> test)
-
filter
public final C filter(java.util.function.Predicate<? super Replica> predicate)
- Specified by:
filter
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- a *eagerly constructed* copy of this collection containing the Replica that match the provided predicate. An effort will be made to either return ourself, or a subList, where possible. It is guaranteed that no changes to any upstream Builder will affect the state of the result.
-
filter
public final C filter(java.util.function.Predicate<? super Replica> predicate, int limit)
- Specified by:
filter
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- a *eagerly constructed* copy of this collection containing the Replica that match the provided predicate. An effort will be made to either return ourself, or a subList, where possible. It is guaranteed that no changes to any upstream Builder will affect the state of the result. Only the first maxSize items will be returned.
-
filterLazily
public final java.lang.Iterable<Replica> filterLazily(java.util.function.Predicate<? super Replica> predicate)
- Specified by:
filterLazily
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- a *lazily constructed* Iterable over this collection, containing the Replica that match the provided predicate.
-
filterLazily
public final java.lang.Iterable<Replica> filterLazily(java.util.function.Predicate<? super Replica> predicate, int limit)
- Specified by:
filterLazily
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- a *lazily constructed* Iterable over this collection, containing the Replica that match the provided predicate. Only the first maxSize matching items will be returned.
-
sorted
public final C sorted(java.util.Comparator<? super Replica> comparator)
- Specified by:
sorted
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- an *eagerly constructed* copy of this collection containing the Replica re-ordered according to this comparator It is guaranteed that no changes to any upstream Builder will affect the state of the result.
-
get
public final Replica get(int i)
- Specified by:
get
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Parameters:
i
- a value in the range [0..size())- Returns:
- the i'th Replica, in our iteration order
-
size
public final int size()
- Specified by:
size
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- the number of Replica contained
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmpty
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Returns:
- true iff size() == 0
-
iterator
public final java.util.Iterator<Replica> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<C extends AbstractReplicaCollection<C>>
- Specified by:
iterator
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
-
forEach
public final void forEach(java.util.function.Consumer<? super Replica> forEach)
- Specified by:
forEach
in interfacejava.lang.Iterable<C extends AbstractReplicaCollection<C>>
-
stream
public final java.util.stream.Stream<Replica> stream()
- Specified by:
stream
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
-
equals
public final boolean equals(java.lang.Object o)
It's not clear whether
AbstractReplicaCollection
should implement the order sensitiveequals
ofList
or the order obliviousequals
ofSet
. We never rely on equality in the database so rather then leave in a potentially surprising implementation we have it throwUnsupportedOperationException
.Don't implement this and pick one behavior over the other. If you want equality you can static import
Iterables.elementsEqual(Iterable, Iterable)
and use that to get order sensitive equals.- Specified by:
equals
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
It's not clear whether
AbstractReplicaCollection
should implement the order sensitivehashCode
ofList
or the order obliviousequals
ofSet
. We never rely on hashCode in the database so rather then leave in a potentially surprising implementation we have it throwUnsupportedOperationException
.Don't implement this and pick one behavior over the other.
- Specified by:
hashCode
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public final java.lang.String toString()
- Specified by:
toString
in interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
- Overrides:
toString
in classjava.lang.Object
-
-