@Test(expectedExceptions = IllegalArgumentException.class) public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedZone() { NullEqualToIsParentOrIsGrandparentOfCurrentLocation predicate = new NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Suppliers.ofInstance(orphanedZone)); Hardware md = new HardwareBuilder().id("foo").location(region).build(); predicate.apply(md); }
@Override public boolean apply(ComputeMetadata input) { Location current = locationSupplier.get(); if (current == null) return true; if (input.getLocation() == null) return true; Location parent = current.getParent(); checkArgument( parent != null || current.getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; arg: %s", current); checkState( input.getLocation().getParent() != null || input.getLocation().getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; input: %s", input.getLocation()); Builder<Predicate<Location>> predicates = ImmutableSet.builder(); predicates.add(equalTo(current)); if (parent != null) { predicates.add(equalTo(parent)); Location grandparent = parent.getParent(); if (grandparent != null) predicates.add(equalTo(grandparent)); } return Predicates.or(predicates.build()).apply(input.getLocation()); }
NullEqualToIsParentOrIsGrandparentOfCurrentLocation implements Predicate<ComputeMetadata> { @Override public boolean apply(ComputeMetadata input) { Location current = locationSupplier.get(); if (current == null) return true; if (input.getLocation() == null) return true; Location parent = current.getParent(); checkArgument( parent != null || current.getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; arg: %s", current); checkState( input.getLocation().getParent() != null || input.getLocation().getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; input: %s", input.getLocation()); Builder<Predicate<Location>> predicates = ImmutableSet.builder(); predicates.add(equalTo(current)); if (parent != null) { predicates.add(equalTo(parent)); Location grandparent = parent.getParent(); if (grandparent != null) predicates.add(equalTo(grandparent)); } return Predicates.or(predicates.build()).apply(input.getLocation()); } }
NullEqualToIsParentOrIsGrandparentOfCurrentLocation implements Predicate<ComputeMetadata> { @Override public boolean apply(ComputeMetadata input) { Location current = locationSupplier.get(); if (current == null) return true; if (input.getLocation() == null) return true; Location parent = current.getParent(); checkArgument( parent != null || current.getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; arg: %s", current); checkState( input.getLocation().getParent() != null || input.getLocation().getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; input: %s", input.getLocation()); Builder<Predicate<Location>> predicates = ImmutableSet.builder(); predicates.add(equalTo(current)); if (parent != null) { predicates.add(equalTo(parent)); Location grandparent = parent.getParent(); if (grandparent != null) predicates.add(equalTo(grandparent)); } return Predicates.or(predicates.build()).apply(input.getLocation()); } NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Supplier<Location> locationSupplier); }
NullEqualToIsParentOrIsGrandparentOfCurrentLocation implements Predicate<ComputeMetadata> { @Override public boolean apply(ComputeMetadata input) { Location current = locationSupplier.get(); if (current == null) return true; if (input.getLocation() == null) return true; Location parent = current.getParent(); checkArgument( parent != null || current.getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; arg: %s", current); checkState( input.getLocation().getParent() != null || input.getLocation().getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; input: %s", input.getLocation()); Builder<Predicate<Location>> predicates = ImmutableSet.builder(); predicates.add(equalTo(current)); if (parent != null) { predicates.add(equalTo(parent)); Location grandparent = parent.getParent(); if (grandparent != null) predicates.add(equalTo(grandparent)); } return Predicates.or(predicates.build()).apply(input.getLocation()); } NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Supplier<Location> locationSupplier); @Override boolean apply(ComputeMetadata input); @Override String toString(); }
NullEqualToIsParentOrIsGrandparentOfCurrentLocation implements Predicate<ComputeMetadata> { @Override public boolean apply(ComputeMetadata input) { Location current = locationSupplier.get(); if (current == null) return true; if (input.getLocation() == null) return true; Location parent = current.getParent(); checkArgument( parent != null || current.getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; arg: %s", current); checkState( input.getLocation().getParent() != null || input.getLocation().getScope() == LocationScope.PROVIDER, "only locations of scope PROVIDER can have a null parent; input: %s", input.getLocation()); Builder<Predicate<Location>> predicates = ImmutableSet.builder(); predicates.add(equalTo(current)); if (parent != null) { predicates.add(equalTo(parent)); Location grandparent = parent.getParent(); if (grandparent != null) predicates.add(equalTo(grandparent)); } return Predicates.or(predicates.build()).apply(input.getLocation()); } NullEqualToIsParentOrIsGrandparentOfCurrentLocation(Supplier<Location> locationSupplier); @Override boolean apply(ComputeMetadata input); @Override String toString();  }