Remove UNRESERVED as a reservation type

This is a follow-up to Lai's refactoring of the get reservation types
code to return a set rather than a single type. Since we're always
returning a set now, the more natural way to represent a label that is
not reserved is to return an empty set rather than a set containing
UNRESERVED.

Also fixes some minor style issues I ran across regarding static
importing and test method naming that I ran across (no logic
implications).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151132116
This commit is contained in:
mcilwain 2017-03-24 09:09:06 -07:00 committed by Ben McIlwain
parent 4260fb573f
commit b03bd3b525
12 changed files with 83 additions and 90 deletions

View file

@ -25,7 +25,6 @@ import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
import static google.registry.model.registry.label.ReservationType.NAMESERVER_RESTRICTED;
import static google.registry.model.registry.label.ReservationType.RESERVED_FOR_ANCHOR_TENANT;
import static google.registry.model.registry.label.ReservationType.UNRESERVED;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.joda.time.DateTimeZone.UTC;
@ -37,9 +36,9 @@ import com.google.common.base.Splitter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.net.InternetDomainName;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.googlecode.objectify.Key;
@ -211,27 +210,25 @@ public final class ReservedList
}
/**
* Queries the set of all reserved lists associated with the specified tld and returns the
* reservation types of the label. If the label is in none of the lists, it returns a set that
* contains UNRESERVED.
* Queries the set of all reserved lists associated with the specified TLD and returns the
* reservation types of the label.
*
* <p>If the label is in none of the lists, it returns an empty set.
*/
public static ImmutableSet<ReservationType> getReservationTypes(String label, String tld) {
checkNotNull(label, "label");
if (label.length() == 0) {
return ImmutableSet.of(FULLY_BLOCKED);
}
ImmutableSet<ReservedListEntry> entries = getReservedListEntries(label, tld);
return entries.isEmpty()
? ImmutableSet.of(UNRESERVED)
: ImmutableSet.copyOf(
Iterables.transform(
entries,
new Function<ReservedListEntry, ReservationType>() {
@Override
public ReservationType apply(ReservedListEntry reservedListEntry) {
return reservedListEntry.reservationType;
}
}));
return FluentIterable.from(getReservedListEntries(label, tld))
.transform(
new Function<ReservedListEntry, ReservationType>() {
@Override
public ReservationType apply(ReservedListEntry reservedListEntry) {
return reservedListEntry.reservationType;
}
})
.toSet();
}
/**