-
Notifications
You must be signed in to change notification settings - Fork 0
Helper classes
Dokkaltek edited this page Apr 11, 2025
·
1 revision
There are a few helper classes that aim to aid you acting as wrappers for other elements.
This class acts as the Pair<> class in Spring, and holds 2 different objects of your choice. It can be useful when you need to return 2 objects from a method.
Unlike Spring Boot Pair class, you can add nulls to the Duo using Duo.ofNullable(), but by default it won't allow nulls if using Duo.of()
Pretty much the same as Duo but for 3 objects instead of 2.
This is a wrapper over an ArrayList that has some syntax sugar methods, like:
-
first()
-> Obtains the first element. -
last()
-> Obtains the last element. -
lastIndex()
-> Obtains the index of the last element (same as list.length - 1) -
addToHead(T)
-> Adds the element as the first of the list, and moves all other elements after. -
removeFirst(T)
-> Removes the first element of the list. -
removeLast(T)
-> Removes the last element of the list. -
filter(Predicate)
-> Keeps the elements that match a predicate. -
findFirstMatch(Predicate)
-> Finds the first element that matches the predicate. -
map(Function)
-> Uses an iterator to map the elements of the list. -
mapToStream(Function>
-> Performs the mapping and returns a Stream. -
reduce(BinaryOperator<T>)
-> Reduces the entries to one using the Streams API.
You also have a few constructors, but also convenience ones like:
-
WrapperList.of("some", "elements", "here")
-> Creates a WrapperList of the given elements. Similar to Java 11 List.of(), but it returns a mutable list here. -
WrapperList.from(anotherList)
-> Returns a list of fixed size with the initial size of the old list.