All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reactfx.util.WrapperBase Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version
package org.reactfx.util;

import java.util.Objects;

/**
 * Base class for value-based wrappers, that is wrappers that implement
 * {@link #equals(Object)} and {@link #hashCode()} solely by comparing/hashing
 * the wrapped values.
 * @param  type of the wrapped value.
 */
public abstract class WrapperBase {
    private final T delegate;

    /**
     * @param delegate wrapped value.
     */
    protected WrapperBase(T delegate) {
        if(delegate == null) {
            throw new IllegalArgumentException("delegate cannot be null");
        }
        this.delegate = delegate;
    }

    public final T getWrappedValue() {
        return delegate;
    }

    @Override
    public final boolean equals(Object that) {
        if(that instanceof WrapperBase) {
            return Objects.equals(
                    ((WrapperBase) that).delegate,
                    this.delegate);
        } else {
            return false;
        }
    }

    @Override
    public final int hashCode() {
        return delegate.hashCode();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy