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

com.maxifier.mxcache.proxy.MxAbstractProxy Maven / Gradle / Ivy

Go to download

Constains all classes necessary for launching a MxCache-instrumentated application

There is a newer version: 2.6.9
Show newest version
/*
 * Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
 */
package com.maxifier.mxcache.proxy;

import javax.annotation.Nonnull;

import java.io.Serializable;

/**
 * @author Alexander Kochurov ([email protected])
 */
public class MxAbstractProxy> extends MxProxy implements Serializable {
    @Nonnull
    protected final C value;
    private final Class valueClass;
    private final Class containerClass;

    protected MxAbstractProxy(@Nonnull C value, Class valueClass, Class containerClass) {
        this.value = value;
        this.valueClass = valueClass;
        this.containerClass = containerClass;
    }

    @Override
    public String toString() {
        return "Proxy for <" + value.getValue() + ">";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof MxAbstractProxy)) {
            return false;
        }

        MxAbstractProxy that = (MxAbstractProxy) o;
        return containerClass == that.containerClass &&
                valueClass == that.valueClass &&
                value.getValue().equals(that.value.getValue());
    }

    @Override
    public int hashCode() {
        int result = value.getValue().hashCode();
        result = 31 * result + valueClass.hashCode();
        result = 31 * result + containerClass.hashCode();
        return result;
    }

    protected Object writeReplace() {
        return new WriteProxy(value, valueClass, containerClass);
    }

    @Nonnull
    @Override
    public C getValue() {
        return value;
    }

    //------------------------------------------------------------------------------------------------------------------

    private static final class WriteProxy> implements Serializable {
        private static final long serialVersionUID = 43218791L;

        @Nonnull
        private C container;
        private Class valueClass;
        private Class containerClass;

        /**
         * @deprecated for serialization only
         */
        @Deprecated
        public WriteProxy() {
        }

        public WriteProxy(@Nonnull C container, Class valueClass, Class containerClass) {
            this.container = container;
            this.valueClass = valueClass;
            this.containerClass = containerClass;
        }

        public Object readResolve() {
            return MxProxyGenerator.getProxyFactory(valueClass, containerClass).createProxy(container);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy