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 classAbstractReplicaCollection.ReplicaListA 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 classAbstractReplicaCollection.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.ReplicaListEMPTY_LISTprotected AbstractReplicaCollection.ReplicaListlist
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleananyMatch(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)intcount(java.util.function.Predicate<? super Replica> test)booleanequals(java.lang.Object o)It's not clear whetherAbstractReplicaCollectionshould implement the order sensitiveequalsofListor the order obliviousequalsofSet.Cfilter(java.util.function.Predicate<? super Replica> predicate)Cfilter(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)voidforEach(java.util.function.Consumer<? super Replica> forEach)Replicaget(int i)inthashCode()It's not clear whetherAbstractReplicaCollectionshould implement the order sensitivehashCodeofListor the order obliviousequalsofSet.booleanisEmpty()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;intsize()abstract Csnapshot()Csorted(java.util.Comparator<? super Replica> comparator)java.util.stream.Stream<Replica>stream()CsubList(int start, int end)java.lang.StringtoString()-
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:
subListin 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:
countin 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:
filterin 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:
filterin 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:
filterLazilyin 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:
filterLazilyin 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:
sortedin 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:
getin 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:
sizein interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>- Returns:
- the number of Replica contained
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmptyin interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>- Returns:
- true iff size() == 0
-
iterator
public final java.util.Iterator<Replica> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<C extends AbstractReplicaCollection<C>>- Specified by:
iteratorin interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
-
forEach
public final void forEach(java.util.function.Consumer<? super Replica> forEach)
- Specified by:
forEachin interfacejava.lang.Iterable<C extends AbstractReplicaCollection<C>>
-
stream
public final java.util.stream.Stream<Replica> stream()
- Specified by:
streamin interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>
-
equals
public final boolean equals(java.lang.Object o)
It's not clear whether
AbstractReplicaCollectionshould implement the order sensitiveequalsofListor the order obliviousequalsofSet. 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:
equalsin interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
It's not clear whether
AbstractReplicaCollectionshould implement the order sensitivehashCodeofListor the order obliviousequalsofSet. 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:
hashCodein interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>- Overrides:
hashCodein classjava.lang.Object
-
toString
public final java.lang.String toString()
- Specified by:
toStringin interfaceReplicaCollection<C extends AbstractReplicaCollection<C>>- Overrides:
toStringin classjava.lang.Object
-
-