Package com.diffplug.spotless
Class LazyForwardingEquality<T extends java.io.Serializable>
- java.lang.Object
-
- com.diffplug.spotless.LazyForwardingEquality<T>
-
- All Implemented Interfaces:
NoLambda
,java.io.Serializable
- Direct Known Subclasses:
FormatterStep.Strict
public abstract class LazyForwardingEquality<T extends java.io.Serializable> extends java.lang.Object implements java.io.Serializable, NoLambda
Implements equality, hashcode, and serialization entirely in terms of lazily-computed state. The state's serialized form is used to implement equals() and hashCode(), so you don't have to.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.diffplug.spotless.NoLambda
NoLambda.EqualityBasedOnSerialization
-
-
Constructor Summary
Constructors Constructor Description LazyForwardingEquality()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract T
calculateState()
This function is guaranteed to be called at most once.boolean
equals(java.lang.Object other)
int
hashCode()
protected T
state()
Returns the underlying state, possibly triggering a call to {calculateState()
.byte[]
toBytes()
Returns a byte array representation of everything inside thisSerializableFileFilter
.static void
unlazy(java.lang.Object in)
Ensures that the lazy state has been evaluated.
-
-
-
Method Detail
-
calculateState
protected abstract T calculateState() throws java.lang.Exception
This function is guaranteed to be called at most once. If the state is never required, then it will never be called at all. Throws exception because it's likely that there will be some IO going on.- Throws:
java.lang.Exception
-
state
protected final T state()
Returns the underlying state, possibly triggering a call to {calculateState()
.
-
toBytes
public byte[] toBytes()
Description copied from interface:NoLambda
Returns a byte array representation of everything inside thisSerializableFileFilter
. The main purpose of this method is to ensure one can't instantiate this class with lambda expressions, which are notoriously difficult to serialize and deserialize properly. (SeeSerializableFileFilterImpl.SkipFilesNamed
for an example of how to make a serializable subclass.)
-
equals
public final boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
unlazy
public static void unlazy(java.lang.Object in)
Ensures that the lazy state has been evaluated.
-
-