summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed Ashour <asashour@yahoo.com>2017-09-13 15:18:53 +0200
committerHenri Sara <henri.sara@gmail.com>2017-09-14 08:44:50 +0300
commitcaf41dbac44b53c475e20ccc621c80c754033df9 (patch)
tree54f8260fb352be4ef3822ccd430f7e60e5c963ac
parentce25750a8fd3642cf1ed7d0dac708517d5bfd226 (diff)
downloadvaadin-framework-caf41dbac44b53c475e20ccc621c80c754033df9.tar.gz
vaadin-framework-caf41dbac44b53c475e20ccc621c80c754033df9.zip
Simplify conditional logic.
-rw-r--r--client/src/main/java/com/vaadin/client/LayoutManager.java10
-rw-r--r--client/src/main/java/com/vaadin/client/WidgetUtil.java6
-rw-r--r--client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java6
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java6
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VNotification.java6
-rw-r--r--server/src/main/java/com/vaadin/server/ComponentSizeValidator.java86
-rw-r--r--server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java9
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractComponent.java7
-rw-r--r--shared/src/main/java/com/vaadin/shared/util/SharedUtil.java9
9 files changed, 41 insertions, 104 deletions
diff --git a/client/src/main/java/com/vaadin/client/LayoutManager.java b/client/src/main/java/com/vaadin/client/LayoutManager.java
index 878ac17901..b679fe980e 100644
--- a/client/src/main/java/com/vaadin/client/LayoutManager.java
+++ b/client/src/main/java/com/vaadin/client/LayoutManager.java
@@ -144,21 +144,15 @@ public class LayoutManager {
return true;
} else if (elementResizeListeners.containsKey(e)) {
return true;
- } else if (getMeasuredSize(e, nullSize).hasDependents()) {
- return true;
- } else {
- return false;
}
+ return getMeasuredSize(e, nullSize).hasDependents();
}
private boolean needsMeasureForManagedLayout(ComponentConnector connector) {
if (connector instanceof ManagedLayout) {
return true;
- } else if (connector.getParent() instanceof ManagedLayout) {
- return true;
- } else {
- return false;
}
+ return connector.getParent() instanceof ManagedLayout;
}
/**
diff --git a/client/src/main/java/com/vaadin/client/WidgetUtil.java b/client/src/main/java/com/vaadin/client/WidgetUtil.java
index f6ffe4cecd..d42ba541c6 100644
--- a/client/src/main/java/com/vaadin/client/WidgetUtil.java
+++ b/client/src/main/java/com/vaadin/client/WidgetUtil.java
@@ -769,11 +769,7 @@ public class WidgetUtil {
com.google.gwt.dom.client.Element pe) {
String overflow = getComputedStyle(pe, "overflow");
if (overflow != null) {
- if (overflow.equals("auto") || overflow.equals("scroll")) {
- return true;
- } else {
- return false;
- }
+ return overflow.equals("auto") || overflow.equals("scroll");
} else {
return false;
}
diff --git a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
index 1eb9908335..8623bc1d76 100644
--- a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
@@ -773,12 +773,8 @@ public abstract class AbstractComponentConnector extends AbstractConnector
AbstractComponentState state = getState();
if (state.description != null && !state.description.equals("")) {
return true;
- } else if (state.errorMessage != null
- && !state.errorMessage.equals("")) {
- return true;
- } else {
- return false;
}
+ return state.errorMessage != null && !state.errorMessage.equals("");
}
/**
diff --git a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java
index 9f53935440..0595d65069 100644
--- a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java
+++ b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java
@@ -667,11 +667,7 @@ public class VDragAndDropWrapper extends VCustomComponent
drag.getCurrentGwtEvent(), 0.2);
drag.getDropDetails().put("horizontalLocation",
horizontalDropLocation.toString());
- if (oldHL != horizontalDropLocation || oldVL != verticalDropLocation) {
- return true;
- } else {
- return false;
- }
+ return oldHL != horizontalDropLocation || oldVL != verticalDropLocation;
}
protected void deEmphasis(boolean doLayout) {
diff --git a/client/src/main/java/com/vaadin/client/ui/VNotification.java b/client/src/main/java/com/vaadin/client/ui/VNotification.java
index 6042ff11d6..f5815e093b 100644
--- a/client/src/main/java/com/vaadin/client/ui/VNotification.java
+++ b/client/src/main/java/com/vaadin/client/ui/VNotification.java
@@ -426,11 +426,7 @@ public class VNotification extends VOverlay {
hide();
return false;
}
- if (temporaryStyle == STYLE_SYSTEM) {
- return true;
- } else {
- return false;
- }
+ return temporaryStyle == STYLE_SYSTEM;
}
// default
switch (type) {
diff --git a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java
index 20100e0e5a..19ece940e2 100644
--- a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java
+++ b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java
@@ -305,7 +305,6 @@ public class ComponentSizeValidator implements Serializable {
this.component = component;
this.info = info;
}
-
}
private static Deque<ComponentInfo> getHeightAttributes(
@@ -435,7 +434,7 @@ public class ComponentSizeValidator implements Serializable {
public static boolean parentCanDefineHeight(Component component) {
Component parent = component.getParent();
if (parent == null) {
- // main window, valid situation
+ // main window
return true;
}
if (parent.getHeight() < 0) {
@@ -446,37 +445,28 @@ public class ComponentSizeValidator implements Serializable {
}
if (parent instanceof AbstractOrderedLayout) {
- boolean horizontal = true;
if (parent instanceof VerticalLayout) {
- horizontal = false;
- }
- if (horizontal && hasNonRelativeHeightComponent(
- (AbstractOrderedLayout) parent)) {
- return true;
- } else {
return false;
}
+ return hasNonRelativeHeightComponent(
+ (AbstractOrderedLayout) parent);
} else if (parent instanceof GridLayout) {
GridLayout gl = (GridLayout) parent;
Area componentArea = gl.getComponentArea(component);
- boolean rowHasHeight = false;
- for (int row = componentArea.getRow1(); !rowHasHeight
- && row <= componentArea.getRow2(); row++) {
- for (int column = 0; !rowHasHeight
- && column < gl.getColumns(); column++) {
+ for (int row = componentArea.getRow1();
+ row <= componentArea.getRow2(); row++) {
+ for (int column = 0;
+ column < gl.getColumns(); column++) {
Component c = gl.getComponent(column, row);
if (c != null) {
- rowHasHeight = !hasRelativeHeight(c);
+ if (!hasRelativeHeight(c)) {
+ return true;
+ }
}
}
}
- if (!rowHasHeight) {
- return false;
- } else {
- // Other components define row height
- return true;
- }
+ return false;
} else if (isForm(parent)) {
/*
* If some other part of the form is not relative it determines
@@ -503,9 +493,8 @@ public class ComponentSizeValidator implements Serializable {
// Relative height
if (parent.getParent() != null) {
return parentCanDefineHeight(parent);
- } else {
- return true;
}
+ return true;
} else {
// Absolute height
return true;
@@ -516,7 +505,7 @@ public class ComponentSizeValidator implements Serializable {
* Comparability form component which is defined in the different jar.
*
* TODO : Normally this logic shouldn't be here. But it means that the whole
- * this class has wrong design and impementation and should be refactored.
+ * this class has wrong design and implementation and should be refactored.
*/
private static boolean formHasNonRelativeWidthComponent(Component form) {
HasComponents parent = (HasComponents) form;
@@ -553,7 +542,7 @@ public class ComponentSizeValidator implements Serializable {
public static boolean parentCanDefineWidth(Component component) {
Component parent = component.getParent();
if (parent == null) {
- // main window, valid situation
+ // main window
return true;
}
if (parent instanceof Window) {
@@ -566,37 +555,25 @@ public class ComponentSizeValidator implements Serializable {
if (parent instanceof AbstractOrderedLayout) {
AbstractOrderedLayout ol = (AbstractOrderedLayout) parent;
- boolean horizontal = true;
- if (ol instanceof VerticalLayout) {
- horizontal = false;
- }
- if (!horizontal && hasNonRelativeWidthComponent(ol)) {
- // valid situation, other components defined width
- return true;
- } else {
- return false;
- }
+ // VerticalLayout and a child defines height
+ return ol instanceof VerticalLayout
+ && hasNonRelativeWidthComponent(ol);
} else if (parent instanceof GridLayout) {
GridLayout gl = (GridLayout) parent;
Area componentArea = gl.getComponentArea(component);
- boolean columnHasWidth = false;
- for (int col = componentArea.getColumn1(); !columnHasWidth
- && col <= componentArea.getColumn2(); col++) {
- for (int row = 0; !columnHasWidth
- && row < gl.getRows(); row++) {
+ for (int col = componentArea.getColumn1();
+ col <= componentArea.getColumn2(); col++) {
+ for (int row = 0; row < gl.getRows(); row++) {
Component c = gl.getComponent(col, row);
if (c != null) {
- columnHasWidth = !hasRelativeWidth(c);
+ if (!hasRelativeWidth(c)) {
+ return true;
+ }
}
}
}
- if (!columnHasWidth) {
- return false;
- } else {
- // Other components define column width
- return true;
- }
+ return false;
} else if (parent instanceof AbstractSplitPanel
|| parent instanceof TabSheet
|| parent instanceof CustomComponent) {
@@ -608,18 +585,11 @@ public class ComponentSizeValidator implements Serializable {
return false;
} else if (parent instanceof Window) {
// Sub window can define width based on caption
- if (parent.getCaption() != null
- && !parent.getCaption().isEmpty()) {
- return true;
- } else {
- return false;
- }
- } else if (parent instanceof Panel) {
- // TODO Panel should be able to define width based on caption
- return false;
- } else {
- return true;
+ return parent.getCaption() != null
+ && !parent.getCaption().isEmpty();
}
+ // TODO Panel should be able to define width based on caption
+ return !(parent instanceof Panel);
} else if (hasRelativeWidth(parent)) {
// Relative width
if (parent.getParent() == null) {
diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
index 0ec39c9416..50b23f80a3 100644
--- a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
+++ b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
@@ -58,13 +58,8 @@ public class ClassPathExplorer {
/**
* File filter that only accepts directories.
*/
- private final static FileFilter DIRECTORIES_ONLY = (File f) -> {
- if (f.exists() && f.isDirectory()) {
- return true;
- } else {
- return false;
- }
- };
+ private final static FileFilter DIRECTORIES_ONLY = (File f) ->
+ f.exists() && f.isDirectory();
/**
* Contains information about widgetsets and themes found on the classpath
diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
index c31331c3e4..cce8d970dd 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
@@ -426,12 +426,9 @@ public abstract class AbstractComponent extends AbstractClientConnector
return false;
} else if (!super.isConnectorEnabled()) {
return false;
- } else if (getParent() instanceof SelectiveRenderer
- && !((SelectiveRenderer) getParent()).isRendered(this)) {
- return false;
- } else {
- return true;
}
+ return !(getParent() instanceof SelectiveRenderer)
+ || ((SelectiveRenderer) getParent()).isRendered(this);
}
/*
diff --git a/shared/src/main/java/com/vaadin/shared/util/SharedUtil.java b/shared/src/main/java/com/vaadin/shared/util/SharedUtil.java
index 974c45ae02..d1b7cf0b22 100644
--- a/shared/src/main/java/com/vaadin/shared/util/SharedUtil.java
+++ b/shared/src/main/java/com/vaadin/shared/util/SharedUtil.java
@@ -93,13 +93,10 @@ public class SharedUtil implements Serializable {
} else if (!Character.isUpperCase(camelCaseString.charAt(i - 1))) {
// Word ends if previous char wasn't upper case
return true;
- } else if (i + 1 < camelCaseString.length()
- && !Character.isUpperCase(camelCaseString.charAt(i + 1))) {
- // Word ends if next char isn't upper case
- return true;
- } else {
- return false;
}
+ // Word ends if next char isn't upper case
+ return i + 1 < camelCaseString.length()
+ && !Character.isUpperCase(camelCaseString.charAt(i + 1));
}
/**