Class ConfigArray

java.lang.Object
org.omegazero.common.config.ConfigArray
All Implemented Interfaces:
Serializable, Iterable<Object>

public class ConfigArray extends Object implements Serializable, Iterable<Object>
A read-only array of any type of data, providing a layer of abstraction for different data representations. Created by a Configuration instance.
Since:
2.4
See Also:
  • Field Details

    • data

      protected final List<Object> data
      The data.
  • Constructor Details

    • ConfigArray

      public ConfigArray()
      Creates an empty ConfigArray.
    • ConfigArray

      @Deprecated public ConfigArray(int initialCapacity)
      Deprecated.
      Creates a ConfigArray.
      Parameters:
      initialCapacity - The number of elements
    • ConfigArray

      public ConfigArray(List<Object> data)
      Creates a ConfigArray with the given elements.

      Changes on the given list have no effects on this ConfigArray.

      Parameters:
      data - The data
  • Method Details

    • copyData

      public List<Object> copyData()
      Creates a new ArrayList with all values of this ConfigArray. Changes to the returned list have no effect on this ConfigArray.
      Returns:
      A List with all values of this ConfigArray
    • merge

      public ConfigArray merge(ConfigArray other)
      Creates a new ConfigArray that contains all values of this and the given ConfigArray. Values of this ConfigArray are added first, followed by values in the provided ConfigArray.
      Both provided objects stay unchanged.
      Parameters:
      other - The ConfigArray to merge this one with
      Returns:
      A new ConfigArray with all values of this and other
    • size

      public int size()
      Returns the number of elements in this ConfigArray.
      Returns:
      The number of elements
      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns whether this ConfigArray is empty.
      Returns:
      true if empty
      See Also:
    • contains

      public boolean contains(Object o)
      Returns whether the given element o is in this ConfigArray.
      Parameters:
      o - The element to search
      Returns:
      true if o exists
      See Also:
    • toArray

      public Object[] toArray()
      Converts this ConfigArray to an Object array.
      Returns:
      The array containing all elements
      See Also:
    • toArray

      public <T> T[] toArray(Class<T> type)
      Converts this ConfigArray to an array of the given type.
      Parameters:
      type - The target type
      Returns:
      The array containing all elements
      Throws:
      ClassCastException - If any element in this ConfigArray is not of the given type
      Since:
      2.11.0
      See Also:
    • containsAll

      public boolean containsAll(Collection<?> c)
      Returns whether all elements in the given Collection are contained in this ConfigArray.
      Parameters:
      c - The collection
      Returns:
      true if all elements of the collection exist
      See Also:
    • get

      public Object get(int index)
      Returns the element at the given position in this ConfigArray.
      Parameters:
      index - The index
      Returns:
      The element at the index
      See Also:
    • indexOf

      public int indexOf(Object o)
      Returns the index of the given element.
      Parameters:
      o - The element to search
      Returns:
      The index of the element, or -1 if the element does not exist
      See Also:
    • lastIndexOf

      public int lastIndexOf(Object o)
      Returns the last index of the given element.
      Parameters:
      o - The element to search
      Returns:
      The last index of the element, or -1 if the element does not exist
      See Also:
    • iterator

      public Iterator<Object> iterator()
      Specified by:
      iterator in interface Iterable<Object>
    • equals

      public boolean equals(Object o)
      Determines whether the given object is equal to this ConfigArray.

      Another object is equal if it is also a ConfigArray and contains the same elements.

      Overrides:
      equals in class Object
      See Also:
    • hashCode

      public int hashCode()
      Returns a hash code for this ConfigArray.
      Overrides:
      hashCode in class Object
      See Also:
    • clone

      public ConfigArray clone()
      Returns a clone of this ConfigArray, which contains the same elements as this ConfigArray.
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Returns a string representation of this ConfigArray.
      Overrides:
      toString in class Object
      See Also:
      • List#toString()