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>
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
,SequencedCollection<E>
- Direct Known Subclasses:
BooleanArrayList
,DoubleArrayList
,FloatArrayList
,IntArrayList
,LazyStringArrayList
,LongArrayList
,ProtobufArrayList
An abstract implementation of
Internal.ProtobufList
which manages mutability semantics. All mutate
methods must check if the list is mutable before proceeding. Subclasses must invoke ensureIsMutable()
manually when overriding those methods.
This implementation assumes all subclasses are array based, supporting random access.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
private boolean
Whether or not this list is modifiable.Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a mutable list by default.AbstractProtobufList
(boolean isMutable) Constructs an immutable list for EMPTY lists -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) void
clear()
protected void
Throws anUnsupportedOperationException
if the list is immutable.boolean
int
hashCode()
boolean
Returns whether this list can be modified via the publicly accessibleList
methods.final void
Makes this list immutable.remove
(int index) boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) 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 java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface com.google.protobuf.Internal.ProtobufList
mutableCopyWithCapacity
Methods inherited from interface java.util.List
addFirst, addLast, contains, containsAll, get, getFirst, getLast, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeFirst, removeLast, replaceAll, reversed, size, sort, spliterator, subList, toArray, toArray
-
Field Details
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY- See Also:
-
isMutable
private boolean isMutableWhether or not this list is modifiable.
-
-
Constructor Details
-
AbstractProtobufList
AbstractProtobufList()Constructs a mutable list by default. -
AbstractProtobufList
AbstractProtobufList(boolean isMutable) Constructs an immutable list for EMPTY lists
-
-
Method Details
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceList<E>
- Overrides:
equals
in classAbstractList<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classAbstractList<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
add
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
addAll
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractList<E>
-
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
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
set
-
ensureIsMutable
protected void ensureIsMutable()Throws anUnsupportedOperationException
if the list is immutable. Subclasses are responsible for invoking this method on mutate operations.
-