Package com.google.protobuf
Class AbstractProtobufList<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- com.google.protobuf.AbstractProtobufList<E>
-
- All Implemented Interfaces:
Internal.ProtobufList<E>,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.RandomAccess
- Direct Known Subclasses:
BooleanArrayList,DoubleArrayList,FloatArrayList,IntArrayList,LazyStringArrayList,LongArrayList,ProtobufArrayList
abstract class AbstractProtobufList<E> extends java.util.AbstractList<E> implements Internal.ProtobufList<E>
An abstract implementation ofInternal.ProtobufListwhich manages mutability semantics. All mutate methods must check if the list is mutable before proceeding. Subclasses must invokeensureIsMutable()manually when overriding those methods.This implementation assumes all subclasses are array based, supporting random access.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_CAPACITYprivate booleanisMutableWhether or not this list is modifiable.
-
Constructor Summary
Constructors Constructor Description AbstractProtobufList()Constructs a mutable list by default.AbstractProtobufList(boolean isMutable)Constructs an immutable list for EMPTY lists
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)booleanadd(E e)booleanaddAll(int index, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)voidclear()protected voidensureIsMutable()Throws anUnsupportedOperationExceptionif the list is immutable.booleanequals(java.lang.Object o)inthashCode()booleanisModifiable()Returns whether this list can be modified via the publicly accessibleListmethods.voidmakeImmutable()Makes this list immutable.Eremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)Eset(int index, E element)-
Methods inherited from class java.util.AbstractList
get, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.protobuf.Internal.ProtobufList
mutableCopyWithCapacity
-
-
-
-
Field Detail
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY
- See Also:
- Constant Field Values
-
isMutable
private boolean isMutable
Whether or not this list is modifiable.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
add
public boolean add(E e)
-
add
public void add(int index, E element)
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
-
addAll
public boolean addAll(int index, java.util.Collection<? extends E> c)
-
clear
public void clear()
-
isModifiable
public boolean isModifiable()
Description copied from interface:Internal.ProtobufListReturns whether this list can be modified via the publicly accessibleListmethods.- Specified by:
isModifiablein interfaceInternal.ProtobufList<E>
-
makeImmutable
public final void makeImmutable()
Description copied from interface:Internal.ProtobufListMakes this list immutable. All subsequent modifications will throw anUnsupportedOperationException.- Specified by:
makeImmutablein interfaceInternal.ProtobufList<E>
-
remove
public E remove(int index)
-
remove
public boolean remove(java.lang.Object o)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
ensureIsMutable
protected void ensureIsMutable()
Throws anUnsupportedOperationExceptionif the list is immutable. Subclasses are responsible for invoking this method on mutate operations.
-
-