Class SequencedCollectionsExamples
java.lang.Object
net.jrodolfo.java_evolution.java21.SequencedCollectionsExamples
Demonstrates sequenced collections, introduced in Java 21.
Java had many ordered collections before Java 21, but there was no shared API
for first element, last element, or reversed views. Generic code had to know
whether it was dealing with a List, deque, ordered set, or ordered
map.
Sequenced collection interfaces give encounter-ordered data structures a
common vocabulary. The reversed() operation returns a reversed view
rather than requiring callers to make a defensive copy just to look at the
same data from the other direction.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCaptures direct observations fromSequencedMap.static final recordCaptures direct observations fromSequencedCollection.static final recordCaptures the state of a collection and its reversed view after a mutation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionObserves that a reversed view is backed by its original collection.Uses first and last entry operations fromSequencedMap.summarizeSequence(List<String> values) Uses first, last, and reversed operations fromSequencedCollection.
-
Constructor Details
-
SequencedCollectionsExamples
public SequencedCollectionsExamples()
-
-
Method Details
-
summarizeSequence
Uses first, last, and reversed operations fromSequencedCollection.- Parameters:
values- ordered values- Returns:
- a summary of sequence operations
-
observeReversedView
Observes that a reversed view is backed by its original collection.- Returns:
- the original and reversed collections after changing the view
-
summarizeMapOrder
Uses first and last entry operations fromSequencedMap.- Returns:
- a summary of map encounter order
-