Class ArraysPlume.ListOrArray<T extends @Nullable Object>

java.lang.Object
org.plumelib.util.ArraysPlume.ListOrArray<T>
Type Parameters:
T - the type of array or list elements
Enclosing class:
ArraysPlume

private static class ArraysPlume.ListOrArray<T extends @Nullable Object> extends Object
A wrapper around a list or an array (or null). Avoids code duplication for arrays and lists, at the cost of object construction and method calls.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) T @Nullable []
    The array that this object wraps, or null.
    (package private) @Nullable List<T>
    The list that this object wraps, or null.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ListOrArray(@Nullable List<T> theList)
    Creates a ListOrArray that wraps a list.
    ListOrArray(T @Nullable [] theArray)
    Creates a ListOrArray that wraps an array.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    copyInto(T[] dest, int destPos)
    Copy the contents of this into the given array, starting at the given index in the array.
    (package private) boolean
    Returns true if this represents an empty collection.
    (package private) boolean
    Returns true if this represents a null value.
    (package private) @Nullable Class<? extends @Nullable Object>
    Returns the least upper bound of the classes of the elements of this.
    (package private) @org.checkerframework.checker.index.qual.NonNegative int
    Returns the size of the collection this represents.
    (package private) T[]
    Returns an array with the same contents as this.
     
    Returns a verbose representation of this, for debugging.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • theArray

      T extends @Nullable Object @Nullable [] theArray
      The array that this object wraps, or null.
    • theList

      @Nullable List<T extends @Nullable Object> theList
      The list that this object wraps, or null.
  • Constructor Details

    • ListOrArray

      ListOrArray(T @Nullable [] theArray)
      Creates a ListOrArray that wraps an array.
      Parameters:
      theArray - the delegate that will be wrapped
    • ListOrArray

      ListOrArray(@Nullable List<T> theList)
      Creates a ListOrArray that wraps a list.
      Parameters:
      theList - the delegate that will be wrapped
  • Method Details

    • isNull

      @Pure boolean isNull()
      Returns true if this represents a null value.
      Returns:
      true if this represents a null value
    • size

      @Pure @org.checkerframework.checker.index.qual.NonNegative int size()
      Returns the size of the collection this represents.
      Returns:
      the size of the collection this represents
    • isEmpty

      @Pure boolean isEmpty()
      Returns true if this represents an empty collection.
      Returns:
      true if this represents an empty collection
    • toArray

      @SideEffectFree T[] toArray()
      Returns an array with the same contents as this.
      Returns:
      an array with the same contents as this
    • copyInto

      void copyInto(T[] dest, int destPos)
      Copy the contents of this into the given array, starting at the given index in the array.
      Parameters:
      dest - the destination array
      destPos - the index at which to start overwriting elements of dest
    • leastUpperBound

      @Nullable Class<? extends @Nullable Object> leastUpperBound()
      Returns the least upper bound of the classes of the elements of this.
      Returns:
      the least upper bound of the classes of the elements of this
    • toString

      public String toString(@GuardSatisfied ArraysPlume.ListOrArray<T extends @Nullable Object> this)
      Overrides:
      toString in class Object
    • toStringDebug

      public String toStringDebug()
      Returns a verbose representation of this, for debugging.
      Returns:
      a verbose representation of this, for debugging