Convert ChangeTriplet to @AutoValue

Instead of throwing an exception when parsing fails, use Optional.

Change-Id: I124eb2717ae625c6a0cbd4739ae0600236cfc11d
This commit is contained in:
Dave Borowitz
2014-12-10 07:51:20 -08:00
parent af4b19079d
commit 665e7bda73
2 changed files with 40 additions and 34 deletions

View File

@@ -20,6 +20,7 @@ import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;
@@ -560,15 +561,14 @@ public class ChangeUtil {
}
// Try change triplet
ChangeTriplet triplet;
try {
triplet = new ChangeTriplet(id);
} catch (ChangeTriplet.ParseException e) {
throw new ResourceNotFoundException(id);
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id);
if (triplet.isPresent()) {
return db.get().changes().byBranchKey(
triplet.get().branch(),
triplet.get().id()).toList();
}
return db.get().changes().byBranchKey(
triplet.getBranchNameKey(),
triplet.getChangeKey()).toList();
throw new ResourceNotFoundException(id);
}
private IdentifiedUser user() {