com.github.t3t5u.common.android.ColumnConstraint Maven / Gradle / Ivy
The newest version!
package com.github.t3t5u.common.android;
import org.apache.commons.lang3.StringUtils;
// http://www.sqlite.org/syntaxdiagrams.html#column-constraint
final class ColumnConstraint {
private final String name;
private final String value;
private ColumnConstraint(final String name, final String value) {
this.name = name;
this.value = value;
}
static ColumnConstraint newNotNull() {
return new ColumnConstraint("NOT NULL", null);
}
static ColumnConstraint newUnique() {
return new ColumnConstraint("UNIQUE", null);
}
static ColumnConstraint newDefault(final T value, final ColumnType type) {
return new ColumnConstraint("DEFAULT", value == null ? "NULL" : type.toString(value));
}
@Override
public boolean equals(final Object o) {
return (o instanceof ColumnConstraint) && name.equals(((ColumnConstraint>) o).name);
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public String toString() {
return name + (StringUtils.isBlank(value) ? "" : " " + value);
}
}