// Copyright 2016 The Domain Registry Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package google.registry.model.registry.label; import static com.google.common.base.Strings.emptyToNull; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import com.googlecode.objectify.annotation.Id; import google.registry.model.Buildable.GenericBuilder; import google.registry.model.ImmutableObject; /** * Represents a label entry parsed from a line in a Reserved List txt file. * * @param The type of the value stored for the domain label, e.g. {@link ReservationType}. */ public abstract class DomainLabelEntry, D extends DomainLabelEntry> extends ImmutableObject implements Comparable { @Id String label; String comment; /** * Returns the label of the field, which also happens to be used as the key for the Map object * that is serialized from Datastore. */ public String getLabel() { return label; } /** * Returns the value of the field (used for determining which entry takes priority over another). */ public abstract T getValue(); @Override @SuppressWarnings("unchecked") public int compareTo(D other) { return ((Comparable) getValue()).compareTo(other.getValue()); } /** A generic builder base. */ public abstract static class Builder, B extends Builder> extends GenericBuilder { public Builder() {} protected Builder(T instance) { super(instance); } public B setLabel(String label) { getInstance().label = label; return thisCastToDerived(); } public B setComment(String comment) { getInstance().comment = comment; return thisCastToDerived(); } @Override public T build() { checkArgumentNotNull(emptyToNull(getInstance().label), "Label must be specified"); checkArgumentNotNull(getInstance().getValue(), "Value must be specified"); return super.build(); } } }