com.scalar.db.sql.common.ColumnDefinitionImpl Maven / Gradle / Ivy
package com.scalar.db.sql.common;
import com.google.common.base.MoreObjects;
import com.scalar.db.sql.ColumnDefinition;
import com.scalar.db.sql.DataType;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
public class ColumnDefinitionImpl implements ColumnDefinition {
@Nullable private final String namespaceName;
@Nullable private final String tableName;
private final String columnName;
private final DataType dataType;
ColumnDefinitionImpl(
@Nullable String namespaceName,
@Nullable String tableName,
String columnName,
DataType dataType) {
this.namespaceName = namespaceName;
this.tableName = tableName;
this.columnName = Objects.requireNonNull(columnName);
this.dataType = Objects.requireNonNull(dataType);
}
@Override
public Optional getNamespaceName() {
return Optional.ofNullable(namespaceName);
}
@Override
public Optional getTableName() {
return Optional.ofNullable(tableName);
}
@Override
public String getColumnName() {
return columnName;
}
@Override
public DataType getDataType() {
return dataType;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ColumnDefinitionImpl)) {
return false;
}
ColumnDefinitionImpl that = (ColumnDefinitionImpl) o;
return Objects.equals(getNamespaceName(), that.getNamespaceName())
&& Objects.equals(getTableName(), that.getTableName())
&& getColumnName().equals(that.getColumnName())
&& getDataType() == that.getDataType();
}
@Override
public int hashCode() {
return Objects.hash(getNamespaceName(), getTableName(), getColumnName(), getDataType());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("namespaceName", namespaceName)
.add("tableName", tableName)
.add("columnName", columnName)
.add("dataType", dataType)
.toString();
}
}