From a1af515897aef4dcd95cef4b11db4d651247b5e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Per-=C3=85ke=20Minborg?= Date: Fri, 28 Oct 2016 11:40:54 -0700 Subject: [PATCH] Replace Stack with Deque Change-Id: I80b73b653e97904605dc62484a7448f3bfbf722a --- .../vaadin/server/ComponentSizeValidator.java | 21 ++++++++++--------- .../com/vaadin/server/JsonPaintTarget.java | 21 ++++++++++--------- .../src/main/java/com/vaadin/ui/MenuBar.java | 13 ++++++------ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java index 129000b3bb..a4981a94b9 100644 --- a/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java +++ b/server/src/main/java/com/vaadin/server/ComponentSizeValidator.java @@ -23,7 +23,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,6 +40,8 @@ import com.vaadin.ui.TabSheet; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; +import java.util.ArrayDeque; +import java.util.Deque; @SuppressWarnings({ "serial", "deprecation" }) public class ComponentSizeValidator implements Serializable { @@ -105,7 +106,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 isForm(Component component) { if (!(component instanceof HasComponents)) { @@ -123,7 +124,7 @@ public class ComponentSizeValidator implements Serializable { } private static void printServerError(String msg, - Stack attributes, boolean widthError, + Deque attributes, boolean widthError, PrintStream errorStream) { StringBuffer err = new StringBuffer(); err.append("Vaadin DEBUG\n"); @@ -134,7 +135,7 @@ public class ComponentSizeValidator implements Serializable { while (attributes.size() > LAYERS_SHOWN) { attributes.pop(); } - while (!attributes.empty()) { + while (!attributes.isEmpty()) { ci = attributes.pop(); showComponent(ci.component, ci.info, err, indent, widthError); } @@ -219,7 +220,7 @@ public class ComponentSizeValidator implements Serializable { clientJSON.append("\"id\":\"").append(paintableId).append("\""); if (invalidHeight) { - Stack attributes = null; + Deque attributes = null; String msg = ""; // set proper error messages if (parent instanceof AbstractOrderedLayout) { @@ -249,7 +250,7 @@ public class ComponentSizeValidator implements Serializable { clientJSON.append(",\"heightMsg\":\"").append(msg).append("\""); } if (invalidWidth) { - Stack attributes = null; + Deque attributes = null; String msg = ""; if (parent instanceof AbstractOrderedLayout) { AbstractOrderedLayout ol = (AbstractOrderedLayout) parent; @@ -307,9 +308,9 @@ public class ComponentSizeValidator implements Serializable { } - private static Stack getHeightAttributes( + private static Deque getHeightAttributes( Component component) { - Stack attributes = new Stack<>(); + Deque attributes = new ArrayDeque<>(); attributes .add(new ComponentInfo(component, getHeightString(component))); Component parent = component.getParent(); @@ -322,9 +323,9 @@ public class ComponentSizeValidator implements Serializable { return attributes; } - private static Stack getWidthAttributes( + private static Deque getWidthAttributes( Component component) { - Stack attributes = new Stack<>(); + final Deque attributes = new ArrayDeque<>(); attributes.add(new ComponentInfo(component, getWidthString(component))); Component parent = component.getParent(); attributes.add(new ComponentInfo(parent, getWidthString(parent))); diff --git a/server/src/main/java/com/vaadin/server/JsonPaintTarget.java b/server/src/main/java/com/vaadin/server/JsonPaintTarget.java index 3d0b7393e6..69a9889c30 100644 --- a/server/src/main/java/com/vaadin/server/JsonPaintTarget.java +++ b/server/src/main/java/com/vaadin/server/JsonPaintTarget.java @@ -24,14 +24,15 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; -import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.ui.Alignment; import com.vaadin.ui.Component; import com.vaadin.ui.CustomLayout; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; import java.util.List; /** @@ -50,13 +51,13 @@ public class JsonPaintTarget implements PaintTarget { private final static String UIDL_ARG_NAME = "name"; - private final Stack mOpenTags; + private final Deque mOpenTags; - private final Stack openJsonTags; + private final Deque openJsonTags; // these match each other element-wise - private final Stack openPaintables; - private final Stack openPaintableTags; + private final Deque openPaintables; + private final Deque openPaintableTags; private final PrintWriter uidlBuffer; @@ -97,11 +98,11 @@ public class JsonPaintTarget implements PaintTarget { uidlBuffer = new PrintWriter(outWriter); // Initialize tag-writing - mOpenTags = new Stack<>(); - openJsonTags = new Stack<>(); + mOpenTags = new ArrayDeque<>(); + openJsonTags = new ArrayDeque<>(); - openPaintables = new Stack<>(); - openPaintableTags = new Stack<>(); + openPaintables = new ArrayDeque<>(); + openPaintableTags = new ArrayDeque<>(); cacheEnabled = cachingRequired; } @@ -157,7 +158,7 @@ public class JsonPaintTarget implements PaintTarget { * If the parent tag is closed before every child tag is closed an * PaintException is raised. * - * @param tag + * @param tagName * the name of the end tag. * @throws PaintException * if the paint operation failed. diff --git a/server/src/main/java/com/vaadin/ui/MenuBar.java b/server/src/main/java/com/vaadin/ui/MenuBar.java index 8fca3f1460..5319df7e8b 100644 --- a/server/src/main/java/com/vaadin/ui/MenuBar.java +++ b/server/src/main/java/com/vaadin/ui/MenuBar.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Stack; import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Element; @@ -36,6 +35,8 @@ import com.vaadin.shared.ui.menubar.MenuBarState; import com.vaadin.ui.Component.Focusable; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; +import java.util.ArrayDeque; +import java.util.Deque; /** *

@@ -70,7 +71,7 @@ public class MenuBar extends AbstractComponent return (MenuBarState) super.getState(markAsDirty); } - /** Paint (serialise) the component for the client. */ + /** Paint (serialize) the component for the client. */ @Override public void paintContent(PaintTarget target) throws PaintException { target.addAttribute(MenuBarConstants.OPEN_ROOT_MENU_ON_HOWER, @@ -159,10 +160,10 @@ public class MenuBar extends AbstractComponent target.endTag("item"); } - /** Deserialize changes received from client. */ + /** De-serialize changes received from client. */ @Override public void changeVariables(Object source, Map variables) { - Stack items = new Stack<>(); + final Deque items = new ArrayDeque<>(); boolean found = false; if (variables.containsKey("clickedId")) { @@ -176,9 +177,9 @@ public class MenuBar extends AbstractComponent MenuItem tmpItem = null; // Go through all the items in the menu - while (!found && !items.empty()) { + while (!found && !items.isEmpty()) { tmpItem = items.pop(); - found = (clickedId.intValue() == tmpItem.getId()); + found = (clickedId == tmpItem.getId()); if (tmpItem.hasChildren()) { itr = tmpItem.getChildren().iterator(); -- 2.39.5