001package gudusoft.gsqlparser.dlineage.util;
002
003/**
004 * The lineage model's key for a name that is only meaningful inside a scope: a table alias inside
005 * one statement, a variable or cursor inside one routine. The scope and the name are kept apart as
006 * structure, never joined into one string, so no spelling of a name can collide with the text of a
007 * scope, and the name keeps the identity key the name service minted for it.
008 *
009 * <p>In-process only, like the keys it holds.</p>
010 */
011public final class ScopedNameKey {
012
013    private final Object scope;
014    private final Object name;
015
016    /**
017     * @param scope what the name is resolved in (a statement's hash, a routine's key); never null
018     * @param name the name's own identity key, as {@link DlineageUtil#tableNameKey} or a column key
019     *        gives it; never null
020     */
021    public ScopedNameKey(Object scope, Object name) {
022        if (scope == null) {
023            throw new IllegalArgumentException("scope");
024        }
025        if (name == null) {
026            throw new IllegalArgumentException("name");
027        }
028        this.scope = scope;
029        this.name = name;
030    }
031
032    public Object getScope() {
033        return scope;
034    }
035
036    public Object getName() {
037        return name;
038    }
039
040    @Override
041    public boolean equals(Object o) {
042        if (this == o) {
043            return true;
044        }
045        if (!(o instanceof ScopedNameKey)) {
046            return false;
047        }
048        ScopedNameKey other = (ScopedNameKey) o;
049        return scope.equals(other.scope) && name.equals(other.name);
050    }
051
052    @Override
053    public int hashCode() {
054        return 31 * scope.hashCode() + name.hashCode();
055    }
056
057    @Override
058    public String toString() {
059        return scope + " / " + name;
060    }
061}