Class Wrapper<V>

java.lang.Object
org.ujorm.tools.common.Wrapper<V>
Type Parameters:
V - Object value
All Implemented Interfaces:
Comparable<Wrapper<V>>, Confessionable

public final class Wrapper<V> extends Object implements 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 Details

    • getValue

      @NotNull public V getValue()
      Returns the original value
    • wrap

      public Wrapper<V> wrap(@NotNull V value)
      Create a new wrapper for the value
    • equals

      public boolean equals(@Nullable @Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(@Nullable @Nullable Wrapper<V> wrapper)
      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:
      compareTo in interface Comparable<V>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • confessTo

      public Appendable confessTo(Appendable writer) throws IOException
      Description copied from interface: Confessionable
      Confess data to a writer
      Specified by:
      confessTo in interface Confessionable
      Parameters:
      writer - An output sequence
      Returns:
      Return the argument object.
      Throws:
      IOException
    • of

      public static <D, P> Wrapper<D> of(@NotNull D value, @NotNull @NotNull Function<D,P>... functions)
      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