[cleanup] Use a Supplier instead of evaluate methods in Optional orElse.
If a method is called in the orElse parameter, this one will be
evaluated
as soon as the Optional is built. Use orElseGet with a supplier allows
to evaluate the method only if the orElseGet is called.
Change-Id: I0e4a193dc03629b76bb13c0b481c61c6ee3d0af2
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
diff --git a/plugins/org.eclipse.sirius.properties.edit/src-spec/org/eclipse/sirius/properties/provider/Utils.java b/plugins/org.eclipse.sirius.properties.edit/src-spec/org/eclipse/sirius/properties/provider/Utils.java
index 097110a..15193bf 100644
--- a/plugins/org.eclipse.sirius.properties.edit/src-spec/org/eclipse/sirius/properties/provider/Utils.java
+++ b/plugins/org.eclipse.sirius.properties.edit/src-spec/org/eclipse/sirius/properties/provider/Utils.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2017 Obeo.
+ * Copyright (c) 2017, 2020 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -90,7 +90,7 @@
private static StyledString computeIdentifiedElementLabel(ItemProviderAdapter itemProviderAdapter, IdentifiedElement identifiedElement, String defaultLabelKey) {
String label = Optional.ofNullable(identifiedElement.getLabel()).orElse(""); //$NON-NLS-1$
if (label.isEmpty()) {
- label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty()).orElse(itemProviderAdapter.getString(defaultLabelKey));
+ label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty()).orElseGet(() -> itemProviderAdapter.getString(defaultLabelKey));
}
StyledString styledString = new StyledString(label);
@@ -156,7 +156,8 @@
IdentifiedElement identifiedElement = (IdentifiedElement) object;
String label = Optional.ofNullable(identifiedElement.getLabel()).orElse(""); //$NON-NLS-1$
if (label.isEmpty()) {
- label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty()).orElse(itemProviderAdapter.getString("_UI_" + identifiedElement.eClass().getName() + "_type")); //$NON-NLS-1$ //$NON-NLS-2$
+ label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty())
+ .orElseGet(() -> itemProviderAdapter.getString("_UI_" + identifiedElement.eClass().getName() + "_type")); //$NON-NLS-1$ //$NON-NLS-2$
}
return label;
}
diff --git a/plugins/org.eclipse.sirius.server.backend/src/org/eclipse/sirius/server/backend/internal/services/project/SiriusServerProjectService.java b/plugins/org.eclipse.sirius.server.backend/src/org/eclipse/sirius/server/backend/internal/services/project/SiriusServerProjectService.java
index 074eb73..a477596 100644
--- a/plugins/org.eclipse.sirius.server.backend/src/org/eclipse/sirius/server/backend/internal/services/project/SiriusServerProjectService.java
+++ b/plugins/org.eclipse.sirius.server.backend/src/org/eclipse/sirius/server/backend/internal/services/project/SiriusServerProjectService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 Obeo.
+ * Copyright (c) 2018, 2020 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -92,7 +92,7 @@
Optional<ModelingProject> optionalModelingProject = optionalProjectName.flatMap(this::findModelingProjectByName);
Optional<SiriusServerProjectDto> optionalProject = optionalModelingProject.map(this::getProjectFromModelingProject);
- return optionalProject.map(project -> new SiriusServerResponse(STATUS_OK, project)).orElse(new SiriusServerResponse(STATUS_NOT_FOUND));
+ return optionalProject.map(project -> new SiriusServerResponse(STATUS_OK, project)).orElseGet(() -> new SiriusServerResponse(STATUS_NOT_FOUND));
}
/**
diff --git a/plugins/org.eclipse.sirius.server/src/org/eclipse/sirius/server/api/ISiriusServerService.java b/plugins/org.eclipse.sirius.server/src/org/eclipse/sirius/server/api/ISiriusServerService.java
index 089b768..7c03d41 100644
--- a/plugins/org.eclipse.sirius.server/src/org/eclipse/sirius/server/api/ISiriusServerService.java
+++ b/plugins/org.eclipse.sirius.server/src/org/eclipse/sirius/server/api/ISiriusServerService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 Obeo.
+ * Copyright (c) 2018, 2020 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -79,7 +79,7 @@
optionalResponse = Optional.ofNullable(this.doError(request, variables, remainingPart));
break;
}
- return optionalResponse.orElse(this.doError(request, variables, remainingPart));
+ return optionalResponse.orElseGet(() -> this.doError(request, variables, remainingPart));
}
/**
diff --git a/plugins/org.eclipse.sirius.workflow.edit/src-spec/org/eclipse/sirius/workflow/provider/Utils.java b/plugins/org.eclipse.sirius.workflow.edit/src-spec/org/eclipse/sirius/workflow/provider/Utils.java
index 358b641..549ddde 100644
--- a/plugins/org.eclipse.sirius.workflow.edit/src-spec/org/eclipse/sirius/workflow/provider/Utils.java
+++ b/plugins/org.eclipse.sirius.workflow.edit/src-spec/org/eclipse/sirius/workflow/provider/Utils.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2017 Obeo.
+ * Copyright (c) 2017, 2020 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -82,7 +82,7 @@
private static StyledString computeIdentifiedElementLabel(ItemProviderAdapter itemProviderAdapter, IdentifiedElement identifiedElement, String defaultLabelKey) {
String label = Optional.ofNullable(identifiedElement.getLabel()).orElse(""); //$NON-NLS-1$
if (label.isEmpty()) {
- label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty()).orElse(itemProviderAdapter.getString(defaultLabelKey));
+ label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty()).orElseGet(() -> itemProviderAdapter.getString(defaultLabelKey));
}
StyledString styledString = new StyledString(label);
@@ -110,7 +110,8 @@
IdentifiedElement identifiedElement = (IdentifiedElement) object;
String label = Optional.ofNullable(identifiedElement.getLabel()).orElse(""); //$NON-NLS-1$
if (label.isEmpty()) {
- label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty()).orElse(itemProviderAdapter.getString("_UI_" + identifiedElement.eClass().getName() + "_type")); //$NON-NLS-1$ //$NON-NLS-2$
+ label = Optional.ofNullable(identifiedElement.getName()).filter(id -> !id.isEmpty())
+ .orElseGet(() -> itemProviderAdapter.getString("_UI_" + identifiedElement.eClass().getName() + "_type")); //$NON-NLS-1$ //$NON-NLS-2$
}
return label;
}