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

it.bz.opendatahub.alpinebits.middleware.Key Maven / Gradle / Ivy

The newest version!
// SPDX-FileCopyrightText: NOI Techpark 
//
// SPDX-License-Identifier: MPL-2.0

/*
 * 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 it.bz.opendatahub.alpinebits.middleware;

import java.util.Objects;

/**
 * This class implementats for {@link Context} keys.
 *
 * @param  type of the key
 */
public final class Key {
    private final String identifier;
    private final Class type;

    private Key(String identifier, Class type) {
        this.identifier = identifier;
        this.type = type;
    }

    /**
     * This method simplifies key building. It just wraps the
     * new Key(String, Class) call.
     * @param identifier key identifier
     * @param type key type
     * @return the key, created with the given parameters
     */
    public static  Key key(String identifier, Class type) {
        return new Key<>(identifier, type);
    }

    /**
     * Get the identifier of the key.
     *
     * @return identifier of the key
     */
    public String getIdentifier() {
        return identifier;
    }

    /**
     * Get the type of the key.
     *
     * @return type of the key
     */
    public Class getType() {
        return type;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Key key = (Key) o;
        return Objects.equals(identifier, key.identifier) &&
                Objects.equals(type, key.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(identifier, type);
    }

    @Override
    public String toString() {
        return "Key{" +
                "identifier='" + identifier + '\'' +
                ", type=" + type +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy