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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanaddAll(Collection<? extends E> c) voidclear()booleanstatic <E> ExactCollection<E>empty()booleanget(int index) inthashCode()intiterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class java.util.AbstractCollection
add, containsAll, isEmpty, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
sizein interfaceCollection<E>- Specified by:
sizein classAbstractCollection<E>
-
get
-
add
-
indexOf
-
contains
- Specified by:
containsin interfaceCollection<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Overrides:
removein classAbstractCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Overrides:
addAllin classAbstractCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Overrides:
removeAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Overrides:
retainAllin classAbstractCollection<E>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Overrides:
hashCodein classObject
-
equals
- Specified by:
equalsin interfaceCollection<E>- Overrides:
equalsin classObject
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>
-