Java Code Examples for java8.util.Optional#ofNullable()
The following examples show how to use
java8.util.Optional#ofNullable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddFeatureDialogFragment.java From ground-android with Apache License 2.0 | 6 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); // TODO: Inject and use custom factory. Optional<Project> activeProject = Loadable.getValue(homeScreenViewModel.getActiveProject()); if (!activeProject.isPresent()) { addFeatureRequestSubject.onError(new IllegalStateException("No active project")); return fail("Could not get active project"); } Optional<Point> cameraPosition = Optional.ofNullable(mapContainerViewModel.getCameraPosition().getValue()); if (!cameraPosition.isPresent()) { addFeatureRequestSubject.onError(new IllegalStateException("No camera position")); return fail("Could not get camera position"); } return createDialog(activeProject.get(), cameraPosition.get()); }
Example 2
Source File: MatrixJsonRoomTopicEvent.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<String> getTopic() { return Optional.ofNullable(content.getTopic()); }
Example 3
Source File: Collectors.java From streamsupport with GNU General Public License v2.0 | 4 votes |
/** * Returns a {@code Collector} which performs a reduction of its * input elements under a specified {@code BinaryOperator}. The result * is described as an {@code Optional<T>}. * * <p><b>API Note:</b><br> * The {@code reducing()} collectors are most useful when used in a * multi-level reduction, downstream of {@code groupingBy} or * {@code partitioningBy}. To perform a simple reduction on a stream, * use {@link Stream#reduce(BinaryOperator)} instead. * * <p>For example, given a stream of {@code Person}, to calculate tallest * person in each city: * <pre>{@code * Comparator<Person> byHeight = Comparator.comparing(Person::getHeight); * Map<City, Optional<Person>> tallestByCity * = people.stream().collect(groupingBy(Person::getCity, reducing(BinaryOperator.maxBy(byHeight)))); * }</pre> * * @param <T> element type for the input and output of the reduction * @param op a {@code BinaryOperator<T>} used to reduce the input elements * @return a {@code Collector} which implements the reduction operation * * @see #reducing(Object, BinaryOperator) * @see #reducing(Object, Function, BinaryOperator) */ public static <T> Collector<T, ?, Optional<T>> reducing(BinaryOperator<T> op) { class OptionalBox implements Consumer<T> { T value = null; boolean present = false; @Override public void accept(T t) { if (present) { value = op.apply(value, t); } else { value = t; present = true; } } } return new CollectorImpl<T, OptionalBox, Optional<T>>( OptionalBox::new, OptionalBox::accept, (a, b) -> { if (b.present) a.accept(b.value); return a; }, a -> Optional.ofNullable(a.value), CH_NOID); }
Example 4
Source File: RoomCreationOptions.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Boolean> isGuestCanJoin() { return Optional.ofNullable(guestCanJoin); }
Example 5
Source File: MatrixJsonRoomPowerLevelsEvent.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Double> getUsersDefault() { return Optional.ofNullable(content.getUsersDefault()); }
Example 6
Source File: RoomCreationOptions.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<String> getTopic() { return Optional.ofNullable(topic); }
Example 7
Source File: RoomCreationOptions.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Boolean> isDirect() { return Optional.ofNullable(isDirect); }
Example 8
Source File: MatrixJsonRoomPowerLevelsEvent.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Double> getKick() { return Optional.ofNullable(content.getKick()); }
Example 9
Source File: GsonUtil.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
public static Optional<JsonElement> findElement(JsonObject o, String key) { return Optional.ofNullable(o.get(key)); }
Example 10
Source File: MatrixJsonRoomPowerLevelsEvent.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Double> getEventsDefault() { return Optional.ofNullable(content.getEventsDefault()); }
Example 11
Source File: MatrixHttpClient.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<String> getDeviceId() { return Optional.ofNullable(context.getDeviceId()); }
Example 12
Source File: GeoJsonGeometry.java From ground-android with Apache License 2.0 | 4 votes |
public Optional<JSONObject> getJson() { return Optional.ofNullable(json.optJSONObject(GEOMETRY_KEY)); }
Example 13
Source File: MatrixJsonRoomNameEvent.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<String> getName() { return Optional.ofNullable(content.getName()); }
Example 14
Source File: RoomCreationOptions.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Set<_MatrixID>> getInvites() { return Optional.ofNullable(invites); }
Example 15
Source File: SyncOptions.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Long> getTimeout() { return Optional.ofNullable(timeout); }
Example 16
Source File: EditObservationViewModel.java From ground-android with Apache License 2.0 | 4 votes |
Optional<Response> getResponse(String fieldId) { return Optional.ofNullable(responses.get(fieldId)); }
Example 17
Source File: MatrixHttpContentResult.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
public Optional<List<String>> getHeader(String name) { return Optional.ofNullable(headers.get(name)); }
Example 18
Source File: Project.java From ground-android with Apache License 2.0 | 4 votes |
public Optional<Layer> getLayer(String layerId) { return Optional.ofNullable(getLayerMap().get(layerId)); }
Example 19
Source File: SettingsManager.java From settlers-remake with MIT License | 4 votes |
private Optional<String> getAsOptional(String key) { return Optional.ofNullable(get(key)); }
Example 20
Source File: MatrixRoomMessageChunkOptions.java From matrix-java-sdk with GNU Affero General Public License v3.0 | 4 votes |
@Override public Optional<Long> getLimit() { return Optional.ofNullable(limit); }