Skip to content

io microsphere collection UnmodifiableQueue

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

UnmodifiableQueue

Type: Class | Module: microsphere-java-core | Package: io.microsphere.collection | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/collection/UnmodifiableQueue.java

Overview

An unmodifiable view of a Queue. This implementation decorates a given queue and prevents any modification operations from succeeding. All mutation methods, such as #add, #remove, #offer, and others, throw an UnsupportedOperationException.

The behavior of this class is undefined if the underlying queue is modified directly while this view exists. It is intended to be used for creating immutable snapshots of queues where modification attempts are not allowed.

Example Usage

`Queue mutableQueue = new LinkedList<>();
mutableQueue.add("Hello");
Queue unmodifiableQueue = new UnmodifiableQueue<>(mutableQueue);
unmodifiableQueue.add("World"); // throws UnsupportedOperationException
 `

This class is serializable if the underlying queue is serializable.

Declaration

public class UnmodifiableQueue<E> implements Queue<E>, Serializable

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Queue<String> mutableQueue = new LinkedList<>();
mutableQueue.add("Hello");
Queue<String> unmodifiableQueue = new UnmodifiableQueue<>(mutableQueue);
unmodifiableQueue.add("World"); // throws UnsupportedOperationException

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.collection.UnmodifiableQueue;

API Reference

Public Methods

Method Description
size
isEmpty
contains
iterator
toArray
toArray
add
remove
offer
remove
poll
element
peek
containsAll
addAll
removeAll
removeIf
retainAll
clear
spliterator

See Also

  • Queue
  • CollectionUtils#unmodifiableIterator(Iterator)

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally