Permalink
Browse files

array exception fixed

  • Loading branch information...
1 parent 681e490 commit f28735add7cdab9f42520d778360f781b955fa84 @michaelmosmann michaelmosmann committed Mar 12, 2013
Showing with 446 additions and 241 deletions.
  1. +1 −222 .../org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformator.java
  2. +127 −0 ...-kryo2/src/main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeType.java
  3. +150 −0 ...yo2/src/main/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMap.java
  4. +7 −7 ...ageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest-sample1-match.tree
  5. +2 −3 .../wicketstuff/pageserializer/kryo2/inspecting/analyze/report/SimilarNodeTreeTransformatorTest.java
  6. +3 −1 .../src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TestTreeReader.java
  7. +2 −2 ...ryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeReader.java
  8. +10 −0 ...java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-compress.tree
  9. +6 −0 ...va/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-compressed.tree
  10. +4 −0 ...t/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest-labels.tree
  11. +52 −0 ...src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeMapTest.java
  12. +11 −0 ...java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-equal-match.tree
  13. +11 −0 .../test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-equal.tree
  14. +11 −0 ...a/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-notEqual-match.tree
  15. +11 −0 ...st/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest-notEqual.tree
  16. +32 −0 ...o2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/TreeTypeTest.java
  17. +6 −6 ...zer-kryo2/src/test/java/org/wicketstuff/pageserializer/kryo2/inspecting/analyze/report/Trees.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;
- }
-
-
- }
}
@@ -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;
+ }
+
+
+}
Oops, something went wrong.

0 comments on commit f28735a

Please sign in to comment.