Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

array exception fixed

  • Loading branch information...
commit f28735add7cdab9f42520d778360f781b955fa84 1 parent 681e490
@michaelmosmann michaelmosmann authored
Showing with 446 additions and 241 deletions.
  1. +1 −222 .../main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformator.java
  2. +127 −0 ...serializer-kryo2/src/main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeType.java
  3. +150 −0 ...ializer-kryo2/src/main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMap.java
  4. +7 −7 ...ketstuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest-sample1-match.tree
  5. +2 −3 ...t/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest.java
  6. +3 −1 ...izer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TestTreeReader.java
  7. +2 −2 ...rializer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeReader.java
  8. +10 −0 .../src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-compress.tree
  9. +6 −0 ...rc/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-compressed.tree
  10. +4 −0 ...o2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-labels.tree
  11. +52 −0 ...zer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest.java
  12. +11 −0 .../src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-equal-match.tree
  13. +11 −0 ...-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-equal.tree
  14. +11 −0 ...c/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-notEqual-match.tree
  15. +11 −0 ...yo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-notEqual.tree
  16. +32 −0 ...alizer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest.java
  17. +6 −6 ...nt/serializer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/Trees.java
View
223 ...ketstuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformator.java
@@ -21,13 +21,7 @@
package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,11 +56,7 @@ public static ISerializedObjectTree transformTree(ISerializedObjectTree tree)
transformed.add(transformTree(t));
}
- TreeTypeMap typeMap = new TreeTypeMap();
- for (ISerializedObjectTree t : transformed)
- {
- typeMap.add(t);
- }
+ TreeTypeMap typeMap = new TreeTypeMap(transformed);
if (typeMap.hasLessEntries(transformed.size()))
{
@@ -92,215 +82,4 @@ public static ISerializedObjectTree transformTree(ISerializedObjectTree tree)
}
return true;
}
-
- static class TreeTypeMap
- {
-
- Map<TreeType, List<ISerializedObjectTree>> map = new LinkedHashMap<SimilarNodeTreeTransformator.TreeType, List<ISerializedObjectTree>>();
-
- public void add(ISerializedObjectTree tree)
- {
- TreeType key = new TreeType(tree);
- List<ISerializedObjectTree> list = map.get(key);
- if (list == null)
- {
- list = new ArrayList<ISerializedObjectTree>();
- map.put(key, list);
- }
- list.add(tree);
- }
-
- public List<ISerializedObjectTree> compressedResult()
- {
- List<ISerializedObjectTree> ret = new ArrayList<ISerializedObjectTree>();
-
- for (Entry<TreeType, List<ISerializedObjectTree>> entry : map.entrySet())
- {
- List<ISerializedObjectTree> list = entry.getValue();
- ret.add(list.size() == 1 ? list.get(0) : compress(list));
- }
-
- return ret;
- }
-
- private ISerializedObjectTree compress(List<ISerializedObjectTree> list)
- {
- ISerializedObjectTree first = list.get(0);
- final Class<?> type = first.type();
- final String label = allLables(list);
-
- int size = 0;
- for (ISerializedObjectTree t : list)
- {
- size = size + t.size();
- }
-
- return new ImmutableTree(null, type, label, size, compressedChildren(list));
- }
-
- private List<? extends ISerializedObjectTree> compressedChildren(
- List<ISerializedObjectTree> list)
- {
- ISerializedObjectTree first = list.get(0);
- List<ISerializedObjectTree> ret = new ArrayList<ISerializedObjectTree>();
- for (int childIndex = 0, childCount = first.children().size(); childIndex < childCount; childIndex++)
- {
- List<ISerializedObjectTree> children = new ArrayList<ISerializedObjectTree>();
- for (ISerializedObjectTree entry : list)
- {
- children.add(entry.children().get(childIndex));
- }
- ret.add(compress(children));
- }
- return ret;
- }
-
- private String allLables(List<ISerializedObjectTree> list)
- {
- Set<String> labels = new LinkedHashSet<String>();
- for (ISerializedObjectTree t : list)
- {
- if (t.label() != null)
- labels.add(t.label());
- }
- if (labels.isEmpty())
- {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (String s : labels)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- sb.append("|");
- }
- sb.append(s);
- }
- return sb.toString();
- }
-
- public boolean hasLessEntries(int size)
- {
- return map.size() < size;
- }
- }
-
- protected static final class TreeType implements Comparable<TreeType>
- {
- final Class<?> type;
- final List<TreeType> children;
-
- public TreeType(ISerializedObjectTree tree)
- {
- this.type = tree.type();
- this.children = children(tree.children());
- }
-
- @Override
- public int compareTo(TreeType o)
- {
- if (this.equals(o))
- return 0;
- int typeResult = type.getName().compareTo(o.type.getName());
- if (typeResult != 0)
- return typeResult;
- int sizeDiff = children.size() - o.children.size();
- if (sizeDiff != 0)
- return sizeDiff > 0 ? 1 : -1;
- for (int i = 0, s = children.size(); i < s; i++)
- {
- int childCompare = children.get(i).compareTo(o.children.get(i));
- if (childCompare != 0)
- return childCompare;
- }
- return 0;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- format(sb, 0);
- return sb.toString();
- }
-
- private void format(StringBuilder sb, int level)
- {
- indent(sb, level);
- sb.append(type.getName());
- if (!children.isEmpty())
- {
- indent(sb, level);
- sb.append("{\n");
- for (TreeType c : children) {
- c.format(sb,level+1);
- sb.append(",\n");
- }
- indent(sb, level);
- sb.append("}\n");
- }
- }
-
- private void indent(StringBuilder sb, int level)
- {
- for (int i=0;i<level;i++) {
- sb.append(" ");
- }
- }
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((children == null) ? 0 : children.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TreeType other = (TreeType)obj;
- if (children == null)
- {
- if (other.children != null)
- return false;
- }
- else if (!children.equals(other.children))
- return false;
- if (type == null)
- {
- if (other.type != null)
- return false;
- }
- else if (!type.equals(other.type))
- return false;
- return true;
- }
-
- private static List<TreeType> children(List<? extends ISerializedObjectTree> list)
- {
- List<TreeType> ret = new ArrayList<SimilarNodeTreeTransformator.TreeType>();
- for (ISerializedObjectTree t : list)
- {
- ret.add(new TreeType(t));
- }
- Collections.sort(ret);
- return ret;
- }
-
-
- }
}
View
127 ...rc/main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeType.java
@@ -0,0 +1,127 @@
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+
+/**
+ * NOT A PUBLIC API
+ * a tree as a key - this way you can compare trees with other trees
+ * @author mosmann
+ *
+ */
+final class TreeType implements Comparable<TreeType>
+{
+ final Class<?> type;
+ final List<TreeType> children;
+
+ public TreeType(ISerializedObjectTree tree)
+ {
+ this.type = tree.type();
+ this.children = children(tree.children());
+ }
+
+ @Override
+ public int compareTo(TreeType o)
+ {
+ if (this.equals(o))
+ return 0;
+ int typeResult = type.getName().compareTo(o.type.getName());
+ if (typeResult != 0)
+ return typeResult;
+ int sizeDiff = children.size() - o.children.size();
+ if (sizeDiff != 0)
+ return sizeDiff > 0 ? 1 : -1;
+ for (int i = 0, s = children.size(); i < s; i++)
+ {
+ int childCompare = children.get(i).compareTo(o.children.get(i));
+ if (childCompare != 0)
+ return childCompare;
+ }
+ return 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ format(sb, 0);
+ return sb.toString();
+ }
+
+ private void format(StringBuilder sb, int level)
+ {
+ indent(sb, level);
+ sb.append(type.getName());
+ if (!children.isEmpty())
+ {
+ indent(sb, level);
+ sb.append("{\n");
+ for (TreeType c : children) {
+ c.format(sb,level+1);
+ sb.append(",\n");
+ }
+ indent(sb, level);
+ sb.append("}\n");
+ }
+ }
+
+ private void indent(StringBuilder sb, int level)
+ {
+ for (int i=0;i<level;i++) {
+ sb.append(" ");
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((children == null) ? 0 : children.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ TreeType other = (TreeType)obj;
+ if (children == null)
+ {
+ if (other.children != null)
+ return false;
+ }
+ else if (!children.equals(other.children))
+ return false;
+ if (type == null)
+ {
+ if (other.type != null)
+ return false;
+ }
+ else if (!type.equals(other.type))
+ return false;
+ return true;
+ }
+
+ private static List<TreeType> children(List<? extends ISerializedObjectTree> list)
+ {
+ List<TreeType> ret = new ArrayList<TreeType>();
+ for (ISerializedObjectTree t : list)
+ {
+ ret.add(new TreeType(t));
+ }
+ Collections.sort(ret);
+ return ret;
+ }
+
+
+}
View
150 ...main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMap.java
@@ -0,0 +1,150 @@
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ImmutableTree;
+
+/**
+ * NOT A PUBLIC API
+ * this builds a map of similar trees
+ *
+ * @author mosmann
+ *
+ */
+class TreeTypeMap {
+
+ Map<TreeType, List<ISerializedObjectTree>> map;
+
+ public TreeTypeMap(List<? extends ISerializedObjectTree> source) {
+ Map<TreeType, List<ISerializedObjectTree>> typeMap = new LinkedHashMap<TreeType, List<ISerializedObjectTree>>();
+
+ for (ISerializedObjectTree tree : source) {
+ TreeType key = new TreeType(tree);
+ List<ISerializedObjectTree> list = typeMap.get(key);
+ if (list == null) {
+ list = new ArrayList<ISerializedObjectTree>();
+ typeMap.put(key, list);
+ }
+ list.add(tree);
+ }
+
+ map = typeMap;
+ }
+
+ public List<ISerializedObjectTree> compressedResult() {
+ List<ISerializedObjectTree> ret = new ArrayList<ISerializedObjectTree>();
+
+ for (Entry<TreeType, List<ISerializedObjectTree>> entry : map.entrySet()) {
+ List<ISerializedObjectTree> list = entry.getValue();
+ ret.add(list.size() == 1
+ ? list.get(0)
+ : compress(list));
+ }
+
+ return ret;
+ }
+
+ /**
+ * join a list of nodes into one, label and size information will be aggregated
+ *
+ * @param list
+ * source nodes
+ * @return one node
+ */
+ protected static ISerializedObjectTree compress(List<? extends ISerializedObjectTree> list) {
+ ISerializedObjectTree first = list.get(0);
+ final Class<?> type = first.type();
+ final String label = allLables(list);
+
+ int size = 0;
+ for (ISerializedObjectTree t : list) {
+ size = size + t.size();
+ }
+
+ return new ImmutableTree(null, type, label, size, compressedChildren(list));
+ }
+
+ /**
+ * all entries in the list are equal, join every matching child node for every entry
+ *
+ * @param source
+ * entries with same tree layout
+ * @return tree with compressed child layout
+ */
+ protected static List<? extends ISerializedObjectTree> compressedChildren(List<? extends ISerializedObjectTree> source) {
+ List<ISerializedObjectTree> ret = new ArrayList<ISerializedObjectTree>();
+ List<List<? extends ISerializedObjectTree>> childrens = new ArrayList<List<? extends ISerializedObjectTree>>();
+
+ int columns = 0;
+ for (ISerializedObjectTree entry : source) {
+ List<? extends ISerializedObjectTree> sortedChildren = sortByTreeType(entry.children());
+ columns = sortedChildren.size();
+ childrens.add(sortedChildren);
+ }
+
+ for (int i = 0; i < columns; i++) {
+ List<ISerializedObjectTree> columnValues = new ArrayList<ISerializedObjectTree>();
+ for (List<? extends ISerializedObjectTree> line : childrens) {
+ columnValues.add(line.get(i));
+ }
+ ISerializedObjectTree compressed = compress(columnValues);
+ ret.add(compressed);
+ }
+ return ret;
+ }
+
+ private static List<? extends ISerializedObjectTree> sortByTreeType(List<? extends ISerializedObjectTree> source) {
+ List<ISerializedObjectTree> ret = new ArrayList<ISerializedObjectTree>();
+ ret.addAll(source);
+ Collections.sort(ret, new Comparator<ISerializedObjectTree>() {
+
+ @Override
+ public int compare(ISerializedObjectTree o1, ISerializedObjectTree o2) {
+ return new TreeType(o1).compareTo(new TreeType(o2));
+ }
+ });
+ return ret;
+ }
+
+ /**
+ * joins all labels from list into on
+ *
+ * @param list
+ * tree elements
+ * @return joined label
+ */
+ protected static String allLables(List<? extends ISerializedObjectTree> list) {
+ Set<String> labels = new LinkedHashSet<String>();
+ for (ISerializedObjectTree t : list) {
+ if (t.label() != null)
+ labels.add(t.label());
+ }
+ if (labels.isEmpty()) {
+ return null;
+ }
+ StringBuilder sb = new StringBuilder();
+ boolean first = true;
+ for (String s : labels) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append("|");
+ }
+ sb.append(s);
+ }
+ return sb.toString();
+ }
+
+ public boolean hasLessEntries(int size) {
+ return map.size() < size;
+ }
+}
View
14 ...lizer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest-sample1-match.tree
@@ -4,16 +4,16 @@ org.wicketstuff.pageserializer.kryo2.pages.ListViewPage(asSample) | 141
org.apache.wicket.markup.html.list.ListView(list) | 114
[Ljava.lang.Object; | 2
org.apache.wicket.markup.html.list.ListItem(0|1|2) | 67
+ java.lang.Integer | 21
+ java.lang.String | 9
org.apache.wicket.markup.html.basic.Label(label) | 63
- org.apache.wicket.markup.html.list.ListItemModel | 9
- java.lang.Integer | 3
- org.apache.wicket.markup.html.list.ListView(list) | 3
java.lang.Integer | 18
java.lang.String | 8
org.apache.wicket.markup.html.list.ListItem(0|1|2) | 3
+ org.apache.wicket.markup.html.list.ListItemModel | 9
+ java.lang.Integer | 3
+ org.apache.wicket.markup.html.list.ListView(list) | 3
org.apache.wicket.markup.html.list.ListItemModel | 3
- java.lang.Integer | 21
- java.lang.String | 9
org.apache.wicket.markup.html.list.ListView(list) | 3
org.apache.wicket.model.util.WildcardListModel | 2
java.util.Arrays$ArrayList | 3
@@ -25,11 +25,11 @@ org.wicketstuff.pageserializer.kryo2.pages.ListViewPage(asSample) | 141
org.apache.wicket.markup.html.list.ListView(list2) | 68
[Ljava.lang.Object; | 2
org.apache.wicket.markup.html.list.ListItem(0|1|2) | 24
+ java.lang.Integer | 21
+ java.lang.String | 3
org.apache.wicket.markup.html.list.ListItemModel | 9
java.lang.Integer | 3
org.apache.wicket.markup.html.list.ListView(list2) | 3
- java.lang.Integer | 21
- java.lang.String | 3
org.apache.wicket.markup.html.list.ListView(list2) | 3
org.apache.wicket.model.util.WildcardListModel | 2
java.util.Arrays$ArrayList | 1
View
5 ...tuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest.java
@@ -37,12 +37,11 @@
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ImmutableTree;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ObjectId;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.TreeProcessors;
-import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.SimilarNodeTreeTransformator.TreeType;
import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report.filter.TypeFilter;
import org.wicketstuff.pageserializer.kryo2.pages.ListViewPage;
public class SimilarNodeTreeTransformatorTest
-{
+{
@Test
public void dontChangeAnything()
{
@@ -100,7 +99,7 @@ public void testCompression() throws IOException {
new TreeSizeReport().process(result);
ISerializedObjectTree match = Trees.fromResource(getClass(), "sample1-match");
new TreeSizeReport().process(match);
-
+
Trees.assertEqualsTree(match, result);
}
View
4 ...t/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TestTreeReader.java
@@ -20,6 +20,8 @@
*/
package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+import java.io.IOException;
+
import junit.framework.Assert;
import org.apache.wicket.markup.html.list.ListView;
@@ -64,7 +66,7 @@ public void lineParser()
}
@Test
- public void lineLines()
+ public void lineLines() throws IOException
{
String lines = "org.wicketstuff.pageserializer.kryo2.pages.ListViewPage(0) | 141\n"
+ " java.lang.Integer | 9\n"
View
4 .../test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeReader.java
@@ -59,7 +59,7 @@ public static ISerializedObjectTree fromResourceWithFilename(Class<?> baseType,
}
}
- public static ISerializedObjectTree fromString(String asString)
+ public static ISerializedObjectTree fromString(String asString) throws IOException
{
List<Line> lines = new ArrayList<Line>();
String[] textLines = Strings.split(asString, '\n');
@@ -96,7 +96,7 @@ public static ISerializedObjectTree fromString(String asString)
return parent.asObjectTree();
}
- return null;
+ throw new IOException("empty file");
}
View
10 .../wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-compress.tree
@@ -0,0 +1,10 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a) | 0
+ .TreeTypeMapTest$B(1) | 0
+ .TreeTypeMapTest$D(0) | 0
+ .TreeTypeMapTest$C(2) | 0
+ .TreeTypeMapTest$A(b) | 0
+ .TreeTypeMapTest$C(3) | 0
+ .TreeTypeMapTest$B(4) | 0
+ .TreeTypeMapTest$D(0) | 0
+
View
6 ...icketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-compressed.tree
@@ -0,0 +1,6 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a|b) | 0
+ .TreeTypeMapTest$B(1|4) | 0
+ .TreeTypeMapTest$D(0) | 0
+ .TreeTypeMapTest$C(2|3) | 0
+
View
4 ...rg/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-labels.tree
@@ -0,0 +1,4 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a) | 0
+ .TreeTypeMapTest$A(b) | 0
+ .TreeTypeMapTest$A(c) | 0
View
52 .../java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest.java
@@ -0,0 +1,52 @@
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+
+public class TreeTypeMapTest {
+
+ @Test
+ public void joinLabels() throws IOException {
+ ISerializedObjectTree source = Trees.fromResource(getClass(), "labels");
+ Assert.assertEquals("a|b|c", TreeTypeMap.allLables(source.children()));
+ }
+ @Test
+ public void noLabels() throws IOException {
+ Assert.assertEquals(null, TreeTypeMap.allLables(new ArrayList<ISerializedObjectTree>()));
+ }
+
+ @Test
+ public void compressNothing() throws IOException {
+ ISerializedObjectTree source = Trees.fromResource(getClass(), "compress");
+ ISerializedObjectTree match= Trees.fromResource(getClass(), "compressed");
+// ISerializedObjectTree compressed = TreeTypeMap.compress(source.children());
+ ISerializedObjectTree compressed = SimilarNodeTreeTransformator.transformTree(source);
+ Trees.assertEqualsTree(match, compressed);
+ }
+
+ static class Root {
+
+ }
+
+ static class A {
+
+ }
+
+ static class B {
+
+ }
+
+ static class C {
+
+ }
+
+ static class D {
+
+ }
+
+}
View
11 .../wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-equal-match.tree
@@ -0,0 +1,11 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a) | 0
+ .TreeTypeMapTest$B(1) | 0
+ .TreeTypeMapTest$B(2) | 0
+ .TreeTypeMapTest$A(b) | 0
+ .TreeTypeMapTest$A(3) | 0
+ .TreeTypeMapTest$B(4) | 0
+ .TreeTypeMapTest$C(5) | 0
+ .TreeTypeMapTest$A(c) | 0
+ .TreeTypeMapTest$C(6) | 0
+
View
11 ...va/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-equal.tree
@@ -0,0 +1,11 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a) | 0
+ .TreeTypeMapTest$B(1) | 0
+ .TreeTypeMapTest$B(2) | 0
+ .TreeTypeMapTest$A(b) | 0
+ .TreeTypeMapTest$C(3) | 0
+ .TreeTypeMapTest$B(4) | 0
+ .TreeTypeMapTest$A(5) | 0
+ .TreeTypeMapTest$A(c) | 0
+ .TreeTypeMapTest$C(6) | 0
+
View
11 ...cketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-notEqual-match.tree
@@ -0,0 +1,11 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a) | 0
+ .TreeTypeMapTest$B(1) | 0
+ .TreeTypeMapTest$B(2) | 0
+ .TreeTypeMapTest$A(b) | 0
+ .TreeTypeMapTest$B(3) | 0
+ .TreeTypeMapTest$B(4) | 0
+ .TreeTypeMapTest$B(5) | 0
+ .TreeTypeMapTest$A(c) | 0
+ .TreeTypeMapTest$B(6) | 0
+
View
11 ...org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-notEqual.tree
@@ -0,0 +1,11 @@
+.TreeTypeMapTest$Root(asSample) | 1
+ .TreeTypeMapTest$A(a) | 0
+ .TreeTypeMapTest$B(1) | 0
+ .TreeTypeMapTest$B(2) | 0
+ .TreeTypeMapTest$A(b) | 0
+ .TreeTypeMapTest$B(3) | 0
+ .TreeTypeMapTest$B(4) | 0
+ .TreeTypeMapTest$B(5) | 0
+ .TreeTypeMapTest$A(c) | 0
+ .TreeTypeMapTest$C(6) | 0
+
View
32 ...est/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest.java
@@ -0,0 +1,32 @@
+package org.wicketstuff.pageserializer.kryo2.inspecting.analyze.report;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.wicketstuff.pageserializer.kryo2.inspecting.analyze.ISerializedObjectTree;
+
+
+public class TreeTypeTest {
+
+ @Test
+ public void notEqual() throws IOException {
+ ISerializedObjectTree source = Trees.fromResource(getClass(), "notEqual");
+ ISerializedObjectTree match= Trees.fromResource(getClass(), "notEqual-match");
+ TreeType sourceType=new TreeType(source);
+ TreeType matchType=new TreeType(match);
+ Assert.assertFalse(matchType.equals(sourceType));
+ Assert.assertFalse(matchType.compareTo(sourceType)==0);
+ }
+
+ @Test
+ public void equal() throws IOException {
+ ISerializedObjectTree source = Trees.fromResource(getClass(), "equal");
+ ISerializedObjectTree match= Trees.fromResource(getClass(), "equal-match");
+ TreeType sourceType=new TreeType(source);
+ TreeType matchType=new TreeType(match);
+ Assert.assertEquals(matchType,sourceType);
+ Assert.assertTrue(matchType.compareTo(sourceType)==0);
+ }
+}
View
12 ...2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/Trees.java
@@ -50,12 +50,12 @@ public static ISerializedObjectTree fromResource(Class<?> clazz, String postFix)
public static void assertEqualsTree(ISerializedObjectTree expected, ISerializedObjectTree result)
{
- Assert.assertEquals("id", expected.id(), result.id());
- Assert.assertEquals("type", expected.type(), result.type());
- Assert.assertEquals("label", expected.label(), result.label());
- Assert.assertEquals("size", expected.size(), result.size());
- Assert.assertEquals("childSize", expected.childSize(), result.childSize());
- Assert.assertEquals("children", expected.children().size(), result.children().size());
+ Assert.assertEquals(expected+":id", expected.id(), result.id());
+ Assert.assertEquals(expected+":type", expected.type(), result.type());
+ Assert.assertEquals(expected+":label", expected.label(), result.label());
+ Assert.assertEquals(expected+":size", expected.size(), result.size());
+ Assert.assertEquals(expected+":childSize", expected.childSize(), result.childSize());
+ Assert.assertEquals(expected+":children", expected.children().size(), result.children().size());
for (int i = 0, s = expected.children().size(); i < s; i++)
{
assertEqualsTree(expected.children().get(i), result.children().get(i));
Please sign in to comment.
Something went wrong with that request. Please try again.