Package edu.uky.ai.util
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()
-
Constructor Details
-
ImmutableArray
Constructs a new immutable array which reflects the given array.- Parameters:
array
- the array to mirror
-
ImmutableArray
Creates an immutable array that contains the elements of a collection.- Parameters:
collection
- the collection to mirrortype
- the type of object kept in the array
-
-
Method Details
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
size
public int size()Returns the number of elements in the array.- Returns:
- the number of elements
-
get
Returns the element at a given index.- Parameters:
index
- the index in the array- Returns:
- the element at that index
-
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
- Specified by:
iterator
in interfacejava.lang.Iterable<E>
-
forEach
- Specified by:
forEach
in interfacejava.lang.Iterable<E>
-