Package org.ujorm.tools.common
Class Wrapper<V>
java.lang.Object
org.ujorm.tools.common.Wrapper<V>
- Type Parameters:
V- Object value
- All Implemented Interfaces:
Comparable<Wrapper<V>>,Confessionable
The wrapper implements a common
hash(), equals() and compareTo() methods
Usage:
Person p1 = new Person(1, "A"); Person p2 = new Person(1, "B"); Wrapper<Person> w1 = Wrapper.of(p1, Person::getId, Person::getName); Wrapper<Person> w2 = w1.wrap(p2); assertTrue(w1.compareTo(w2) < 0);
- Author:
- Pavel Ponec
-
Method Summary
Modifier and TypeMethodDescriptionintCompares this object with the specified object for order.confessTo(Appendable writer) Confess data to a writerbooleangetValue()Returns the original valueinthashCode()static <D,P> Wrapper<D> Create a new wrapperstatic <D,P> Wrapper<D> Create a new wrappertoString()Create a new wrapper for the value
-
Method Details
-
getValue
Returns the original value -
wrap
Create a new wrapper for the value -
equals
-
hashCode
public int hashCode() -
compareTo
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareToin interfaceComparable<V>
-
toString
-
confessTo
Description copied from interface:ConfessionableConfess data to a writer- Specified by:
confessToin interfaceConfessionable- Parameters:
writer- An output sequence- Returns:
- Return the argument object.
- Throws:
IOException
-
of
Create a new wrapper -
of
public static <D,P> Wrapper<D> of(@NotNull D value, boolean nullFirst, @NotNull @NotNull Function<D, P>... functions) Create a new wrapper
-