diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index be12d363a..405e08d94 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -58,6 +58,7 @@ import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Cache; import com.jpexs.decompiler.flash.helpers.Helper; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineButton2Tag; @@ -505,10 +506,10 @@ public class SWF { return false; } - private List> uniqueAS3Packs(List> packs) { - List> ret = new ArrayList<>(); - for (KeyValue item : packs) { - for (KeyValue itemOld : ret) { + private List> uniqueAS3Packs(List> packs) { + List> ret = new ArrayList<>(); + for (MyEntry item : packs) { + for (MyEntry itemOld : ret) { if (item.key.equals(itemOld.key)) { Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Duplicate pack path found!"); break; @@ -519,14 +520,14 @@ public class SWF { return ret; } - public List> getAS3Packs() { + public List> getAS3Packs() { List abcTags = new ArrayList<>(); for (Tag t : tags) { if (t instanceof ABCContainerTag) { abcTags.add((ABCContainerTag) t); } } - List> packs = new ArrayList<>(); + List> packs = new ArrayList<>(); for (int i = 0; i < abcTags.size(); i++) { ABCContainerTag t = abcTags.get(i); packs.addAll(t.getABC().getScriptPacks()); @@ -597,8 +598,8 @@ public class SWF { abcTags.add((ABCContainerTag) t); } } - List> packs = getAS3Packs(); - for (KeyValue item : packs) { + List> packs = getAS3Packs(); + for (MyEntry item : packs) { Future future = executor.submit(new ExportPackTask(cnt, packs.size(), item.key, item.value, outdir, abcTags, isPcode, "", paralel)); futureResults.add(future); } @@ -1343,7 +1344,7 @@ public class SWF { public static final String validNextCharacters = validFirstCharacters + "0123456789"; public static final String fooCharacters = "bcdfghjklmnpqrstvwz"; public static final String fooJoinCharacters = "aeiouy"; - private List> allVariableNames = new ArrayList<>(); + private List> allVariableNames = new ArrayList<>(); private HashSet allVariableNamesStr = new HashSet<>(); private List allFunctions = new ArrayList<>(); private HashMap allStrings = new HashMap<>(); @@ -1449,7 +1450,7 @@ public class SWF { return null; } - private static void getVariables(ConstantPool constantPool, List localData, Stack stack, List output, ActionGraphSource code, int ip, List> variables, List functions, HashMap strings, List visited, HashMap usageTypes) { + private static void getVariables(ConstantPool constantPool, List localData, Stack stack, List output, ActionGraphSource code, int ip, List> variables, List functions, HashMap strings, List visited, HashMap usageTypes) { boolean debugMode = false; while ((ip > -1) && ip < code.size()) { if (visited.contains(ip)) { @@ -1537,7 +1538,7 @@ public class SWF { } if (name instanceof DirectValueTreeItem) { - variables.add(new KeyValue<>((DirectValueTreeItem) name, constantPool)); + variables.add(new MyEntry<>((DirectValueTreeItem) name, constantPool)); usageTypes.put((DirectValueTreeItem) name, usageType); } @@ -1598,7 +1599,7 @@ public class SWF { }; } - private static void getVariables(List> variables, List functions, HashMap strings, HashMap usageType, ActionGraphSource code, int addr) { + private static void getVariables(List> variables, List functions, HashMap strings, HashMap usageType, ActionGraphSource code, int addr) { List localData = Helper.toList(new HashMap(), new HashMap(), new HashMap()); try { getVariables(null, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), variables, functions, strings, new ArrayList(), usageType); @@ -1607,8 +1608,8 @@ public class SWF { } } - private List> getVariables(List> variables, List functions, HashMap strings, HashMap usageType, ASMSource src) { - List> ret = new ArrayList<>(); + private List> getVariables(List> variables, List functions, HashMap strings, HashMap usageType, ASMSource src) { + List> ret = new ArrayList<>(); List actions = src.getActions(version); actionsMap.put(src, actions); getVariables(variables, functions, strings, usageType, new ActionGraphSource(actions, version, new HashMap(), new HashMap(), new HashMap()), 0); @@ -1792,7 +1793,7 @@ public class SWF { getVariables(objs, ""); informListeners("rename", ""); int fc = 0; - for (KeyValue it : allVariableNames) { + for (MyEntry it : allVariableNames) { String name = it.key.toStringNoH(it.value); allVariableNamesStr.add(name); } @@ -1846,10 +1847,10 @@ public class SWF { List vars = new ArrayList<>(); - for (KeyValue item : cti.vars) { + for (MyEntry item : cti.vars) { vars.add(item.key); } - for (KeyValue item : cti.staticVars) { + for (MyEntry item : cti.staticVars) { vars.add(item.key); } for (GraphTargetItem gti : vars) { @@ -1946,7 +1947,7 @@ public class SWF { HashSet stringsNoVarH = new HashSet<>(); List allVariableNamesDv = new ArrayList<>(); - for (KeyValue it : allVariableNames) { + for (MyEntry it : allVariableNames) { allVariableNamesDv.add(it.key); } for (DirectValueTreeItem ti : allStrings.keySet()) { @@ -1956,7 +1957,7 @@ public class SWF { } int vc = 0; - for (KeyValue it : allVariableNames) { + for (MyEntry it : allVariableNames) { vc++; String name = it.key.toStringNoH(it.value); String changed = deobfuscateName(name, false, usageTypes.get(it.key), renameType, selected); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index b5e485196..931086f13 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.abc; import com.jpexs.decompiler.flash.EventListener; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.UnknownInstructionCode; @@ -32,6 +31,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.abc.usages.*; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import java.io.*; import java.util.ArrayList; import java.util.HashMap; @@ -706,8 +706,8 @@ public class ABC { /*public void export(String directory, boolean pcode, List abcList, boolean paralel) throws IOException { export(directory, pcode, abcList, "", paralel); }*/ - public List> getScriptPacks() { - List> ret = new ArrayList<>(); + public List> getScriptPacks() { + List> ret = new ArrayList<>(); for (int i = 0; i < script_info.length; i++) { ret.addAll(script_info[i].getPacks(this, i)); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index 7898530a4..a3369b13a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -16,12 +16,12 @@ */ package com.jpexs.decompiler.flash.abc.types; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import java.util.ArrayList; import java.util.List; @@ -31,8 +31,8 @@ public class ScriptInfo { public int init_index; //MethodInfo public Traits traits; - public List> getPacks(ABC abc, int scriptIndex) { - List> ret = new ArrayList<>(); + public List> getPacks(ABC abc, int scriptIndex) { + List> ret = new ArrayList<>(); List otherTraits = new ArrayList<>(); for (int j = 0; j < traits.traits.length; j++) { @@ -59,7 +59,7 @@ public class ScriptInfo { traitIndices.addAll(otherTraits); } otherTraits = new ArrayList<>(); - ret.add(new KeyValue<>(new ClassPath(packageName, objectName), new ScriptPack(abc, scriptIndex, traitIndices))); + ret.add(new MyEntry<>(new ClassPath(packageName, objectName), new ScriptPack(abc, scriptIndex, traitIndices))); } } return ret; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index 855759f0f..4a7d85d8b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.action; import com.jpexs.decompiler.flash.DisassemblyListener; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; @@ -43,6 +42,7 @@ import com.jpexs.decompiler.flash.graph.NotItem; import com.jpexs.decompiler.flash.graph.ScriptEndItem; import com.jpexs.decompiler.flash.helpers.Helper; import com.jpexs.decompiler.flash.helpers.Highlighting; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.StringReader; @@ -986,8 +986,8 @@ public class Action implements GraphSourceItem { List ret = new ArrayList<>(); List functions = new ArrayList<>(); List staticFunctions = new ArrayList<>(); - List> vars = new ArrayList<>(); - List> staticVars = new ArrayList<>(); + List> vars = new ArrayList<>(); + List> staticVars = new ArrayList<>(); GraphTargetItem className; GraphTargetItem extendsOp = null; List implementsOp = new ArrayList<>(); @@ -1144,14 +1144,14 @@ public class Action implements GraphSourceItem { ((FunctionTreeItem) smt.value).calculatedFunctionName = smt.objectName; functions.add((FunctionTreeItem) smt.value); } else { - vars.add(new KeyValue<>(smt.objectName, smt.value)); + vars.add(new MyEntry<>(smt.objectName, smt.value)); } } else if (((RegisterNumber) ((DirectValueTreeItem) smt.object).value).number == classReg) { if (smt.value instanceof FunctionTreeItem) { ((FunctionTreeItem) smt.value).calculatedFunctionName = smt.objectName; staticFunctions.add((FunctionTreeItem) smt.value); } else { - staticVars.add(new KeyValue<>(smt.objectName, smt.value)); + staticVars.add(new MyEntry<>(smt.objectName, smt.value)); } } else { ok = false; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ClassTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ClassTreeItem.java index 27800fd56..51ba8eda7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ClassTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ClassTreeItem.java @@ -16,7 +16,6 @@ */ package com.jpexs.decompiler.flash.action.treemodel.clauses; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.treemodel.ConstantPool; import com.jpexs.decompiler.flash.action.treemodel.TreeItem; @@ -24,6 +23,7 @@ import com.jpexs.decompiler.flash.graph.Block; import com.jpexs.decompiler.flash.graph.ContinueItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import com.jpexs.decompiler.flash.helpers.Helper; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import java.util.ArrayList; import java.util.List; @@ -34,8 +34,8 @@ public class ClassTreeItem extends TreeItem implements Block { public GraphTargetItem extendsOp; public List implementsOp; public GraphTargetItem className; - public List> vars; - public List> staticVars; + public List> vars; + public List> staticVars; @Override public List> getSubs() { @@ -45,7 +45,7 @@ public class ClassTreeItem extends TreeItem implements Block { return ret; } - public ClassTreeItem(GraphTargetItem className, GraphTargetItem extendsOp, List implementsOp, List functions, List> vars, List staticFunctions, List> staticVars) { + public ClassTreeItem(GraphTargetItem className, GraphTargetItem extendsOp, List implementsOp, List functions, List> vars, List staticFunctions, List> staticVars) { super(null, NOPRECEDENCE); this.className = className; this.functions = functions; @@ -81,10 +81,10 @@ public class ClassTreeItem extends TreeItem implements Block { for (GraphTargetItem f : staticFunctions) { ret += "static " + f.toString(constants) + "\r\n"; } - for (KeyValue item : vars) { + for (MyEntry item : vars) { ret += "var " + item.key.toStringNoQuotes(constants) + " = " + item.value.toString(constants) + ";\r\n"; } - for (KeyValue item : staticVars) { + for (MyEntry item : staticVars) { ret += "static var " + item.key.toStringNoQuotes(constants) + " = " + item.value.toString(constants) + ";\r\n"; } ret += "}\r\n"; diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index 1acd1f6ed..b0f571391 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -1057,37 +1057,15 @@ public class Graph { List loops2 = new ArrayList<>(loops); loops2.remove(lastP1); if (!part.leadsTo(code, lastP1.loopContinue, loops2)) { - /*boolean notlead=true; - for(GraphPart p:part.throwParts){ - if(p.leadsTo(code, lastP1.loopContinue, loops2)){ - notlead=false; - break; - } - }*/ - //if(notlead){ - /*boolean isthrow = false; - loopthrow: - for (GraphPart p : part.refs) { - if (p.throwParts.contains(part)) { - isthrow = true; - break; - } - for (GraphPart t : p.throwParts) { - if (t.leadsTo(code, part, loops)) { - isthrow = true; - break loopthrow; - } - } - } - if (!isthrow) {*/ - if (lastP1.breakCandidatesLocked == 0) { + if (debugMode) { + System.err.println("added breakCandidate " + part + " to " + lastP1); + } + lastP1.breakCandidates.add(part); lastP1.breakCandidatesLevels.add(level); return; } - //} - //} } } } @@ -1171,52 +1149,15 @@ public class Graph { } if (isLoop) { - GraphPart found; List backupCandidates = new ArrayList<>(); - List spcheck = new ArrayList<>(stopPart); - if (!spcheck.isEmpty()) { - spcheck.remove(spcheck.size() - 1); - } - for (int i = currentLoop.breakCandidates.size() - 1; i >= 0; i--) { - if (spcheck.contains(currentLoop.breakCandidates.get(i))) { - if (currentLoop.breakCandidates.get(i).start >= code.size()) { - continue; - } - currentLoop.breakCandidatesLevels.remove(i); - backupCandidates.add(currentLoop.breakCandidates.remove(i)); - } - } Map removed = new HashMap<>(); - /* - Set newcommon=new HashSet<>(); - for (GraphPart cand : currentLoop.breakCandidates) { - for (GraphPart cand2 : currentLoop.breakCandidates) { - if(cand==cand2){ - continue; - } - List c=new ArrayList<>(); - c.add(cand); - c.add(cand2); - - GraphPart common=getCommonPart(c, loops); - if(common!=null){ - if(!currentLoop.breakCandidates.contains(common)){ - newcommon.add(common); - } - } - } - } - currentLoop.breakCandidates.addAll(newcommon);*/ do { found = null; loopcand: for (GraphPart cand : currentLoop.breakCandidates) { for (GraphPart cand2 : currentLoop.breakCandidates) { if (cand.leadsTo(code, cand2, loops)) { - /*if (cand.path.equals(cand2.path)) { - found = cand2; - } else {*/ int lev1 = Integer.MAX_VALUE; int lev2 = Integer.MAX_VALUE; for (int i = 0; i < currentLoop.breakCandidates.size(); i++) { @@ -1236,7 +1177,6 @@ public class Graph { } else { found = cand; } - //} break loopcand; } } @@ -1263,7 +1203,6 @@ public class Graph { Map count = new HashMap<>(); GraphPart winner = null; int winnerCount = 0; - boolean winnerBreakCandidate = true; for (GraphPart cand : currentLoop.breakCandidates) { if (!count.containsKey(cand)) { @@ -1280,12 +1219,6 @@ public class Graph { break; } } - /*if(winnerBreakCandidate && !otherBreakCandidate){ - winnerCount = count.get(cand); - winner = cand; - winnerBreakCandidate=otherBreakCandidate; - }else if(!winnerBreakCandidate && otherBreakCandidate){ - */ if (otherBreakCandidate) { } else if (count.get(cand) > winnerCount) { winnerCount = count.get(cand); @@ -1325,8 +1258,13 @@ public class Graph { start = true; } } + List removedVisited = new ArrayList<>(); for (GraphPart r : removed.keySet()) { + if (removedVisited.contains(r)) { + continue; + } getLoops(r, loops, stopPart, false, removed.get(r), visited); + removedVisited.add(r); } start = false; for (int l = 0; l < loops.size(); l++) { @@ -1338,7 +1276,6 @@ public class Graph { el.phase = 2; } } - //currentLoop.phase = 2; getLoops(currentLoop.loopBreak, loops, stopPart, false, level, visited); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java index d3ce6d45d..a4428cff0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/GraphPart.java @@ -230,4 +230,28 @@ public class GraphPart { ret.add(this); return ret; } + + @Override + public int hashCode() { + int hash = 7; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (!(obj instanceof GraphPart)) { + return false; + } + final GraphPart other = (GraphPart) obj; + if (this.start != other.start) { + return false; + } + if (this.end != other.end) { + return false; + } + return true; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 11555d391..6275e3c9b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.gui.abc; import com.jpexs.decompiler.flash.Configuration; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; @@ -34,6 +33,7 @@ import com.jpexs.decompiler.flash.gui.abc.tablemodels.NamespaceSetTableModel; import com.jpexs.decompiler.flash.gui.abc.tablemodels.NamespaceTableModel; import com.jpexs.decompiler.flash.gui.abc.tablemodels.StringTableModel; import com.jpexs.decompiler.flash.gui.abc.tablemodels.UIntTableModel; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import java.awt.BorderLayout; import java.awt.Component; @@ -92,7 +92,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { searchIgnoreCase = ignoreCase; searchRegexp = regexp; ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); - List> allpacks = clModel.getList(); + List> allpacks = clModel.getList(); found = new ArrayList<>(); Pattern pat = null; if (regexp) { @@ -100,7 +100,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { } else { pat = Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0); } - for (KeyValue item : allpacks) { + for (MyEntry item : allpacks) { decompiledTextArea.cacheScriptPack(item.value, list); if (pat.matcher(decompiledTextArea.getCachedText(item.value)).find()) { found.add(item.value); @@ -468,7 +468,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener { public void hilightScript(String name) { ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); ScriptPack pack = null; - for (KeyValue item : clModel.getList()) { + for (MyEntry item : clModel.getList()) { if (item.key.toString().equals(name)) { pack = item.value; break; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java index 1e2836ee8..8e0917943 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java @@ -16,7 +16,6 @@ */ package com.jpexs.decompiler.flash.gui.abc; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; @@ -24,6 +23,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.View; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import java.util.ArrayList; import java.util.List; @@ -37,7 +37,7 @@ import javax.swing.tree.TreeSelectionModel; public class ClassesListTree extends JTree implements TreeSelectionListener { private List abcList; - public List> treeList; + public List> treeList; private ABCPanel abcPanel; private SWF swf; @@ -97,7 +97,7 @@ public class ClassesListTree extends JTree implements TreeSelectionListener { return selectedScripts; } - public List> getTreeList(List list) { + public List> getTreeList(List list) { return swf.getAS3Packs(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java index 78e0054ab..60625f992 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java @@ -16,12 +16,12 @@ */ package com.jpexs.decompiler.flash.gui.abc; -import com.jpexs.decompiler.flash.KeyValue; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import static com.jpexs.decompiler.flash.gui.AppStrings.translate; +import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import java.util.List; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; @@ -78,18 +78,18 @@ class ClassIndexVisitor implements TreeVisitor { public class ClassesListTreeModel implements TreeModel { private Tree classTree = new Tree(); - private List> list; + private List> list; - public List> getList() { + public List> getList() { return list; } - public ClassesListTreeModel(List> list) { + public ClassesListTreeModel(List> list) { this(list, null); } - public ClassesListTreeModel(List> list, String filter) { - for (KeyValue item : list) { + public ClassesListTreeModel(List> list, String filter) { + for (MyEntry item : list) { if (filter != null) { if (!filter.equals("")) { if (!item.key.toString().contains(filter)) { diff --git a/trunk/src/com/jpexs/decompiler/flash/KeyValue.java b/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MyEntry.java similarity index 74% rename from trunk/src/com/jpexs/decompiler/flash/KeyValue.java rename to trunk/src/com/jpexs/decompiler/flash/helpers/collections/MyEntry.java index 22fd992e3..d7c0bb660 100644 --- a/trunk/src/com/jpexs/decompiler/flash/KeyValue.java +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MyEntry.java @@ -14,8 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.jpexs.decompiler.flash; +package com.jpexs.decompiler.flash.helpers.collections; +import java.util.Map.Entry; import java.util.Objects; /** @@ -24,12 +25,12 @@ import java.util.Objects; * @param Value * @author JPEXS */ -public class KeyValue { +public class MyEntry implements Entry { public K key; public V value; - public KeyValue(K key, V value) { + public MyEntry(K key, V value) { this.key = key; this.value = value; } @@ -56,7 +57,7 @@ public class KeyValue { return false; } @SuppressWarnings("unchecked") - final KeyValue other = (KeyValue) obj; + final MyEntry other = (MyEntry) obj; if (!Objects.equals(this.key, other.key)) { return false; } @@ -65,4 +66,20 @@ public class KeyValue { } return true; } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return value; + } + + @Override + public V setValue(V value) { + this.value = value; + return value; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MyMap.java b/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MyMap.java new file mode 100644 index 000000000..8e371af03 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MyMap.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.helpers.collections; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * + * @param + * @param + * @author JPEXS + */ +public class MyMap implements Map { + + List> values = new ArrayList<>(); + + @Override + public int size() { + return values.size(); + } + + @Override + public boolean isEmpty() { + return values.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + for (MyEntry kv : values) { + if (kv.key.equals(key)) { + return true; + } + } + return false; + } + + @Override + public boolean containsValue(Object value) { + for (MyEntry kv : values) { + if (kv.value.equals(value)) { + return true; + } + } + return false; + } + + @Override + public V get(Object key) { + for (MyEntry kv : values) { + if (kv.key.equals(key)) { + return kv.value; + } + } + return null; + } + + @Override + public V put(K key, V value) { + for (MyEntry kv : values) { + if (kv.key.equals(key)) { + kv.value = value; + return value; + } + } + values.add(new MyEntry<>(key, value)); + return value; + } + + @Override + public V remove(Object key) { + for (int i = 0; i < values.size(); i++) { + MyEntry kv = values.get(i); + if (kv.key.equals(key)) { + values.remove(i); + return kv.value; + } + } + return null; + } + + @Override + public void putAll(Map m) { + for (K k : m.keySet()) { + put(k, m.get(k)); + } + } + + @Override + public void clear() { + values.clear(); + } + + @Override + public Set keySet() { + Set ret = new MySet<>(); + for (MyEntry kv : values) { + ret.add(kv.key); + } + return ret; + } + + @Override + public Collection values() { + Collection ret = new ArrayList<>(); + for (MyEntry kv : values) { + ret.add(kv.value); + } + return ret; + } + + @Override + public Set> entrySet() { + Set> ret = new MySet<>(); + ret.addAll(values); + return ret; + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MySet.java b/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MySet.java new file mode 100644 index 000000000..33b0c4f24 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/helpers/collections/MySet.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.helpers.collections; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * + * @param + * @author JPEXS + */ +public class MySet implements Set { + + List items = new ArrayList<>(); + + @Override + public int size() { + return items.size(); + } + + @Override + public boolean isEmpty() { + return items.isEmpty(); + } + + @Override + public boolean contains(Object o) { + for (T t : items) { + if (t.equals(o)) { + return true; + } + } + return false; + } + + @Override + public Iterator iterator() { + return new Iterator() { + int pos = 0; + + @Override + public boolean hasNext() { + return pos + 1 < items.size(); + } + + @Override + public T next() { + return items.get(pos++); + } + + @Override + public void remove() { + items.remove(pos--); + } + }; + } + + @Override + public Object[] toArray() { + Object[] ret = new Object[items.size()]; + for (int i = 0; i < items.size(); i++) { + ret[i] = items.get(i); + } + return ret; + } + + @Override + public T[] toArray(T[] a) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean add(T e) { + items.add(e); + return true; + } + + @Override + public boolean remove(Object o) { + for (int i = 0; i < items.size(); i++) { + if (items.get(i).equals(o)) { + items.remove(i); + return true; + } + } + return false; + } + + @Override + public boolean containsAll(Collection c) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean addAll(Collection c) { + for (T t : c) { + add(t); + } + return true; + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void clear() { + items.clear(); + } + + @Override + public String toString() { + String ret = "["; + boolean first = true; + for (T t : items) { + if (!first) { + ret += ", "; + } + ret += t.toString(); + first = false; + } + ret += "]"; + return ret; + } +}