@Override public Maybe<String> getManagementPlaneIdMaybe() { return Maybe.ofDisallowingNull(managementPlaneId); }
/** Creates a new Maybe object using {@link #ofDisallowingNull(Object)} semantics. * It is recommended to use that method for clarity. * This method is provided for consistency with {@link Optional#fromNullable(Object)}. */ public static <T> Maybe<T> fromNullable(@Nullable T value) { return ofDisallowingNull(value); }
@Override public Maybe<URL> tryLoadFrom(ClassLoader classLoader, String name) { return Maybe.ofDisallowingNull(classLoader.getResource(name)); }
@Override public Maybe<URL> tryLoadFrom(BrooklynClassLoadingContext loader, String name) { return Maybe.ofDisallowingNull(loader.getResource(name)); }
@Override public Maybe<URL> tryLoadFrom(Bundle bundle, String name) { return Maybe.ofDisallowingNull(SystemFrameworkLoader.get().getResourceFromBundle(name, bundle)); }
@Test public void testMaybeDisallowingNull() { Maybe<Object> m = Maybe.ofDisallowingNull(null); try { m.get(); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "null"); } }
/** Validates that the given type matches the context (if supplied); * if not satisfied. returns an {@link Absent} if failed with details of the error, * with {@link Absent#isNull()} true if the object is null. */ public static Maybe<RegisteredType> tryValidate(RegisteredType item, final RegisteredTypeLoadingContext constraint) { // kept as a Maybe in case someone wants a wrapper around item validity; // unclear what the contract should be, as this can return Maybe.Present(null) // which is suprising, but it is more natural to callers otherwise they'll likely do a separate null check on the item // (often handling null different to errors) so the Maybe.get() is redundant as they have an object for the input anyway. if (item==null || constraint==null) return Maybe.ofDisallowingNull(item); if (constraint.getExpectedKind()!=null && !constraint.getExpectedKind().equals(item.getKind())) return Maybe.absent(item+" is not the expected kind "+constraint.getExpectedKind()); if (constraint.getExpectedJavaSuperType()!=null) { if (!isSubtypeOf(item, constraint.getExpectedJavaSuperType())) { return Maybe.absent(item+" is not for the expected type "+constraint.getExpectedJavaSuperType()); } } return Maybe.of(item); }
log.warn("When stopping {}, timed out after {} waiting for the machine to finish provisioning - machine may we left running", entity(), maxWait); machine = Maybe.ofDisallowingNull(entity().sensors().get(INTERNAL_PROVISIONED_MACHINE));