001package gudusoft.gsqlparser.common.structured;
002
003import java.util.Objects;
004
005public final class StructuredMapType implements StructuredType {
006
007    private final StructuredType keyType;
008    private final StructuredType valueType;
009
010    public StructuredMapType(StructuredType keyType, StructuredType valueType) {
011        if (keyType == null || valueType == null) {
012            throw new IllegalArgumentException("keyType and valueType must not be null");
013        }
014        this.keyType = keyType;
015        this.valueType = valueType;
016    }
017
018    public StructuredType getKeyType() {
019        return keyType;
020    }
021
022    public StructuredType getValueType() {
023        return valueType;
024    }
025
026    @Override
027    public String toDisplayString() {
028        return "MAP<" + keyType.toDisplayString() + ", " + valueType.toDisplayString() + ">";
029    }
030
031    @Override
032    public boolean equals(Object o) {
033        if (this == o) return true;
034        if (!(o instanceof StructuredMapType)) return false;
035        StructuredMapType other = (StructuredMapType) o;
036        return keyType.equals(other.keyType) && valueType.equals(other.valueType);
037    }
038
039    @Override
040    public int hashCode() {
041        return Objects.hash("MAP", keyType, valueType);
042    }
043
044    @Override
045    public String toString() {
046        return toDisplayString();
047    }
048}