Package io.blt.util

Class Obj

java.lang.Object
io.blt.util.Obj

public final class Obj extends Object
Static utility methods for operating on Object.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    poke(T instance, Consumer<T> consumer)
    Passes the instance to the consumer, then returns the instance.
    static <T> T
    tap(Supplier<T> supplier, Consumer<T> consumer)
    Calls the supplier to retrieve an instance which is mutated by the consumer then returned.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • poke

      public static <T> T poke(T instance, Consumer<T> consumer)
      Passes the instance to the consumer, then returns the instance. e.g.
      
       var user = Obj.poke(new User(), u -> {
           u.setName("Greg");
           u.setAge(15);
       });
       
      Type Parameters:
      T - type of instance
      Parameters:
      instance - instance to consume and return
      consumer - operation to perform on instance
      Returns:
      instance after accepting side effects via consumer.
    • tap

      public static <T> T tap(Supplier<T> supplier, Consumer<T> consumer)
      Calls the supplier to retrieve an instance which is mutated by the consumer then returned. e.g.
      
       var user = Obj.tap(User::new, u -> {
           u.setName("Greg");
           u.setAge(15);
       });
       
      Type Parameters:
      T - type of instance
      Parameters:
      supplier - Supplies an instance to consume and return
      consumer - Operation to perform on supplied instance
      Returns:
      Supplied instance after applying side effects via consumer.