@Override @Singleton public Location get() { String region = regionSupplier.get(); Predicate<Location> locationPredicate = region == null ? Predicates.<Location>or(isZone(), isRegion()) : isZoneOrRegionWhereRegionIdEquals(region); Set<? extends Location> locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); try { Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, transform(locations, ToIdAndScope.INSTANCE))); } } }
@Override @Singleton public Location get() { String region = regionSupplier.get(); Predicate<Location> locationPredicate = region == null ? Predicates.<Location>or(isZone(), isRegion()) : isZoneOrRegionWhereRegionIdEquals(region); Set<? extends Location> locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); try { Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, transform(locations, ToIdAndScope.INSTANCE))); } } }
@Override @Singleton public Location get() { String region = regionSupplier.get(); Predicate<Location> locationPredicate = region == null ? Predicates.<Location>or(isZone(), isRegion()) : isZoneOrRegionWhereRegionIdEquals(region); Set<? extends Location> locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); try { Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, transform(locations, ToIdAndScope.INSTANCE))); } } }
@Override @Singleton public Location get() { String region = regionSupplier.get(); Predicate<Location> locationPredicate = region == null ? Predicates.<Location>or(isZone(), isRegion()) : isZoneOrRegionWhereRegionIdEquals(region); Set<? extends Location> locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); try { Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, transform(locations, ToIdAndScope.INSTANCE))); } } }
@Override @Singleton public Location get() { String region = regionSupplier.get(); Predicate<Location> locationPredicate = region == null ? Predicates.<Location>or(isZone(), isRegion()) : isZoneOrRegionWhereRegionIdEquals(region); Set<? extends Location> locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); try { Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, transform(locations, ToIdAndScope.INSTANCE))); } } }
@Override @Singleton public Location get() { String region = regionSupplier.get(); Predicate<Location> locationPredicate = region == null ? Predicates.<Location>or(isZone(), isRegion()) : isZoneOrRegionWhereRegionIdEquals(region); Set<? extends Location> locations = locationsSupplier.get(); if (locationsSupplier.get().size() == 1) return getOnlyElement(locationsSupplier.get()); try { Location toReturn = Iterables.find(locations, locationPredicate); return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent(); } catch (NoSuchElementException e) { throw new NoSuchElementException(String.format("couldn't find region matching %s in %s", locationPredicate, transform(locations, ToIdAndScope.INSTANCE))); } } }