SuggestLocationsResult: Assert for OK status in getLocations().

This commit is contained in:
Andreas Schildbach 2018-12-10 10:43:26 +01:00
parent 907d7f5ad6
commit 4e9ff4d9da

View file

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2015 the original author or authors. * Copyright the original author or authors.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,6 +18,7 @@
package de.schildbach.pte.dto; package de.schildbach.pte.dto;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -57,10 +58,10 @@ public final class SuggestLocationsResult implements Serializable {
} }
public List<Location> getLocations() { public List<Location> getLocations() {
checkState(status == Status.OK, "no locations with status: {}", status);
final List<Location> locations = new ArrayList<>(suggestedLocations.size()); final List<Location> locations = new ArrayList<>(suggestedLocations.size());
for (final SuggestedLocation location : suggestedLocations) for (final SuggestedLocation location : suggestedLocations)
locations.add(location.location); locations.add(location.location);
return locations; return locations;
} }