-
Notifications
You must be signed in to change notification settings - Fork 53
io microsphere collection QueueUtils
Type: Class | Module: microsphere-java-core | Package: io.microsphere.collection | Since: 1.0.0
Source:
microsphere-java-core/src/main/java/io/microsphere/collection/QueueUtils.java
The utilities class for Java Queue
public abstract class QueueUtils implements UtilsAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.1.10-SNAPSHOT
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 |
Queue<String> queue = new LinkedList<>();
boolean result = isQueue(queue); // returns true
List<String> list = new ArrayList<>();
result = isQueue(list); // returns falseboolean result = isQueue(LinkedList.class); // returns true
result = isQueue(ArrayList.class); // returns falseDeque<String> deque = new LinkedList<>();
boolean result = isDeque(deque); // returns true
List<String> list = new ArrayList<>();
result = isDeque(list); // returns falseQueue<String> empty = emptyQueue();
boolean isEmpty = empty.isEmpty(); // returns true
int size = empty.size(); // returns 0Deque<String> empty = emptyDeque();
boolean isEmpty = empty.isEmpty(); // returns true
int size = empty.size(); // returns 0Queue<String> mutableQueue = new LinkedList<>();
mutableQueue.add("Hello");
Queue<String> unmodifiable = unmodifiableQueue(mutableQueue);
unmodifiable.add("World"); // throws UnsupportedOperationExceptionDeque<String> mutableDeque = new LinkedList<>();
mutableDeque.add("Hello");
Deque<String> unmodifiable = unmodifiableDeque(mutableDeque);
unmodifiable.addFirst("World"); // throws UnsupportedOperationExceptionQueue<String> singleton = singletonQueue("Hello");
boolean isEmpty = singleton.isEmpty(); // returns false
int size = singleton.size(); // returns 1
String value = singleton.poll(); // returns "Hello"Deque<String> singleton = singletonDeque("Hello");
boolean isEmpty = singleton.isEmpty(); // returns false
int size = singleton.size(); // returns 1
String value = singleton.pollFirst(); // returns "Hello"Deque<String> deque = new LinkedList<>();
deque.addLast("A");
deque.addLast("B");
deque.addLast("C");
Deque<String> reversed = reversedDeque(deque);
String first = reversed.peekFirst(); // returns "C"
String last = reversed.peekLast(); // returns "A"
// Iterating through the reversed view
for (String value : reversed) {
System.out.println(value); // prints "C", "B", "A"
}Queue<String> queue = ofQueue("Hello", "World");
System.out.println(queue); // prints [Hello, World]
Queue<Integer> emptyQueue = ofQueue();
System.out.println(emptyQueue); // prints []
queue.add("Java"); // throws UnsupportedOperationExceptionArrayDeque<String> deque = newArrayDeque();
deque.add("Hello");
deque.add("World");
System.out.println(deque); // prints [Hello, World]ArrayDeque<String> deque = newArrayDeque(16);
deque.add("Hello");
deque.add("World");
System.out.println(deque); // prints [Hello, World]ArrayDeque<String> deque = newArrayDeque("Hello", "World");
System.out.println(deque); // prints [Hello, World]
ArrayDeque<Integer> emptyDeque = newArrayDeque();
System.out.println(emptyDeque); // prints []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 io.microsphere.collection.QueueUtils;| Method | Description |
|---|---|
isQueue |
Checks whether the specified Iterable is an instance of Queue. |
isQueue |
Checks whether the specified Class type is an instance of Queue. |
isDeque |
Checks whether the specified Iterable is an instance of Deque. |
emptyQueue |
Returns an empty immutable queue instance. |
emptyDeque |
Returns an empty immutable deque instance. |
unmodifiableQueue |
Returns an unmodifiable view of the given queue. |
unmodifiableDeque |
Returns an unmodifiable view of the given deque. |
singletonQueue |
Returns an immutable queue containing only the specified element. |
singletonDeque |
Returns an immutable deque containing only the specified element. |
reversedDeque |
Returns a reversed view of the specified deque. |
ofQueue |
Creates an immutable queue containing the specified elements. |
newArrayDeque |
Creates a new empty ArrayDeque instance. |
newArrayDeque |
Creates a new ArrayDeque instance with the specified initial capacity. |
newArrayDeque |
Creates a new ArrayDeque instance containing the specified elements. |
public static boolean isQueue(@Nullable Object values)Checks whether the specified Iterable is an instance of Queue.
`Queue queue = new LinkedList<>(); boolean result = isQueue(queue); // returns true List list = new ArrayList<>(); result = isQueue(list); // returns false `
public static boolean isQueue(@Nullable Class<?> type)Checks whether the specified Class type is an instance of Queue.
`boolean result = isQueue(LinkedList.class); // returns true result = isQueue(ArrayList.class); // returns false `
public static boolean isDeque(Iterable<?> values)Checks whether the specified Iterable is an instance of Deque.
`Deque deque = new LinkedList<>(); boolean result = isDeque(deque); // returns true List list = new ArrayList<>(); result = isDeque(list); // returns false `
public static <E> Queue<E> emptyQueue()Returns an empty immutable queue instance.
`Queue empty = emptyQueue(); boolean isEmpty = empty.isEmpty(); // returns true int size = empty.size(); // returns 0 `
public static <E> Deque<E> emptyDeque()Returns an empty immutable deque instance.
`Deque empty = emptyDeque(); boolean isEmpty = empty.isEmpty(); // returns true int size = empty.size(); // returns 0 `
public static <E> Queue<E> unmodifiableQueue(Queue<E> queue)Returns an unmodifiable view of the given queue.
This method wraps the provided queue in an UnmodifiableQueue, which prevents any modifications to the queue.
Any attempt to modify the returned queue will result in an UnsupportedOperationException.
`Queue mutableQueue = new LinkedList<>();
mutableQueue.add("Hello");
Queue unmodifiable = unmodifiableQueue(mutableQueue);
unmodifiable.add("World"); // throws UnsupportedOperationException
`
public static <E> Deque<E> unmodifiableDeque(Deque<E> deque)Returns an unmodifiable view of the given deque.
This method wraps the provided deque in an UnmodifiableDeque, which prevents any modifications to the deque.
Any attempt to modify the returned deque will result in an UnsupportedOperationException.
`Deque mutableDeque = new LinkedList<>();
mutableDeque.add("Hello");
Deque unmodifiable = unmodifiableDeque(mutableDeque);
unmodifiable.addFirst("World"); // throws UnsupportedOperationException
`
public static <E> Queue<E> singletonQueue(E element)Returns an immutable queue containing only the specified element.
The returned queue is a singleton instance that holds exactly one element. It is immutable,
so any attempt to modify the queue will result in an UnsupportedOperationException.
`Queue singleton = singletonQueue("Hello");
boolean isEmpty = singleton.isEmpty(); // returns false
int size = singleton.size(); // returns 1
String value = singleton.poll(); // returns "Hello"
`
public static <E> Deque<E> singletonDeque(E element)Returns an immutable deque containing only the specified element.
The returned deque is a singleton instance that holds exactly one element. It is immutable,
so any attempt to modify the deque will result in an UnsupportedOperationException.
`Deque singleton = singletonDeque("Hello");
boolean isEmpty = singleton.isEmpty(); // returns false
int size = singleton.size(); // returns 1
String value = singleton.pollFirst(); // returns "Hello"
`
public static <E> Deque<E> reversedDeque(Deque<E> deque)Returns a reversed view of the specified deque.
This method wraps the provided deque in a ReversedDeque, which presents the elements in reverse order.
Modifications to the original deque are reflected in the reversed view, and vice versa.
However, attempts to modify the reversed view may result in an UnsupportedOperationException
depending on the underlying implementation.
`Deque deque = new LinkedList<>();
deque.addLast("A");
deque.addLast("B");
deque.addLast("C");
Deque reversed = reversedDeque(deque);
String first = reversed.peekFirst(); // returns "C"
String last = reversed.peekLast(); // returns "A"
// Iterating through the reversed view
for (String value : reversed) {
System.out.println(value); // prints "C", "B", "A"
`
}
public static <E> Queue<E> ofQueue(E... elements)Creates an immutable queue containing the specified elements.
This method first creates a new ArrayDeque with the given elements and then wraps it
in an unmodifiable view using #unmodifiableQueue(Queue). The resulting queue is immutable,
so any attempt to modify it will result in an UnsupportedOperationException.
`Queue queue = ofQueue("Hello", "World");
System.out.println(queue); // prints [Hello, World]
Queue emptyQueue = ofQueue();
System.out.println(emptyQueue); // prints []
queue.add("Java"); // throws UnsupportedOperationException
`
public static <E> ArrayDeque<E> newArrayDeque()Creates a new empty ArrayDeque instance.
`ArrayDeque deque = newArrayDeque();
deque.add("Hello");
deque.add("World");
System.out.println(deque); // prints [Hello, World]
`
public static <E> ArrayDeque<E> newArrayDeque(int initialCapacity)Creates a new ArrayDeque instance with the specified initial capacity.
`ArrayDeque deque = newArrayDeque(16);
deque.add("Hello");
deque.add("World");
System.out.println(deque); // prints [Hello, World]
`
public static <E> ArrayDeque<E> newArrayDeque(E... elements)Creates a new ArrayDeque instance containing the specified elements.
`ArrayDeque deque = newArrayDeque("Hello", "World");
System.out.println(deque); // prints [Hello, World]
ArrayDeque emptyDeque = newArrayDeque();
System.out.println(emptyDeque); // prints []
`
Queue
This documentation was auto-generated from the source code of microsphere-java.
java-annotations
java-core
- ACLLoggerFactory
- AbstractArtifactResourceResolver
- AbstractConverter
- AbstractDeque
- AbstractEventDispatcher
- AbstractLogger
- AbstractURLClassPathHandle
- AccessibleObjectUtils
- AdditionalMetadataResourceConfigurationPropertyLoader
- AnnotationUtils
- ArchiveFileArtifactResourceResolver
- ArrayEnumeration
- ArrayStack
- ArrayUtils
- Artifact
- ArtifactDetector
- ArtifactResourceResolver
- Assert
- BannedArtifactClassLoadingExecutor
- BaseUtils
- BeanMetadata
- BeanProperty
- BeanUtils
- ByteArrayToObjectConverter
- CharSequenceComparator
- CharSequenceUtils
- CharsetUtils
- ClassDataRepository
- ClassDefinition
- ClassFileJarEntryFilter
- ClassFilter
- ClassLoaderUtils
- ClassPathResourceConfigurationPropertyLoader
- ClassPathUtils
- ClassUtils
- ClassicProcessIdResolver
- ClassicURLClassPathHandle
- CollectionUtils
- Compatible
- CompositeSubProtocolURLConnectionFactory
- CompositeURLStreamHandlerFactory
- ConditionalEventListener
- ConfigurationProperty
- ConfigurationPropertyGenerator
- ConfigurationPropertyLoader
- ConfigurationPropertyReader
- Configurer
- ConsoleURLConnection
- Constants
- ConstructorDefinition
- ConstructorUtils
- Converter
- Converters
- CustomizedThreadFactory
- DefaultConfigurationPropertyGenerator
- DefaultConfigurationPropertyReader
- DefaultDeserializer
- DefaultEntry
- DefaultSerializer
- DelegatingBlockingQueue
- DelegatingDeque
- DelegatingIterator
- DelegatingQueue
- DelegatingScheduledExecutorService
- DelegatingURLConnection
- DelegatingURLStreamHandlerFactory
- DelegatingWrapper
- Deprecation
- Deserializer
- Deserializers
- DirectEventDispatcher
- DirectoryFileFilter
- EmptyDeque
- EmptyIterable
- EmptyIterator
- EnumerationIteratorAdapter
- EnumerationUtils
- Event
- EventDispatcher
- EventListener
- ExceptionUtils
- ExecutableDefinition
- ExecutableUtils
- ExecutorUtils
- ExtendableProtocolURLStreamHandler
- FastByteArrayInputStream
- FastByteArrayOutputStream
- FieldDefinition
- FieldUtils
- FileChangedEvent
- FileChangedListener
- FileConstants
- FileExtensionFilter
- FileUtils
- FileWatchService
- Filter
- FilterOperator
- FilterUtils
- FormatUtils
- Functional
- GenericEvent
- GenericEventListener
- Handler
- Handler
- HierarchicalClassComparator
- IOFileFilter
- IOUtils
- ImmutableEntry
- IterableAdapter
- IterableUtils
- Iterators
- JDKLoggerFactory
- JSON
- JSONArray
- JSONException
- JSONObject
- JSONStringer
- JSONTokener
- JSONUtils
- JarEntryFilter
- JarUtils
- JavaType
- JmxUtils
- ListUtils
- Listenable
- Lists
- Logger
- LoggerFactory
- LoggingFileChangedListener
- MBeanAttribute
- MBeanAttributeInfoBuilder
- MBeanConstructorInfoBuilder
- MBeanDescribableBuilder
- MBeanExecutableInfoBuilder
- MBeanFeatureInfoBuilder
- MBeanInfoBuilder
- MBeanNotificationInfoBuilder
- MBeanOperationInfoBuilder
- MBeanParameterInfoBuilder
- ManagementUtils
- ManifestArtifactResourceResolver
- MapToPropertiesConverter
- MapUtils
- Maps
- MavenArtifact
- MavenArtifactResourceResolver
- MemberDefinition
- MemberUtils
- MetadataResourceConfigurationPropertyLoader
- MethodDefinition
- MethodHandleUtils
- MethodHandlesLookupUtils
- MethodUtils
- ModernProcessIdResolver
- ModernURLClassPathHandle
- Modifier
- MultiValueConverter
- MultipleType
- MutableInteger
- MutableURLStreamHandlerFactory
- NameFileFilter
- NoOpLogger
- NoOpLoggerFactory
- NoOpURLClassPathHandle
- NumberToByteConverter
- NumberToCharacterConverter
- NumberToDoubleConverter
- NumberToFloatConverter
- NumberToIntegerConverter
- NumberToLongConverter
- NumberToShortConverter
- NumberUtils
- ObjectToBooleanConverter
- ObjectToByteArrayConverter
- ObjectToByteConverter
- ObjectToCharacterConverter
- ObjectToDoubleConverter
- ObjectToFloatConverter
- ObjectToIntegerConverter
- ObjectToLongConverter
- ObjectToOptionalConverter
- ObjectToShortConverter
- ObjectToStringConverter
- PackageNameClassFilter
- PackageNameClassNameFilter
- ParallelEventDispatcher
- ParameterizedTypeImpl
- PathConstants
- Predicates
- Prioritized
- PriorityComparator
- ProcessExecutor
- ProcessIdResolver
- ProcessManager
- PropertiesToStringConverter
- PropertiesUtils
- PropertyConstants
- PropertyResourceBundleControl
- PropertyResourceBundleUtils
- ProtocolConstants
- ProxyUtils
- QueueUtils
- ReadOnlyIterator
- ReflectionUtils
- ReflectiveConfigurationPropertyGenerator
- ReflectiveDefinition
- ResourceConstants
- ReversedDeque
- Scanner
- SecurityUtils
- SeparatorConstants
- Serializer
- Serializers
- ServiceLoaderURLStreamHandlerFactory
- ServiceLoaderUtils
- ServiceLoadingURLClassPathHandle
- SetUtils
- Sets
- Sfl4jLoggerFactory
- ShutdownHookCallbacksThread
- ShutdownHookUtils
- SimpleClassScanner
- SimpleFileScanner
- SimpleJarEntryScanner
- SingletonDeque
- SingletonEnumeration
- SingletonIterator
- StackTraceUtils
- StandardFileWatchService
- StandardURLStreamHandlerFactory
- StopWatch
- StreamArtifactResourceResolver
- Streams
- StringBuilderWriter
- StringConverter
- StringDeserializer
- StringSerializer
- StringToArrayConverter
- StringToBlockingDequeConverter
- StringToBlockingQueueConverter
- StringToBooleanConverter
- StringToByteConverter
- StringToCharArrayConverter
- StringToCharacterConverter
- StringToClassConverter
- StringToCollectionConverter
- StringToDequeConverter
- StringToDoubleConverter
- StringToDurationConverter
- StringToFloatConverter
- StringToInputStreamConverter
- StringToIntegerConverter
- StringToIterableConverter
- StringToListConverter
- StringToLongConverter
- StringToMultiValueConverter
- StringToNavigableSetConverter
- StringToQueueConverter
- StringToSetConverter
- StringToShortConverter
- StringToSortedSetConverter
- StringToStringConverter
- StringToTransferQueueConverter
- StringUtils
- SubProtocolURLConnectionFactory
- SymbolConstants
- SystemUtils
- ThrowableAction
- ThrowableBiConsumer
- ThrowableBiFunction
- ThrowableConsumer
- ThrowableFunction
- ThrowableSupplier
- ThrowableUtils
- TrueClassFilter
- TrueFileFilter
- TypeArgument
- TypeFinder
- TypeUtils
- URLClassPathHandle
- URLUtils
- UnmodifiableDeque
- UnmodifiableIterator
- UnmodifiableQueue
- Utils
- ValueHolder
- Version
- VersionUtils
- VirtualMachineProcessIdResolver
- Wrapper
- WrapperProcessor
jdk-tools
lang-model
- AnnotatedElementJSONElementVisitor
- AnnotationUtils
- ClassUtils
- ConstructorUtils
- ElementUtils
- ExecutableElementComparator
- FieldUtils
- JSONAnnotationValueVisitor
- JSONElementVisitor
- LoggerUtils
- MemberUtils
- MessagerUtils
- MethodUtils
- ResolvableAnnotationValueVisitor
- StringAnnotationValue
- TypeUtils
annotation-processor
- ConfigurationPropertyAnnotationProcessor
- ConfigurationPropertyJSONElementVisitor
- FilerProcessor
- ResourceProcessor
java-test
- AbstractAnnotationProcessingTest
- Ancestor
- AnnotationProcessingTestProcessor
- ArrayTypeModel
- CollectionTypeModel
- Color
- CompilerInvocationInterceptor
- ConfigurationPropertyModel
- DefaultTestService
- GenericTestService
- MapTypeModel
- Model
- Parent
- PrimitiveTypeModel
- SimpleTypeModel
- StringArrayList
- TestAnnotation
- TestService
- TestServiceImpl