uk.org.lidalia.lang.RichObject Maven / Gradle / Ivy
package uk.org.lidalia.lang;
import java.lang.reflect.Field;
import java.security.PrivilegedAction;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import static com.google.common.base.Optional.fromNullable;
import static java.security.AccessController.doPrivileged;
import static java.util.Arrays.asList;
import static uk.org.lidalia.lang.Classes.inSameClassHierarchy;
import static uk.org.lidalia.lang.Exceptions.throwUnchecked;
/**
* A class that provides implementations of {@link #equals(Object)}, {@link #hashCode()} and {@link #toString()} for its subtypes.
*
* These implementations are based on annotating the fields of the subtypes with the {@link Identity} annotation.
*/
public abstract class RichObject {
private static final int PRIME = 37;
private static final int INITIAL_HASHCODE_VALUE = 17;
private static final LoadingCache, FluentIterable> IDENTITY_FIELDS =
CacheBuilder.newBuilder().weakKeys().softValues().build(new IdentityFieldLoader());
private static final Joiner FIELD_JOINER = Joiner.on(",");
private static final Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy