aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/client/Util.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-03-08 17:56:20 +0200
committerArtur Signell <artur@vaadin.com>2012-03-13 18:10:36 +0200
commit88d1e517cb6ce95be6554984326256e1a1b83f4c (patch)
tree0ade5f8d67f02d3a256e9d1a150bf6f41901b582 /src/com/vaadin/terminal/gwt/client/Util.java
parent042c30f5ac200d3475abdcbfb7e26fcffdf50272 (diff)
downloadvaadin-framework-88d1e517cb6ce95be6554984326256e1a1b83f4c.tar.gz
vaadin-framework-88d1e517cb6ce95be6554984326256e1a1b83f4c.zip
#8500 Initial implementation for sending component hierarchy
automatically to the client and calling a listener method (for the parent) when its child hierarchy has been updated. Minor cleanup of JSON handling at the same time.
Diffstat (limited to 'src/com/vaadin/terminal/gwt/client/Util.java')
-rw-r--r--src/com/vaadin/terminal/gwt/client/Util.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/Util.java b/src/com/vaadin/terminal/gwt/client/Util.java
index 572a9bebb2..39962de907 100644
--- a/src/com/vaadin/terminal/gwt/client/Util.java
+++ b/src/com/vaadin/terminal/gwt/client/Util.java
@@ -6,6 +6,8 @@ package com.vaadin.terminal.gwt.client;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import com.google.gwt.core.client.Scheduler;
@@ -1094,4 +1096,39 @@ public class Util {
boolean touchEvent = Util.isTouchEvent(event);
return touchEvent || event.getButton() == Event.BUTTON_LEFT;
}
+
+ /**
+ * Performs a shallow comparison of the collections.
+ *
+ * @param collection1 The first collection
+ * @param collection2 The second collection
+ * @return true if the collections contain the same elements in the same
+ * order, false otherwise
+ */
+ public static boolean collectionsEquals(Collection collection1, Collection collection2) {
+ if (collection1 == null) {
+ return collection2 == null;
+ }
+ if (collection2 == null) {
+ return false;
+ }
+ Iterator<Object> collection1Iterator = collection1.iterator();
+ Iterator<Object> collection2Iterator = collection2.iterator();
+
+ while (collection1Iterator.hasNext()) {
+ if (!collection2Iterator.hasNext()) {
+ return false;
+ }
+ Object collection1Object = collection1Iterator.next();
+ Object collection2Object = collection2Iterator.next();
+ if (collection1Object != collection2Object) {
+ return false;
+ }
+ }
+ if (collection2Iterator.hasNext()) {
+ return false;
+ }
+
+ return true;
+ }
}