Browse Source

Simplify conditional logic.

tags/8.2.0.alpha2
Ahmed Ashour 6 years ago
parent
commit
caf41dbac4

+ 2
- 8
client/src/main/java/com/vaadin/client/LayoutManager.java View File

@@ -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;
}

/**

+ 1
- 5
client/src/main/java/com/vaadin/client/WidgetUtil.java View File

@@ -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;
}

+ 1
- 5
client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java View File

@@ -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("");
}

/**

+ 1
- 5
client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java View File

@@ -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) {

+ 1
- 5
client/src/main/java/com/vaadin/client/ui/VNotification.java View File

@@ -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) {

+ 28
- 58
server/src/main/java/com/vaadin/server/ComponentSizeValidator.java View File

@@ -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) {

+ 2
- 7
server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java View File

@@ -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

+ 2
- 5
server/src/main/java/com/vaadin/ui/AbstractComponent.java View File

@@ -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);
}

/*

+ 3
- 6
shared/src/main/java/com/vaadin/shared/util/SharedUtil.java View File

@@ -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));
}

/**

Loading…
Cancel
Save