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.ProtobufList
which 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 int
DEFAULT_CAPACITY
private boolean
isMutable
Whether or not this list is modifiable.
-
Constructor Summary
Constructors Constructor Description AbstractProtobufList()
Constructs a mutable list by default.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E e)
boolean
addAll(int index, java.util.Collection<? extends E> c)
boolean
addAll(java.util.Collection<? extends E> c)
void
clear()
protected void
ensureIsMutable()
Throws anUnsupportedOperationException
if the list is immutable.boolean
equals(java.lang.Object o)
int
hashCode()
boolean
isModifiable()
Returns whether this list can be modified via the publicly accessibleList
methods.void
makeImmutable()
Makes this list immutable.E
remove(int index)
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
E
set(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.ProtobufList
Returns whether this list can be modified via the publicly accessibleList
methods.- Specified by:
isModifiable
in interfaceInternal.ProtobufList<E>
-
makeImmutable
public final void makeImmutable()
Description copied from interface:Internal.ProtobufList
Makes this list immutable. All subsequent modifications will throw anUnsupportedOperationException
.- Specified by:
makeImmutable
in 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 anUnsupportedOperationException
if the list is immutable. Subclasses are responsible for invoking this method on mutate operations.
-
-