Class FloatList

java.lang.Object
cloud.opencode.base.collections.primitive.FloatList
All Implemented Interfaces:
Serializable

public final class FloatList extends Object implements Serializable
FloatList - Primitive float List FloatList - 原始 float 列表

A resizable array implementation for primitive float values. Avoids boxing overhead of Float objects.

原始 float 值的可调整大小数组实现。避免 Float 对象的装箱开销。

Features | 主要功能:

  • No boxing overhead - 无装箱开销
  • Memory efficient - 内存高效
  • Random access - 随机访问
  • Resizable - 可调整大小

Usage Examples | 使用示例:

// Create empty - 创建空
FloatList list = FloatList.create();

// Create from values - 从值创建
FloatList list = FloatList.of(1.0f, 2.0f, 3.0f);

// Operations - 操作
list.add(10.5f);
float value = list.get(0);

// Statistics - 统计
float sum = list.sum();
float avg = list.average();

Performance | 性能特性:

  • get/set: O(1) - get/set: O(1)
  • add: O(1) amortized - add: O(1) 均摊
  • contains: O(n) - contains: O(n)

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: N/A (primitive) - 空值安全: 不适用(原始类型)
Since:
JDK 25, opencode-base-collections V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Functional interface for float consumer. float 消费者函数式接口。
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(float value)
    Add a value to the end of this list.
    void
    addAll(float... values)
    Add all values to the end of this list.
    float
    Return the average of all elements.
    void
    Clear this list.
    boolean
    contains(float value)
    Check if this list contains the value.
    static FloatList
    Create an empty FloatList.
    static FloatList
    create(int initialCapacity)
    Create a FloatList with initial capacity.
    boolean
     
    void
    Apply action to each element.
    static FloatList
    from(float[] array)
    Create a FloatList from a float array.
    static FloatList
    from(Collection<Float> collection)
    Create a FloatList from a Collection of Float.
    float
    get(int index)
    Get the element at the specified index.
    int
     
    int
    indexOf(float value)
    Return the index of the first occurrence of the value.
    boolean
    Check if this list is empty.
    float
    max()
    Return the maximum element.
    float
    min()
    Return the minimum element.
    static FloatList
    of(float... values)
    Create a FloatList from values.
    void
    Reverse the order of elements.
    float
    set(int index, float value)
    Set the element at the specified index.
    int
    Return the size of this list.
    void
    Sort the elements in ascending order.
    subList(int fromIndex, int toIndex)
    Return a sub-list view as a new FloatList.
    float
    sum()
    Return the sum of all elements.
    float[]
    Return all elements as a float array.
    Return all elements as a boxed List.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • create

      public static FloatList create()
      Create an empty FloatList. 创建空 FloatList。
      Returns:
      new FloatList | 新的 FloatList
    • create

      public static FloatList create(int initialCapacity)
      Create a FloatList with initial capacity. 创建指定初始容量的 FloatList。
      Parameters:
      initialCapacity - initial capacity | 初始容量
      Returns:
      new FloatList | 新的 FloatList
      Throws:
      IllegalArgumentException - if capacity is negative | 如果容量为负
    • of

      public static FloatList of(float... values)
      Create a FloatList from values. 从值创建 FloatList。
      Parameters:
      values - the values | 值
      Returns:
      new FloatList | 新的 FloatList
    • from

      public static FloatList from(float[] array)
      Create a FloatList from a float array. 从 float 数组创建 FloatList。
      Parameters:
      array - the source array | 源数组
      Returns:
      new FloatList | 新的 FloatList
    • from

      public static FloatList from(Collection<Float> collection)
      Create a FloatList from a Collection of Float. 从 Float 集合创建 FloatList。
      Parameters:
      collection - the source collection | 源集合
      Returns:
      new FloatList | 新的 FloatList
      Throws:
      NullPointerException - if collection contains null elements | 如果集合包含 null 元素
    • size

      public int size()
      Return the size of this list. 返回此列表的大小。
      Returns:
      the size | 大小
    • isEmpty

      public boolean isEmpty()
      Check if this list is empty. 检查此列表是否为空。
      Returns:
      true if empty | 如果为空则返回 true
    • get

      public float get(int index)
      Get the element at the specified index. 获取指定索引处的元素。
      Parameters:
      index - the index | 索引
      Returns:
      the element | 元素
      Throws:
      IndexOutOfBoundsException - if index is out of range | 如果索引超出范围
    • set

      public float set(int index, float value)
      Set the element at the specified index. 设置指定索引处的元素。
      Parameters:
      index - the index | 索引
      value - the new value | 新值
      Returns:
      the old value | 旧值
      Throws:
      IndexOutOfBoundsException - if index is out of range | 如果索引超出范围
    • add

      public void add(float value)
      Add a value to the end of this list. 向此列表末尾添加值。
      Parameters:
      value - the value | 值
    • addAll

      public void addAll(float... values)
      Add all values to the end of this list. 向此列表末尾添加所有值。
      Parameters:
      values - the values | 值
    • clear

      public void clear()
      Clear this list. 清空此列表。
    • contains

      public boolean contains(float value)
      Check if this list contains the value. 检查此列表是否包含该值。
      Parameters:
      value - the value | 值
      Returns:
      true if contains | 如果包含则返回 true
    • indexOf

      public int indexOf(float value)
      Return the index of the first occurrence of the value. 返回值首次出现的索引。
      Parameters:
      value - the value | 值
      Returns:
      the index, or -1 if not found | 索引,未找到则返回 -1
    • sum

      public float sum()
      Return the sum of all elements. 返回所有元素的和。
      Returns:
      the sum | 和
    • min

      public float min()
      Return the minimum element. 返回最小元素。
      Returns:
      the minimum | 最小值
      Throws:
      NoSuchElementException - if empty | 如果为空
    • max

      public float max()
      Return the maximum element. 返回最大元素。
      Returns:
      the maximum | 最大值
      Throws:
      NoSuchElementException - if empty | 如果为空
    • average

      public float average()
      Return the average of all elements. 返回所有元素的平均值。
      Returns:
      the average | 平均值
      Throws:
      NoSuchElementException - if empty | 如果为空
    • toFloatArray

      public float[] toFloatArray()
      Return all elements as a float array. 以 float 数组形式返回所有元素。
      Returns:
      the float array | float 数组
    • toList

      public List<Float> toList()
      Return all elements as a boxed List. 以装箱 List 形式返回所有元素。
      Returns:
      the boxed list | 装箱列表
    • sort

      public void sort()
      Sort the elements in ascending order. 按升序排序元素。
    • reverse

      public void reverse()
      Reverse the order of elements. 反转元素顺序。
    • subList

      public FloatList subList(int fromIndex, int toIndex)
      Return a sub-list view as a new FloatList. 返回子列表(新 FloatList)。
      Parameters:
      fromIndex - start index (inclusive) | 起始索引(包含)
      toIndex - end index (exclusive) | 结束索引(不包含)
      Returns:
      the sub-list | 子列表
      Throws:
      IndexOutOfBoundsException - if indices are out of range | 如果索引超出范围
    • forEach

      public void forEach(FloatList.FloatConsumer action)
      Apply action to each element. 对每个元素应用操作。
      Parameters:
      action - the action | 操作
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object