Class FloatArray

  • Direct Known Subclasses:
    PointArray


    public class FloatArray
    extends Object
    A resizable, ordered or unordered float array. Avoids the boxing that occurs with ArrayList<Float>. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
    • Field Summary

      Fields

      Modifier and Type Field and Description
      float[] items
       
      boolean ordered
       
      int size
       
    • Constructor Summary

      Constructors

      Constructor and Description
      FloatArray()
      Creates an ordered array with a capacity of 16.
      FloatArray(boolean ordered, float[] array, int startIndex, int count)
      Creates a new array containing the elements in the specified array.
      FloatArray(boolean ordered, int capacity)
       
      FloatArray(float[] array)
      Creates a new ordered array containing the elements in the specified array.
      FloatArray(FloatArray array)
      Creates a new array containing the elements in the specific array.
      FloatArray(int capacity)
      Creates an ordered array with the specified capacity.
    • Method Summary

      Modifier and Type Method and Description
      void add(float value)
       
      void addAll(float... array)
       
      void addAll(float[] array, int offset, int length)
       
      void addAll(FloatArray array)
       
      void addAll(FloatArray array, int offset, int length)
       
      void clear()
       
      boolean contains(float value)
       
      float[] ensureCapacity(int additionalCapacity)
      Increases the size of the backing array to accommodate the specified number of additional items.
      boolean equals(Object object)
       
      boolean equals(Object object, float epsilon)
       
      float first()
      Returns the first item.
      float get(int index)
       
      int hashCode()
       
      void incr(int index, float value)
       
      int indexOf(float value)
       
      void insert(int index, float value)
       
      int lastIndexOf(char value)
       
      void mul(int index, float value)
       
      float peek()
      Returns the last item.
      float pop()
      Removes and returns the last item.
      boolean removeAll(FloatArray array)
      Removes from this array all of elements contained in the specified array.
      float removeIndex(int index)
      Removes and returns the item at the specified index.
      void removeRange(int start, int end)
      Removes the items between the specified indices, inclusive.
      boolean removeValue(float value)
       
      protected float[] resize(int newSize)
       
      void reverse()
       
      void set(int index, float value)
       
      float[] setSize(int newSize)
      Sets the array size, leaving any values beyond the current size undefined.
      float[] shrink()
      Reduces the size of the backing array to the size of the actual items.
      void sort()
       
      void swap(int first, int second)
       
      float[] toArray()
       
      String toString()
       
      String toString(String separator)
       
      void truncate(int newSize)
      Reduces the size of the array to the specified size.
      static FloatArray with(float... array)
       
    • Field Detail

      • items

        public float[] items
      • size

        public int size
      • ordered

        public boolean ordered
    • Constructor Detail

      • FloatArray

        public FloatArray()
        Creates an ordered array with a capacity of 16.
      • FloatArray

        public FloatArray(int capacity)
        Creates an ordered array with the specified capacity.
      • FloatArray

        public FloatArray(boolean ordered,
                          int capacity)
        Parameters:
        ordered - If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
        capacity - Any elements added beyond this will cause the backing array to be grown.
      • FloatArray

        public FloatArray(FloatArray array)
        Creates a new array containing the elements in the specific array. The new array will be ordered if the specific array is ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
      • FloatArray

        public FloatArray(float[] array)
        Creates a new ordered array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
      • FloatArray

        public FloatArray(boolean ordered,
                          float[] array,
                          int startIndex,
                          int count)
        Creates a new array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
        Parameters:
        ordered - If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
    • Method Detail

      • add

        public void add(float value)
      • addAll

        public void addAll(FloatArray array,
                           int offset,
                           int length)
      • addAll

        public void addAll(float... array)
      • addAll

        public void addAll(float[] array,
                           int offset,
                           int length)
      • get

        public float get(int index)
      • set

        public void set(int index,
                        float value)
      • incr

        public void incr(int index,
                         float value)
      • mul

        public void mul(int index,
                        float value)
      • insert

        public void insert(int index,
                           float value)
      • swap

        public void swap(int first,
                         int second)
      • contains

        public boolean contains(float value)
      • indexOf

        public int indexOf(float value)
      • lastIndexOf

        public int lastIndexOf(char value)
      • removeValue

        public boolean removeValue(float value)
      • removeIndex

        public float removeIndex(int index)
        Removes and returns the item at the specified index.
      • removeRange

        public void removeRange(int start,
                                int end)
        Removes the items between the specified indices, inclusive.
      • removeAll

        public boolean removeAll(FloatArray array)
        Removes from this array all of elements contained in the specified array.
        Returns:
        true if this array was modified.
      • pop

        public float pop()
        Removes and returns the last item.
      • peek

        public float peek()
        Returns the last item.
      • first

        public float first()
        Returns the first item.
      • clear

        public void clear()
      • shrink

        public float[] shrink()
        Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.
        Returns:
        items
      • ensureCapacity

        public float[] ensureCapacity(int additionalCapacity)
        Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.
        Returns:
        items
      • setSize

        public float[] setSize(int newSize)
        Sets the array size, leaving any values beyond the current size undefined.
        Returns:
        items
      • resize

        protected float[] resize(int newSize)
      • sort

        public void sort()
      • reverse

        public void reverse()
      • truncate

        public void truncate(int newSize)
        Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.
      • toArray

        public float[] toArray()
      • hashCode

        public int hashCode()
      • equals

        public boolean equals(Object object)
      • equals

        public boolean equals(Object object,
                              float epsilon)
      • toString

        public String toString()