类 Converter<A,B>
- 所有已实现的接口:
java.util.function.Function<A,B>
A to B with an associated reverse function from B
to A; used for converting back and forth between different representations of the same-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Returns a converter whoseconvertmethod appliessecondConverterto the result of this converter.final B已过时。final BReturns a representation ofaas an instance of typeB.convertAll(Iterable<? extends A> fromIterable) Returns an iterable that appliesconvertto each element offromIterable.protected abstract AdoBackward(B b) Returns a representation ofbas an instance of typeA.protected abstract BReturns a representation ofaas an instance of typeB.booleanIndicates 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> identity()Returns a serializable converter that always converts or reverses an object to itself.reverse()Returns the reversed view of this converter, which convertsthis.convert(a)back to a value roughly equivalent toa.从类继承的方法 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
Returns a representation ofaas an instance of typeB. Ifacannot be converted, an unchecked exception (such asIllegalArgumentException) should be thrown.- 参数:
a- the instance to convert; will never be null- 返回:
- the converted instance; must not be null
-
doBackward
Returns a representation ofbas an instance of typeA. Ifbcannot be converted, an unchecked exception (such asIllegalArgumentException) 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 aConverter<Chicken, ChickenNugget>), then this is not logically aConverterat all, and should just implementFunction.
-
convert
Returns a representation ofaas an instance of typeB.- 返回:
- the converted value; is null if and only if
ais null
-
convertAll
Returns an iterable that appliesconvertto each element offromIterable. The conversion is done lazily.The returned iterable's iterator supports
remove()if the input iterator does. After a successfulremove()call,fromIterableno longer contains the corresponding element. -
reverse
Returns the reversed view of this converter, which convertsthis.convert(a)back to a value roughly equivalent toa.The returned converter is serializable if
thisconverter is.Note: you should not override this method. It is non-final for legacy reasons.
-
andThen
Returns a converter whoseconvertmethod appliessecondConverterto the result of this converter. Itsreversemethod applies the converters in reverse order.The returned converter is serializable if
thisconverter andsecondConverterare. -
apply
已过时。Provided to satisfy theFunctioninterface; useconvert(A)instead. -
equals
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 returntruewheneverobjectis aConverterthat it considers interchangeable with this one. "Interchangeable" typically means thatObjects.equal(this.convert(a), that.convert(a))is true for allaof typeA(and similarly forreverse). Note that afalseresult from this method does not imply that the converters are known not to be interchangeable. -
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; subclassConverterand implement itsdoForward(A)anddoBackward(B)methods directly.These functions will never be passed
nulland must not under any circumstances returnnull. 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
Returns a serializable converter that always converts or reverses an object to itself.
-
Functioninterface; useconvert(A)instead.