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

com.gs.fw.common.mithra.finder.ObjectWithMapperStack Maven / Gradle / Ivy

There is a newer version: 18.1.0
Show newest version
/*
 Copyright 2016 Goldman Sachs.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */

package com.gs.fw.common.mithra.finder;

import com.gs.fw.common.mithra.util.HashUtil;

import java.util.Map;



public class ObjectWithMapperStack implements Comparable
{

    private MapperStackImpl mapperStack = MapperStackImpl.EMPTY_MAPPER_STACK_IMPL;
    private E object;
    private int hashcode;

    public ObjectWithMapperStack(MapperStackImpl mapperStack, E object)
    {
        if (mapperStack != null)
        {
            this.mapperStack = mapperStack.isFullyEmpty() ? MapperStackImpl.EMPTY_MAPPER_STACK_IMPL : (MapperStackImpl)mapperStack.clone();
        }
        this.object = object;
    }

    public ObjectWithMapperStack(MapperStackImpl mapperStack, E object, Map stackPool)
    {
        MapperStackImpl clone = mapperStack.isFullyEmpty() ? MapperStackImpl.EMPTY_MAPPER_STACK_IMPL : stackPool.get(mapperStack);
        if (clone == null)
        {
            clone = (MapperStackImpl)mapperStack.clone();
            stackPool.put(clone, clone);
        }
        this.mapperStack = clone;
        this.object = object;
    }

    public MapperStackImpl getMapperStack()
    {
        return mapperStack;
    }

    public E getObject()
    {
        return object;
    }

    public void resetWithoutClone(MapperStackImpl mapperStack, E object)
    {
        this.mapperStack = mapperStack;
        this.object = object;
        hashcode = 0;
    }

    public ObjectWithMapperStack copyWithInternalClone(Map msiPool)
    {
        return new ObjectWithMapperStack(mapperStack, this.object, msiPool);
    }

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

        final ObjectWithMapperStack objectWithMapperStack = (ObjectWithMapperStack) o;

        if (mapperStack != objectWithMapperStack.mapperStack && !mapperStack.equals(objectWithMapperStack.mapperStack))
        {
            return false;
        }
        return object.equals(objectWithMapperStack.object);

    }

    public int hashCode()
    {
        if (hashcode == 0)
        {
            hashcode = HashUtil.combineHashes(mapperStack.hashCode(), object.hashCode());
        }
        return hashcode;
    }

    public int compareTo(Object o)
    {
        ObjectWithMapperStack other = (ObjectWithMapperStack) o;
        return this.mapperStack.compareTo(other.mapperStack);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy