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:
java.io.Serializable, java.lang.Iterable<E>

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

    Constructors 
    Constructor Description
    ImmutableArray​(E[] array)
    Constructs a new immutable array which reflects the given array.
    ImmutableArray​(java.util.Collection<E> collection, java.lang.Class<E> type)
    Creates an immutable array that contains the elements of a collection.
  • Method Summary

    Modifier and Type Method Description
    boolean contains​(java.lang.Object element)
    Checks if the array contains a given element.
    boolean equals​(java.lang.Object other)  
    void forEach​(java.util.function.Consumer<? super E> consumer)  
    E get​(int index)
    Returns the element at a given index.
    java.lang.Class<E> getComponentType()
    Returns the array's component type.
    int hashCode()  
    int indexOf​(java.lang.Object element)
    Returns the index of the first object that is equal to a given object.
    java.util.Iterator<E> iterator()  
    int size()
    Returns the number of elements in the array.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    spliterator
  • 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​(java.util.Collection<E> collection, java.lang.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​(java.lang.Object other)
      Overrides:
      equals in class java.lang.Object
    • hashCode

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

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.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 java.lang.Class<E> getComponentType()
      Returns the array's component type.
      Returns:
      the component type
    • contains

      public boolean contains​(java.lang.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​(java.lang.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 java.util.Iterator<E> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<E>
    • forEach

      public void forEach​(java.util.function.Consumer<? super E> consumer)
      Specified by:
      forEach in interface java.lang.Iterable<E>