Class ImmutableArray<E>

java.lang.Object
edu.uky.ai.util.ImmutableArray<E>
Type Parameters:
E - the type of object kept in the array
All Implemented Interfaces:
Serializable, Iterable<E>

public class ImmutableArray<E> extends Object implements Serializable, Iterable<E>
An array whose values cannot be modified.
Author:
Stephen G. Ware
See Also:
  • Constructor Details

    • ImmutableArray

      public ImmutableArray(E[] array)
      Constructs a new immutable array which reflects the given array.
      Parameters:
      array - the array to mirror
    • ImmutableArray

      public ImmutableArray(Collection<E> collection, Class<E> type)
      Creates an immutable array that contains the elements of a collection.
      Parameters:
      collection - the collection to mirror
      type - the type of object kept in the array
  • Method Details

    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • size

      public int size()
      Returns the number of elements in the array.
      Returns:
      the number of elements
    • get

      public final E get(int index)
      Returns the element at a given index.
      Parameters:
      index - the index in the array
      Returns:
      the element at that index
    • getComponentType

      public Class<E> getComponentType()
      Returns the array's component type.
      Returns:
      the component type
    • contains

      public boolean contains(Object element)
      Checks if the array contains a given element.
      Parameters:
      element - the element to search for
      Returns:
      true if the array contains an object equal to the given object, false otherwise
    • indexOf

      public int indexOf(Object element)
      Returns the index of the first object that is equal to a given object.
      Parameters:
      element - the element to search for
      Returns:
      the index of that object in the array, or -1 if no such object exists
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Iterable<E>
    • forEach

      public void forEach(Consumer<? super E> consumer)
      Specified by:
      forEach in interface Iterable<E>