类 Converter<A,B>

java.lang.Object
com.alibaba.ageiport.common.function.Converter<A,B>
所有已实现的接口:
java.util.function.Function<A,B>

public abstract class Converter<A,B> extends Object implements java.util.function.Function<A,B>
A function from A to B with an associated reverse function from B to A; used for converting back and forth between different representations of the same
  • 构造器概要

    构造器
    限定符
    构造器
    说明
    protected
    Constructor for use by subclasses.
  • 方法概要

    修饰符和类型
    方法
    说明
    final <C> Converter<A,C>
    andThen(Converter<B,C> secondConverter)
    Returns a converter whose convert method applies secondConverter to the result of this converter.
    final B
    apply(A a)
    已过时。
    Provided to satisfy the Function interface; use convert(A) instead.
    final B
    Returns a representation of a as an instance of type B.
    convertAll(Iterable<? extends A> fromIterable)
    Returns an iterable that applies convert to each element of fromIterable.
    protected abstract A
    Returns a representation of b as an instance of type A.
    protected abstract B
    Returns a representation of a as an instance of type B.
    boolean
    equals(Object object)
    Indicates whether another object is equal to this converter.
    static <A, B> Converter<A,B>
    from(java.util.function.Function<? super A,? extends B> forwardFunction, java.util.function.Function<? super B,? extends A> backwardFunction)
    Returns a converter based on separate forward and backward functions.
    static <T> Converter<T,T>
    Returns a serializable converter that always converts or reverses an object to itself.
    Returns the reversed view of this converter, which converts this.convert(a) back to a value roughly equivalent to a.

    从类继承的方法 java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    从接口继承的方法 java.util.function.Function

    andThen, compose
  • 构造器详细资料

    • Converter

      protected Converter()
      Constructor for use by subclasses.
  • 方法详细资料

    • doForward

      protected abstract B doForward(A a)
      Returns a representation of a as an instance of type B. If a cannot be converted, an unchecked exception (such as IllegalArgumentException) should be thrown.
      参数:
      a - the instance to convert; will never be null
      返回:
      the converted instance; must not be null
    • doBackward

      protected abstract A doBackward(B b)
      Returns a representation of b as an instance of type A. If b cannot be converted, an unchecked exception (such as IllegalArgumentException) should be thrown.
      参数:
      b - the instance to convert; will never be null
      返回:
      the converted instance; must not be null
      抛出:
      UnsupportedOperationException - if backward conversion is not implemented; this should be very rare. Note that if backward conversion is not only unimplemented but unimplementable (for example, consider a Converter<Chicken, ChickenNugget>), then this is not logically a Converter at all, and should just implement Function.
    • convert

      public final B convert(A a)
      Returns a representation of a as an instance of type B.
      返回:
      the converted value; is null if and only if a is null
    • convertAll

      public Iterable<B> convertAll(Iterable<? extends A> fromIterable)
      Returns an iterable that applies convert to each element of fromIterable. The conversion is done lazily.

      The returned iterable's iterator supports remove() if the input iterator does. After a successful remove() call, fromIterable no longer contains the corresponding element.

    • reverse

      public Converter<B,A> reverse()
      Returns the reversed view of this converter, which converts this.convert(a) back to a value roughly equivalent to a.

      The returned converter is serializable if this converter is.

      Note: you should not override this method. It is non-final for legacy reasons.

    • andThen

      public final <C> Converter<A,C> andThen(Converter<B,C> secondConverter)
      Returns a converter whose convert method applies secondConverter to the result of this converter. Its reverse method applies the converters in reverse order.

      The returned converter is serializable if this converter and secondConverter are.

    • apply

      @Deprecated public final B apply(A a)
      已过时。
      Provided to satisfy the Function interface; use convert(A) instead.
      指定者:
      apply 在接口中 java.util.function.Function<A,B>
    • equals

      public boolean equals(Object object)
      Indicates whether another object is equal to this converter.

      Most implementations will have no reason to override the behavior of Object.equals(java.lang.Object). However, an implementation may also choose to return true whenever object is a Converter that it considers interchangeable with this one. "Interchangeable" typically means that Objects.equal(this.convert(a), that.convert(a)) is true for all a of type A (and similarly for reverse). Note that a false result from this method does not imply that the converters are known not to be interchangeable.

      覆盖:
      equals 在类中 Object
    • from

      public static <A, B> Converter<A,B> from(java.util.function.Function<? super A,? extends B> forwardFunction, java.util.function.Function<? super B,? extends A> backwardFunction)
      Returns a converter based on separate forward and backward functions. This is useful if the function instances already exist, or so that you can supply lambda expressions. If those circumstances don't apply, you probably don't need to use this; subclass Converter and implement its doForward(A) and doBackward(B) methods directly.

      These functions will never be passed null and must not under any circumstances return null. If a value cannot be converted, the function should throw an unchecked exception (typically, but not necessarily, IllegalArgumentException).

      The returned converter is serializable if both provided functions are.

      从以下版本开始:
      17.0
    • identity

      public static <T> Converter<T,T> identity()
      Returns a serializable converter that always converts or reverses an object to itself.