OptionalUtil { public static OptionalLong ofNullable(Long l) { if (l == null) { return OptionalLong.empty(); } else { return OptionalLong.of(l); } } private  OptionalUtil(); static Object unwrap(Object potentiallyOptional); static T unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<T> optional); static Integer unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalInt optional); static Boolean unwrap(OptionalBoolean optional); static Long unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalLong optional); static Double unwrap(@SuppressWarnings("OptionalUsedAsFieldOrParameterType") OptionalDouble optional); static OptionalLong ofNullable(Long l); static OptionalInt ofNullable(Integer i); static OptionalDouble ofNullable(Double d); static OptionalBoolean ofNullable(Boolean b); static OptionalLong parseLong(String value); static OptionalInt parseInt(String value); static OptionalDouble parseDouble(String value); static OptionalBoolean parseBoolean(String value);  }
@Test void ofNullable() { assertTrue(OptionalUtil.ofNullable(1L).isPresent()); assertTrue(OptionalUtil.ofNullable(1).isPresent()); assertTrue(OptionalUtil.ofNullable(1d).isPresent()); assertTrue(OptionalUtil.ofNullable(true).isPresent()); assertFalse(OptionalUtil.ofNullable((Long) null).isPresent()); assertFalse(OptionalUtil.ofNullable((Integer) null).isPresent()); assertFalse(OptionalUtil.ofNullable((Double) null).isPresent()); assertFalse(OptionalUtil.ofNullable((Boolean) null).isPresent()); }