Class OpenCollectionException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenCollectionException extends OpenException
OpenCollectionException - Exception for collection operations OpenCollectionException - 集合操作异常

This exception is thrown when collection operations fail or encounter invalid states. Extends OpenException for unified exception handling across OpenCode components.

当集合操作失败或遇到无效状态时抛出此异常。继承 OpenException 以实现 OpenCode 组件间的统一异常处理。

Features | 主要功能:

  • Extends OpenException with component="Collections" - 继承 OpenException,组件名="Collections"
  • Wraps underlying exceptions - 包装底层异常
  • Provides meaningful error messages - 提供有意义的错误消息
  • Supports exception chaining - 支持异常链
  • Factory methods for common scenarios - 常见场景的工厂方法

Usage Examples | 使用示例:

// Throw with message - 带消息抛出
throw new OpenCollectionException("Collection is empty");

// Throw with cause - 带原因抛出
throw new OpenCollectionException("Operation failed", cause);

// Factory methods - 工厂方法
throw OpenCollectionException.emptyCollection("list");
throw OpenCollectionException.indexOutOfBounds(10, 5);
throw OpenCollectionException.duplicateKey("key1");

// Catch with unified OpenException - 使用统一 OpenException 捕获
try { ... } catch (OpenException e) { // catches all OpenCode exceptions }

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Serializable: Yes - 可序列化: 是
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenCollectionException

      public OpenCollectionException(String message)
      Constructs a new exception with the specified message. 构造带指定消息的新异常。
      Parameters:
      message - the detail message | 详细消息
    • OpenCollectionException

      public OpenCollectionException(String message, Throwable cause)
      Constructs a new exception with the specified message and cause. 构造带指定消息和原因的新异常。
      Parameters:
      message - the detail message | 详细消息
      cause - the cause | 原因
    • OpenCollectionException

      public OpenCollectionException(Throwable cause)
      Constructs a new exception with the specified cause. 构造带指定原因的新异常。
      Parameters:
      cause - the cause | 原因
  • Method Details

    • emptyCollection

      public static OpenCollectionException emptyCollection(String collectionType)
      Create exception for empty collection. 创建空集合异常。
      Parameters:
      collectionType - the type of collection | 集合类型
      Returns:
      new exception | 新异常
    • indexOutOfBounds

      public static OpenCollectionException indexOutOfBounds(int index, int size)
      Create exception for index out of bounds. 创建索引越界异常。
      Parameters:
      index - the invalid index | 无效索引
      size - the collection size | 集合大小
      Returns:
      new exception | 新异常
    • duplicateKey

      public static OpenCollectionException duplicateKey(Object key)
      Create exception for duplicate key. 创建重复键异常。
      Parameters:
      key - the duplicate key | 重复的键
      Returns:
      new exception | 新异常
    • duplicateValue

      public static OpenCollectionException duplicateValue(Object value)
      Create exception for duplicate value. 创建重复值异常。
      Parameters:
      value - the duplicate value | 重复的值
      Returns:
      new exception | 新异常
    • nullElement

      public static OpenCollectionException nullElement()
      Create exception for null element. 创建空元素异常。
      Returns:
      new exception | 新异常
    • nullKey

      public static OpenCollectionException nullKey()
      Create exception for null key. 创建空键异常。
      Returns:
      new exception | 新异常
    • nullValue

      public static OpenCollectionException nullValue()
      Create exception for null value. 创建空值异常。
      Returns:
      new exception | 新异常
    • immutableCollection

      public static OpenCollectionException immutableCollection()
      Create exception for immutable collection modification. 创建不可变集合修改异常。
      Returns:
      new exception | 新异常
    • elementNotFound

      public static OpenCollectionException elementNotFound(Object element)
      Create exception for element not found. 创建元素未找到异常。
      Parameters:
      element - the element | 元素
      Returns:
      new exception | 新异常
    • keyNotFound

      public static OpenCollectionException keyNotFound(Object key)
      Create exception for key not found. 创建键未找到异常。
      Parameters:
      key - the key | 键
      Returns:
      new exception | 新异常
    • illegalCapacity

      public static OpenCollectionException illegalCapacity(int capacity)
      Create exception for illegal capacity. 创建非法容量异常。
      Parameters:
      capacity - the illegal capacity | 非法容量
      Returns:
      new exception | 新异常
    • multipleElementsFound

      public static OpenCollectionException multipleElementsFound(int count)
      Create exception for multiple elements found when expecting one. 创建期望单个元素但找到多个异常。
      Parameters:
      count - the actual count | 实际数量
      Returns:
      new exception | 新异常
    • negativeSize

      public static OpenCollectionException negativeSize(int size)
      Create exception for negative size. 创建负数大小异常。
      Parameters:
      size - the negative size | 负数大小
      Returns:
      new exception | 新异常
    • unsupportedOperation

      public static OpenCollectionException unsupportedOperation(String operation)
      Create exception for unsupported operation. 创建不支持的操作异常。
      Parameters:
      operation - the operation name | 操作名称
      Returns:
      new exception | 新异常