summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/ClassMatching.java
diff options
context:
space:
mode:
authorGravatar lclc982016-07-04 18:14:22 +1000
committerGravatar lclc982016-07-04 18:14:22 +1000
commit59e189bef2b5e6d129fb7c2c988ed0b2130e36ac (patch)
tree2b638e60905251de85a4917152d6fc39a4112194 /src/main/java/cuchaz/enigma/convert/ClassMatching.java
parentFixed Obf Class list order (diff)
downloadenigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.gz
enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.xz
enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.zip
Reformat
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/ClassMatching.java')
-rw-r--r--src/main/java/cuchaz/enigma/convert/ClassMatching.java146
1 files changed, 0 insertions, 146 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java
deleted file mode 100644
index 194b6c4..0000000
--- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java
+++ /dev/null
@@ -1,146 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.convert;
12
13import com.google.common.collect.BiMap;
14import com.google.common.collect.HashBiMap;
15import com.google.common.collect.Lists;
16import com.google.common.collect.Sets;
17
18import java.util.ArrayList;
19import java.util.Collection;
20import java.util.List;
21import java.util.Map.Entry;
22import java.util.Set;
23
24import cuchaz.enigma.mapping.ClassEntry;
25
26public class ClassMatching {
27
28 private ClassForest m_sourceClasses;
29 private ClassForest m_destClasses;
30 private BiMap<ClassEntry, ClassEntry> m_knownMatches;
31
32 public ClassMatching(ClassIdentifier sourceIdentifier, ClassIdentifier destIdentifier) {
33 m_sourceClasses = new ClassForest(sourceIdentifier);
34 m_destClasses = new ClassForest(destIdentifier);
35 m_knownMatches = HashBiMap.create();
36 }
37
38 public void addKnownMatches(BiMap<ClassEntry, ClassEntry> knownMatches) {
39 m_knownMatches.putAll(knownMatches);
40 }
41
42 public void match(Iterable<ClassEntry> sourceClasses, Iterable<ClassEntry> destClasses) {
43 for (ClassEntry sourceClass : sourceClasses) {
44 if (!m_knownMatches.containsKey(sourceClass)) {
45 m_sourceClasses.add(sourceClass);
46 }
47 }
48 for (ClassEntry destClass : destClasses) {
49 if (!m_knownMatches.containsValue(destClass)) {
50 m_destClasses.add(destClass);
51 }
52 }
53 }
54
55 public Collection<ClassMatch> matches() {
56 List<ClassMatch> matches = Lists.newArrayList();
57 for (Entry<ClassEntry, ClassEntry> entry : m_knownMatches.entrySet()) {
58 matches.add(new ClassMatch(entry.getKey(), entry.getValue()));
59 }
60 for (ClassIdentity identity : m_sourceClasses.identities()) {
61 matches.add(new ClassMatch(m_sourceClasses.getClasses(identity), m_destClasses.getClasses(identity)));
62 }
63 for (ClassIdentity identity : m_destClasses.identities()) {
64 if (!m_sourceClasses.containsIdentity(identity)) {
65 matches.add(new ClassMatch(new ArrayList<>(), m_destClasses.getClasses(identity)));
66 }
67 }
68 return matches;
69 }
70
71 public Collection<ClassEntry> sourceClasses() {
72 Set<ClassEntry> classes = Sets.newHashSet();
73 for (ClassMatch match : matches()) {
74 classes.addAll(match.sourceClasses);
75 }
76 return classes;
77 }
78
79 public Collection<ClassEntry> destClasses() {
80 Set<ClassEntry> classes = Sets.newHashSet();
81 for (ClassMatch match : matches()) {
82 classes.addAll(match.destClasses);
83 }
84 return classes;
85 }
86
87 public BiMap<ClassEntry, ClassEntry> uniqueMatches() {
88 BiMap<ClassEntry, ClassEntry> uniqueMatches = HashBiMap.create();
89 for (ClassMatch match : matches()) {
90 if (match.isMatched() && !match.isAmbiguous()) {
91 uniqueMatches.put(match.getUniqueSource(), match.getUniqueDest());
92 }
93 }
94 return uniqueMatches;
95 }
96
97 public Collection<ClassMatch> ambiguousMatches() {
98 List<ClassMatch> ambiguousMatches = Lists.newArrayList();
99 for (ClassMatch match : matches()) {
100 if (match.isMatched() && match.isAmbiguous()) {
101 ambiguousMatches.add(match);
102 }
103 }
104 return ambiguousMatches;
105 }
106
107 public Collection<ClassEntry> unmatchedSourceClasses() {
108 List<ClassEntry> classes = Lists.newArrayList();
109 for (ClassMatch match : matches()) {
110 if (!match.isMatched() && !match.sourceClasses.isEmpty()) {
111 classes.addAll(match.sourceClasses);
112 }
113 }
114 return classes;
115 }
116
117 public Collection<ClassEntry> unmatchedDestClasses() {
118 List<ClassEntry> classes = Lists.newArrayList();
119 for (ClassMatch match : matches()) {
120 if (!match.isMatched() && !match.destClasses.isEmpty()) {
121 classes.addAll(match.destClasses);
122 }
123 }
124 return classes;
125 }
126
127 @Override
128 public String toString() {
129
130 // count the ambiguous classes
131 int numAmbiguousSource = 0;
132 int numAmbiguousDest = 0;
133 for (ClassMatch match : ambiguousMatches()) {
134 numAmbiguousSource += match.sourceClasses.size();
135 numAmbiguousDest += match.destClasses.size();
136 }
137
138 StringBuilder buf = new StringBuilder();
139 buf.append(String.format("%20s%8s%8s\n", "", "Source", "Dest"));
140 buf.append(String.format("%20s%8d%8d\n", "Classes", sourceClasses().size(), destClasses().size()));
141 buf.append(String.format("%20s%8d%8d\n", "Uniquely matched", uniqueMatches().size(), uniqueMatches().size()));
142 buf.append(String.format("%20s%8d%8d\n", "Ambiguously matched", numAmbiguousSource, numAmbiguousDest));
143 buf.append(String.format("%20s%8d%8d\n", "Unmatched", unmatchedSourceClasses().size(), unmatchedDestClasses().size()));
144 return buf.toString();
145 }
146}