Skip to content

Commit

Permalink
Replace Stack with Deque
Browse files Browse the repository at this point in the history
Change-Id: I80b73b653e97904605dc62484a7448f3bfbf722a
  • Loading branch information
minborg authored and Henri Sara committed Nov 5, 2016
1 parent 3e2ddb4 commit a1af515
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
21 changes: 11 additions & 10 deletions server/src/main/java/com/vaadin/server/ComponentSizeValidator.java
Expand Up @@ -23,7 +23,6 @@
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;

Expand All @@ -41,6 +40,8 @@
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 {
Expand Down Expand Up @@ -105,7 +106,7 @@ public static List<InvalidLayout> validateComponentRelativeSizes(
* 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)) {
Expand All @@ -123,7 +124,7 @@ private static boolean isForm(Component component) {
}

private static void printServerError(String msg,
Stack<ComponentInfo> attributes, boolean widthError,
Deque<ComponentInfo> attributes, boolean widthError,
PrintStream errorStream) {
StringBuffer err = new StringBuffer();
err.append("Vaadin DEBUG\n");
Expand All @@ -134,7 +135,7 @@ private static void printServerError(String msg,
while (attributes.size() > LAYERS_SHOWN) {
attributes.pop();
}
while (!attributes.empty()) {
while (!attributes.isEmpty()) {
ci = attributes.pop();
showComponent(ci.component, ci.info, err, indent, widthError);
}
Expand Down Expand Up @@ -219,7 +220,7 @@ public void reportErrors(StringBuilder clientJSON,
clientJSON.append("\"id\":\"").append(paintableId).append("\"");

if (invalidHeight) {
Stack<ComponentInfo> attributes = null;
Deque<ComponentInfo> attributes = null;
String msg = "";
// set proper error messages
if (parent instanceof AbstractOrderedLayout) {
Expand Down Expand Up @@ -249,7 +250,7 @@ public void reportErrors(StringBuilder clientJSON,
clientJSON.append(",\"heightMsg\":\"").append(msg).append("\"");
}
if (invalidWidth) {
Stack<ComponentInfo> attributes = null;
Deque<ComponentInfo> attributes = null;
String msg = "";
if (parent instanceof AbstractOrderedLayout) {
AbstractOrderedLayout ol = (AbstractOrderedLayout) parent;
Expand Down Expand Up @@ -307,9 +308,9 @@ public ComponentInfo(Component component, String info) {

}

private static Stack<ComponentInfo> getHeightAttributes(
private static Deque<ComponentInfo> getHeightAttributes(
Component component) {
Stack<ComponentInfo> attributes = new Stack<>();
Deque<ComponentInfo> attributes = new ArrayDeque<>();
attributes
.add(new ComponentInfo(component, getHeightString(component)));
Component parent = component.getParent();
Expand All @@ -322,9 +323,9 @@ private static Stack<ComponentInfo> getHeightAttributes(
return attributes;
}

private static Stack<ComponentInfo> getWidthAttributes(
private static Deque<ComponentInfo> getWidthAttributes(
Component component) {
Stack<ComponentInfo> attributes = new Stack<>();
final Deque<ComponentInfo> attributes = new ArrayDeque<>();
attributes.add(new ComponentInfo(component, getWidthString(component)));
Component parent = component.getParent();
attributes.add(new ComponentInfo(parent, getWidthString(parent)));
Expand Down
21 changes: 11 additions & 10 deletions server/src/main/java/com/vaadin/server/JsonPaintTarget.java
Expand Up @@ -24,14 +24,15 @@
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;

/**
Expand All @@ -50,13 +51,13 @@ public class JsonPaintTarget implements PaintTarget {

private final static String UIDL_ARG_NAME = "name";

private final Stack<String> mOpenTags;
private final Deque<String> mOpenTags;

private final Stack<JsonTag> openJsonTags;
private final Deque<JsonTag> openJsonTags;

// these match each other element-wise
private final Stack<ClientConnector> openPaintables;
private final Stack<String> openPaintableTags;
private final Deque<ClientConnector> openPaintables;
private final Deque<String> openPaintableTags;

private final PrintWriter uidlBuffer;

Expand Down Expand Up @@ -97,11 +98,11 @@ public JsonPaintTarget(LegacyCommunicationManager manager, Writer outWriter,
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;
}
Expand Down Expand Up @@ -157,7 +158,7 @@ public void startTag(String tagName, boolean isChildNode)
* 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.
Expand Down
13 changes: 7 additions & 6 deletions server/src/main/java/com/vaadin/ui/MenuBar.java
Expand Up @@ -21,7 +21,6 @@
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;
Expand All @@ -36,6 +35,8 @@
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;

/**
* <p>
Expand Down Expand Up @@ -70,7 +71,7 @@ protected MenuBarState getState(boolean markAsDirty) {
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,
Expand Down Expand Up @@ -159,10 +160,10 @@ private void paintItem(PaintTarget target, MenuItem item)
target.endTag("item");
}

/** Deserialize changes received from client. */
/** De-serialize changes received from client. */
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
Stack<MenuItem> items = new Stack<>();
final Deque<MenuItem> items = new ArrayDeque<>();
boolean found = false;

if (variables.containsKey("clickedId")) {
Expand All @@ -176,9 +177,9 @@ public void changeVariables(Object source, Map<String, Object> variables) {
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();
Expand Down

0 comments on commit a1af515

Please sign in to comment.