001package gudusoft.gsqlparser.common.structured; 002 003import java.util.Objects; 004 005public final class StructuredStructField { 006 007 private final String name; 008 private final StructuredType type; 009 private final boolean nullable; 010 011 public StructuredStructField(String name, StructuredType type) { 012 this(name, type, true); 013 } 014 015 public StructuredStructField(String name, StructuredType type, boolean nullable) { 016 if (name == null || name.isEmpty()) { 017 throw new IllegalArgumentException("name must be non-empty"); 018 } 019 if (type == null) { 020 throw new IllegalArgumentException("type must not be null"); 021 } 022 this.name = name; 023 this.type = type; 024 this.nullable = nullable; 025 } 026 027 public String getName() { 028 return name; 029 } 030 031 public StructuredType getType() { 032 return type; 033 } 034 035 public boolean isNullable() { 036 return nullable; 037 } 038 039 @Override 040 public boolean equals(Object o) { 041 if (this == o) return true; 042 if (!(o instanceof StructuredStructField)) return false; 043 StructuredStructField other = (StructuredStructField) o; 044 return nullable == other.nullable && name.equals(other.name) && type.equals(other.type); 045 } 046 047 @Override 048 public int hashCode() { 049 return Objects.hash(name, type, nullable); 050 } 051 052 @Override 053 public String toString() { 054 return name + ": " + type.toDisplayString(); 055 } 056}