Package ints

Class SynchedIntList

java.lang.Object
ints.SynchedIntList

public class SynchedIntList extends Object

Class SynchedIntList represents a list of integers. Class SynchedIntList supports a clear() method, but it does not support a remove() method.

Instances of class SynchedIntList are thread-safe.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default initial capacity of an SynchedIntList, which is 16.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an SynchedIntList object with the default initial capacity.
    SynchedIntList(int initCapacity)
    Constructs an SynchedIntList object with the specified initial capacity.
    SynchedIntList(int[] ia)
    Constructs an SynchedIntList by cloning the specified array.
    Constructs an SynchedIntList by copying the specified SynchedIntList.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int value)
    Adds the specified integer to the end of this list.
    void
    Removes all elements from this list.
    int
    get(int index)
    Returns the element at the specified position in this list.
    int
    set(int index, int value)
    Replaces the element at the specified position in this list with the specified element.
    int
    Returns the number of elements in this list.
    int[]
    Returns an integer array containing the sequence of elements in this list.
    Returns java.util.Arrays.toString(this.toArray())

    Methods inherited from class java.lang.Object

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

    • DEFAULT_INIT_CAPACITY

      public static final int DEFAULT_INIT_CAPACITY
      The default initial capacity of an SynchedIntList, which is 16.
      See Also:
  • Constructor Details

    • SynchedIntList

      public SynchedIntList()
      Constructs an SynchedIntList object with the default initial capacity.
      See Also:
    • SynchedIntList

      public SynchedIntList(int initCapacity)
      Constructs an SynchedIntList object with the specified initial capacity.
      Parameters:
      initCapacity - the initial capacity of this list
      Throws:
      IllegalArgumentException - if initCapacity < 0
    • SynchedIntList

      public SynchedIntList(int[] ia)
      Constructs an SynchedIntList by cloning the specified array.
      Parameters:
      ia - a list of integer values
      Throws:
      NullPointerException - if ia == null
    • SynchedIntList

      public SynchedIntList(SynchedIntList intList)
      Constructs an SynchedIntList by copying the specified SynchedIntList.
      Parameters:
      intList - a list of integer values
      Throws:
      NullPointerException - if intList == null
  • Method Details

    • add

      public void add(int value)
      Adds the specified integer to the end of this list.
      Parameters:
      value - the integer to be added to the end of this list
    • get

      public int get(int index)
      Returns the element at the specified position in this list.
      Parameters:
      index - the index of the element to be returned
      Returns:
      the element at the specified position in this list
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >= this.size()
    • set

      public int set(int index, int value)
      Replaces the element at the specified position in this list with the specified element.
      Parameters:
      index - the index of the element to be replaced
      value - the value to be stored at the specified position in this list
      Returns:
      the previous value at the specified position in this list
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >= this.size()
    • size

      public int size()
      Returns the number of elements in this list.
      Returns:
      the number of elements in this list
    • toArray

      public int[] toArray()
      Returns an integer array containing the sequence of elements in this list.
      Returns:
      an integer array containing the sequence of elements in this list
    • clear

      public void clear()
      Removes all elements from this list.
    • toString

      public String toString()
      Returns java.util.Arrays.toString(this.toArray())
      Overrides:
      toString in class Object
      Returns:
      java.util.Arrays.toString(this.toArray())