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

se.fortnox.reactivewizard.util.CompoundKey Maven / Gradle / Ivy

There is a newer version: 24.6.0
Show newest version
package se.fortnox.reactivewizard.util;

import java.util.Objects;

/**
 * Utility class for keys that consist of multiple values.
 * Usable for things like cache keys etc.
 */
public class CompoundKey {
    private Object[] keys;

    public CompoundKey(Object... keys) {
        this.keys = keys;
    }

    @Override
    public int hashCode() {
        final int prime  = 31;
        int       result = 1;
        for (Object k : keys) {
            result = result * prime + (k == null ? 0 : k.hashCode());
        }
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof CompoundKey)) {
            return false;
        }
        CompoundKey other = (CompoundKey)obj;

        if (other.keys.length != keys.length) {
            return false;
        }

        for (int i = 0; i < keys.length; i++) {
            if (!Objects.equals(keys[i], other.keys[i])) {
                return false;
            }
        }

        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy