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

com.eventsourcing.index.MultiValueAttribute Maven / Gradle / Ivy

/**
 * Copyright (c) 2016, All Contributors (see CONTRIBUTORS file)
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.eventsourcing.index;

import com.eventsourcing.Entity;
import com.eventsourcing.EntityHandle;
import com.googlecode.cqengine.query.option.QueryOptions;

public abstract class MultiValueAttribute
        extends com.googlecode.cqengine.attribute.MultiValueAttribute, A>
        implements Attribute {

    private Class objectType;
    private int cachedHashCode;

    @Override
    public int hashCode() {
        return cachedHashCode;
    }

    @Override public Class getEffectiveObjectType() {
        return objectType == null ? Attribute.readGenericObjectType(getClass(), getAttributeName()) : objectType;
    }

    public MultiValueAttribute() {
        super();
        cachedHashCode = calculateHashCode();
    }

    public MultiValueAttribute(String attributeName) {
        super(attributeName);
        cachedHashCode = calculateHashCode();
    }

    public MultiValueAttribute(Class objectType, Class> handleType, Class attributeType) {
        super(handleType, attributeType);
        this.objectType = objectType;
        cachedHashCode = calculateHashCode();
    }

    public MultiValueAttribute(Class objectType, Class> handleType, Class attributeType,
                               String attributeName) {
        super(handleType, attributeType, attributeName);
        this.objectType = objectType;
        cachedHashCode = calculateHashCode();
    }

    @Override public boolean equals(Object o) {
        return isEqual(o);
    }

    @Override
    public Iterable getValues(EntityHandle object, QueryOptions queryOptions) {
        return getValues(object.get(), queryOptions);
    }

    public abstract Iterable getValues(O object, QueryOptions queryOptions);

    @Override public boolean canEqual(Object other) {
        return other instanceof MultiValueAttribute;
    }

    @Override public String toString() {
        return "MultiValueAttribute{" +
                "objectType=" + getEffectiveObjectType() +
                ", attributeType=" + getAttributeType() +
                ", attributeName='" + getAttributeName() + '\'' +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy