Top Description Inners Fields Constructors Methods
com.google.common.base

public abstract Class Converter<A, B>

extends Object
implements Function<A, B>
Class Inheritance
All Implemented Interfaces
com.google.common.base.Function, java.util.function.Function
Known Direct Subclasses
com.google.common.base.Converter.ReverseConverter, com.google.common.base.Converter.ConverterComposition, com.google.common.base.Converter.FunctionBasedConverter, com.google.common.base.Converter.IdentityConverter, com.google.common.base.Enums.StringConverter, com.google.common.collect.Maps.BiMapConverter, com.google.common.primitives.Doubles.DoubleConverter, com.google.common.primitives.Floats.FloatConverter, com.google.common.primitives.Ints.IntConverter, com.google.common.primitives.Longs.LongConverter, com.google.common.primitives.Shorts.ShortConverter, com.google.common.base.CaseFormat.StringConverter
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.NullnessCasts.uncheckedCastNullableTToT, .Preconditions.checkNotNull

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 information.

Invertibility

The reverse operation may be a strict inverse (meaning that converter.reverse().convert(converter.convert(a)).equals(a) is always true). However, it is very common (perhaps more common) for round-trip conversion to be lossy. Consider an example round-trip using com.google.common.primitives.Doubles#stringConverter:

  1. stringConverter().convert("1.00") returns the Double value 1.0
  2. stringConverter().reverse().convert(1.0) returns the string "1.0" -- not the same string ("1.00") we started with

Note that it should still be the case that the round-tripped and original objects are similar.

Nullability

A converter always converts null to null and non-null references to non-null references. It would not make sense to consider null and a non-null reference to be "different representations of the same information", since one is distinguishable from missing information and the other is not. The convert method handles this null behavior for all converters; implementations of doForward and doBackward are guaranteed to never be passed null, and must never return null.

Common ways to use

Getting a converter:

Using a converter:

Example

  return new Converter<Integer, String>() {
    protected String doForward(Integer i) {
      return Integer.toHexString(i);
    }

    protected Integer doBackward(String s) {
      return parseUnsignedInt(s, 16);
    }
  };

An alternative using Java 8:

return Converter.from(
    Integer::toHexString,
    s -> parseUnsignedInt(s, 16));
Authors
Mike Ward, Kurt Alfred Kluever, Gregory Kick
Since
16.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
Converter.IdentityConverter<T>

A converter that always converts or reverses an object to itself.

private static class

Field Summary

Modifier and TypeField and Description
private final boolean
private transient Converter<B, A>

Constructor Summary

AccessConstructor and Description
protected
Converter()

Constructor for use by subclasses.

pack-priv
Converter(boolean handleNullAutomatically)

Constructor used only by LegacyConverter to suspend automatic null-handling.

Method Summary

Modifier and TypeMethod and Description
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.

public final B
apply(A
the function argument
a
)

Implements com.google.common.base.Function.apply.

Deprecated Provided to satisfy the Function interface; use convert instead.
Applies this function to the given argument.
public final B

Returns:

the converted value; is null if and only if a is null
convert
(A a)

Returns a representation of a as an instance of type B.

public Iterable<B>
convertAll(Iterable<? extends A> fromIterable)

Returns an iterable that applies convert to each element of fromIterable.

pack-priv A
pack-priv B
pack-priv <C> Converter<A, C>
doAndThen(Converter<B, C> secondConverter)

Package-private non-final implementation of andThen() so only we can override it.

protected abstract A

Returns:

the converted instance; must not be null
doBackward
(B
the instance to convert; will never be null
b
)

Returns a representation of b as an instance of type A.

protected abstract B

Returns:

the converted instance; must not be null
doForward
(A
the instance to convert; will never be null
a
)

Returns a representation of a as an instance of type B.

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Implements com.google.common.base.Function.equals.

Indicates whether another object is equal to this converter.
public static <A, B> Converter<A, B>
from(Function<? super A, ? extends B> forwardFunction, Function<? super B, ? extends A> backwardFunction)

Returns a converter based on separate forward and backward functions.

public static <T> Converter<T, T>
identity()

Hides java.util.function.Function.identity.

Returns a serializable converter that always converts or reverses an object to itself.
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.

private A
private B
Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handleNullAutomaticallyback to summary
private final boolean handleNullAutomatically
reverseback to summary
private transient Converter<B, A> reverse
Annotations
@LazyInit
@RetainedWith
@CheckForNull

Constructor Detail

Converterback to summary
protected Converter()

Constructor for use by subclasses.

Converterback to summary
pack-priv Converter(boolean handleNullAutomatically)

Constructor used only by LegacyConverter to suspend automatic null-handling.

Method Detail

andThenback to summary
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.

applyback to summary
public final B apply(A a)

Implements com.google.common.base.Function.apply.

Doc from java.util.function.Function.apply.

Deprecated

Provided to satisfy the Function interface; use convert instead.

Applies this function to the given argument.

Parameters
a:A

the function argument

Returns:B

the function result

Annotations
@Deprecated
@Override
@InlineMe
replacement:this.convert(a)
convertback to summary
public final B convert(A a)

Returns a representation of a as an instance of type B.

Returns:B

the converted value; is null if and only if a is null

Annotations
@CheckForNull
convertAllback to summary
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.

correctedDoBackwardback to summary
pack-priv A correctedDoBackward(B b)
Annotations
@CheckForNull
correctedDoForwardback to summary
pack-priv B correctedDoForward(A a)
Annotations
@CheckForNull
doAndThenback to summary
pack-priv <C> Converter<A, C> doAndThen(Converter<B, C> secondConverter)

Package-private non-final implementation of andThen() so only we can override it.

doBackwardback to summary
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.

Parameters
b:B

the instance to convert; will never be null

Returns:A

the converted instance; must not be null

Annotations
@ForOverride
Exceptions
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.
doForwardback to summary
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.

Parameters
a:A

the instance to convert; will never be null

Returns:B

the converted instance; must not be null

Annotations
@ForOverride
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Implements com.google.common.base.Function.equals.

Indicates whether another object is equal to this converter.

Most implementations will have no reason to override the behavior of Object#equals. 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.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
fromback to summary
public static <A, B> Converter<A, B> from(Function<? super A, ? extends B> forwardFunction, 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 and doBackward 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.

Since
17.0
identityback to summary
public static <T> Converter<T, T> identity()

Hides java.util.function.Function.identity.

Returns a serializable converter that always converts or reverses an object to itself.

Parameters
<T>

Doc from java.util.function.Function.identity. the type of the input and output objects to the function

Returns:Converter<T, T>

Doc from java.util.function.Function.identity.

a function that always returns its input argument

Annotations
@SuppressWarnings:unchecked
reverseback to summary
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.

Annotations
@CheckReturnValue
unsafeDoBackwardback to summary
private A unsafeDoBackward(B b)
Annotations
@CheckForNull
unsafeDoForwardback to summary
private B unsafeDoForward(A a)
Annotations
@CheckForNull
com.google.common.base back to summary

private final Class Converter.ConverterComposition<A, B, C>

extends Converter<A, C>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
pack-priv final Converter<A, B>
pack-priv final Converter<B, C>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
ConverterComposition(Converter<A, B> first, Converter<B, C> second)

Method Summary

Modifier and TypeMethod and Description
pack-priv A
pack-priv C
protected A
doBackward(C
the instance to convert; will never be null
c
)

Implements abstract com.google.common.base.Converter.doBackward.

Returns a representation of b as an instance of type A.
protected C
doForward(A
the instance to convert; will never be null
a
)

Implements abstract com.google.common.base.Converter.doForward.

Returns a representation of a as an instance of type B.
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Indicates whether another object is equal to this converter.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.base.Converter:
andThenapplyconvertconvertAlldoAndThenfromidentityreverse

Field Detail

firstback to summary
pack-priv final Converter<A, B> first
secondback to summary
pack-priv final Converter<B, C> second
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ConverterCompositionback to summary
pack-priv ConverterComposition(Converter<A, B> first, Converter<B, C> second)

Method Detail

correctedDoBackwardback to summary
pack-priv A correctedDoBackward(C c)

Overrides com.google.common.base.Converter.correctedDoBackward.

Annotations
@Override
@CheckForNull
correctedDoForwardback to summary
pack-priv C correctedDoForward(A a)

Overrides com.google.common.base.Converter.correctedDoForward.

Annotations
@Override
@CheckForNull
doBackwardback to summary
protected A doBackward(C c)

Implements abstract com.google.common.base.Converter.doBackward.

Doc from com.google.common.base.Converter.doBackward.

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.

Parameters
c:C

the instance to convert; will never be null

Returns:A

the converted instance; must not be null

Annotations
@Override
doForwardback to summary
protected C doForward(A a)

Implements abstract com.google.common.base.Converter.doForward.

Doc from com.google.common.base.Converter.doForward.

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.

Parameters
a:A

the instance to convert; will never be null

Returns:C

the converted instance; must not be null

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Doc from com.google.common.base.Converter.equals.

Indicates whether another object is equal to this converter.

Most implementations will have no reason to override the behavior of Object#equals. 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.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.common.base back to summary

private final Class Converter.FunctionBasedConverter<A, B>

extends Converter<A, B>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final Function<? super B, ? extends A>
private final Function<? super A, ? extends B>

Constructor Summary

AccessConstructor and Description
private
FunctionBasedConverter(Function<? super A, ? extends B> forwardFunction, Function<? super B, ? extends A> backwardFunction)

Method Summary

Modifier and TypeMethod and Description
protected A
doBackward(B
the instance to convert; will never be null
b
)

Implements abstract com.google.common.base.Converter.doBackward.

Returns a representation of b as an instance of type A.
protected B
doForward(A
the instance to convert; will never be null
a
)

Implements abstract com.google.common.base.Converter.doForward.

Returns a representation of a as an instance of type B.
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Indicates whether another object is equal to this converter.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.base.Converter:
andThenapplyconvertconvertAllcorrectedDoBackwardcorrectedDoForwarddoAndThenfromidentityreverse

Field Detail

backwardFunctionback to summary
private final Function<? super B, ? extends A> backwardFunction
forwardFunctionback to summary
private final Function<? super A, ? extends B> forwardFunction

Constructor Detail

FunctionBasedConverterback to summary
private FunctionBasedConverter(Function<? super A, ? extends B> forwardFunction, Function<? super B, ? extends A> backwardFunction)

Method Detail

doBackwardback to summary
protected A doBackward(B b)

Implements abstract com.google.common.base.Converter.doBackward.

Doc from com.google.common.base.Converter.doBackward.

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.

Parameters
b:B

the instance to convert; will never be null

Returns:A

the converted instance; must not be null

Annotations
@Override
doForwardback to summary
protected B doForward(A a)

Implements abstract com.google.common.base.Converter.doForward.

Doc from com.google.common.base.Converter.doForward.

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.

Parameters
a:A

the instance to convert; will never be null

Returns:B

the converted instance; must not be null

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Doc from com.google.common.base.Converter.equals.

Indicates whether another object is equal to this converter.

Most implementations will have no reason to override the behavior of Object#equals. 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.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.common.base back to summary

private final Class Converter.IdentityConverter<T>

extends Converter<T, T>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

A converter that always converts or reverses an object to itself. Note that T is now a "pass-through type".

Field Summary

Modifier and TypeField and Description
pack-priv static final Converter.IdentityConverter<?>
private static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv <S> Converter<T, S>
doAndThen(Converter<T, S> otherConverter)

Overrides com.google.common.base.Converter.doAndThen.

Package-private non-final implementation of andThen() so only we can override it.
protected T
doBackward(T
the instance to convert; will never be null
t
)

Implements abstract com.google.common.base.Converter.doBackward.

Returns a representation of b as an instance of type A.
protected T
doForward(T
the instance to convert; will never be null
t
)

Implements abstract com.google.common.base.Converter.doForward.

Returns a representation of a as an instance of type B.
private Object
public Converter.IdentityConverter<T>
reverse()

Overrides com.google.common.base.Converter.reverse.

Returns the reversed view of this converter, which converts this.convert(a) back to a value roughly equivalent to a.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.base.Converter:
andThenapplyconvertconvertAllcorrectedDoBackwardcorrectedDoForwardequalsfromidentity

Field Detail

INSTANCEback to summary
pack-priv static final Converter.IdentityConverter<?> INSTANCE
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

IdentityConverterback to summary
private IdentityConverter()

Method Detail

doAndThenback to summary
pack-priv <S> Converter<T, S> doAndThen(Converter<T, S> otherConverter)

Overrides com.google.common.base.Converter.doAndThen.

Doc from com.google.common.base.Converter.doAndThen.

Package-private non-final implementation of andThen() so only we can override it.

Annotations
@Override
doBackwardback to summary
protected T doBackward(T t)

Implements abstract com.google.common.base.Converter.doBackward.

Doc from com.google.common.base.Converter.doBackward.

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.

Parameters
t:T

the instance to convert; will never be null

Returns:T

the converted instance; must not be null

Annotations
@Override
doForwardback to summary
protected T doForward(T t)

Implements abstract com.google.common.base.Converter.doForward.

Doc from com.google.common.base.Converter.doForward.

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.

Parameters
t:T

the instance to convert; will never be null

Returns:T

the converted instance; must not be null

Annotations
@Override
readResolveback to summary
private Object readResolve()
reverseback to summary
public Converter.IdentityConverter<T> reverse()

Overrides com.google.common.base.Converter.reverse.

Doc from com.google.common.base.Converter.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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.common.base back to summary

private final Class Converter.ReverseConverter<A, B>

extends Converter<B, A>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
pack-priv final Converter<A, B>
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
ReverseConverter(Converter<A, B> original)

Method Summary

Modifier and TypeMethod and Description
pack-priv B
pack-priv A
protected B
doBackward(A
the instance to convert; will never be null
a
)

Implements abstract com.google.common.base.Converter.doBackward.

Returns a representation of b as an instance of type A.
protected A
doForward(B
the instance to convert; will never be null
b
)

Implements abstract com.google.common.base.Converter.doForward.

Returns a representation of a as an instance of type B.
public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Indicates whether another object is equal to this converter.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public Converter<A, B>
reverse()

Overrides com.google.common.base.Converter.reverse.

Returns the reversed view of this converter, which converts this.convert(a) back to a value roughly equivalent to a.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.base.Converter:
andThenapplyconvertconvertAlldoAndThenfromidentity

Field Detail

originalback to summary
pack-priv final Converter<A, B> original
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ReverseConverterback to summary
pack-priv ReverseConverter(Converter<A, B> original)

Method Detail

correctedDoBackwardback to summary
pack-priv B correctedDoBackward(A a)

Overrides com.google.common.base.Converter.correctedDoBackward.

Annotations
@Override
@CheckForNull
correctedDoForwardback to summary
pack-priv A correctedDoForward(B b)

Overrides com.google.common.base.Converter.correctedDoForward.

Annotations
@Override
@CheckForNull
doBackwardback to summary
protected B doBackward(A a)

Implements abstract com.google.common.base.Converter.doBackward.

Doc from com.google.common.base.Converter.doBackward.

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.

Parameters
a:A

the instance to convert; will never be null

Returns:B

the converted instance; must not be null

Annotations
@Override
doForwardback to summary
protected A doForward(B b)

Implements abstract com.google.common.base.Converter.doForward.

Doc from com.google.common.base.Converter.doForward.

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.

Parameters
b:B

the instance to convert; will never be null

Returns:A

the converted instance; must not be null

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides com.google.common.base.Converter.equals.

Implements com.google.common.base.Function.equals.

Doc from com.google.common.base.Converter.equals.

Indicates whether another object is equal to this converter.

Most implementations will have no reason to override the behavior of Object#equals. 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.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
reverseback to summary
public Converter<A, B> reverse()

Overrides com.google.common.base.Converter.reverse.

Doc from com.google.common.base.Converter.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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override