Package me.ahoo.cosid.sharding
Class ExactCollection<E>
java.lang.Object
java.util.AbstractCollection<E>
me.ahoo.cosid.sharding.ExactCollection<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,RandomAccess
准确式集合.
用于 Interval 算法、Mod 算法可以提前预知节点数量的场景。
主要针对以下问题: -- 使用HashSet
导致的内存空间浪费 -- 添加元素时导致的集合膨胀(也可以通过给定 expectedSize 计算准确 capacity 就像Sets.newHashSetWithExpectedSize(int)
)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
static <E> ExactCollection<E>
empty()
boolean
get
(int index) int
hashCode()
int
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class java.util.AbstractCollection
add, containsAll, isEmpty, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
ExactCollection
public ExactCollection(int size) -
ExactCollection
-
-
Method Details
-
empty
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in classAbstractCollection<E>
-
get
-
add
-
indexOf
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Overrides:
contains
in classAbstractCollection<E>
-
iterator
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in classAbstractCollection<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Overrides:
remove
in classAbstractCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classObject
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classObject
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Overrides:
clear
in classAbstractCollection<E>
-