summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/MemberMatches.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/convert/MemberMatches.java')
-rw-r--r--src/main/java/cuchaz/enigma/convert/MemberMatches.java143
1 files changed, 0 insertions, 143 deletions
diff --git a/src/main/java/cuchaz/enigma/convert/MemberMatches.java b/src/main/java/cuchaz/enigma/convert/MemberMatches.java
deleted file mode 100644
index 662c1db..0000000
--- a/src/main/java/cuchaz/enigma/convert/MemberMatches.java
+++ /dev/null
@@ -1,143 +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.*;
14
15import java.util.Collection;
16import java.util.Set;
17
18import cuchaz.enigma.mapping.ClassEntry;
19import cuchaz.enigma.mapping.Entry;
20
21
22public class MemberMatches<T extends Entry> {
23
24 private BiMap<T, T> m_matches;
25 private Multimap<ClassEntry, T> m_matchedSourceEntries;
26 private Multimap<ClassEntry, T> m_unmatchedSourceEntries;
27 private Multimap<ClassEntry, T> m_unmatchedDestEntries;
28 private Multimap<ClassEntry, T> m_unmatchableSourceEntries;
29
30 public MemberMatches() {
31 m_matches = HashBiMap.create();
32 m_matchedSourceEntries = HashMultimap.create();
33 m_unmatchedSourceEntries = HashMultimap.create();
34 m_unmatchedDestEntries = HashMultimap.create();
35 m_unmatchableSourceEntries = HashMultimap.create();
36 }
37
38 public void addMatch(T srcEntry, T destEntry) {
39 boolean wasAdded = m_matches.put(srcEntry, destEntry) == null;
40 assert (wasAdded);
41 wasAdded = m_matchedSourceEntries.put(srcEntry.getClassEntry(), srcEntry);
42 assert (wasAdded);
43 }
44
45 public void addUnmatchedSourceEntry(T sourceEntry) {
46 boolean wasAdded = m_unmatchedSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry);
47 assert (wasAdded);
48 }
49
50 public void addUnmatchedDestEntry(T destEntry) {
51 boolean wasAdded = m_unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry);
52 assert (wasAdded);
53 }
54
55 public void addUnmatchableSourceEntry(T sourceEntry) {
56 boolean wasAdded = m_unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry);
57 assert (wasAdded);
58 }
59
60 public Set<ClassEntry> getSourceClassesWithUnmatchedEntries() {
61 return m_unmatchedSourceEntries.keySet();
62 }
63
64 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedEntries() {
65 Set<ClassEntry> out = Sets.newHashSet();
66 out.addAll(m_matchedSourceEntries.keySet());
67 out.removeAll(m_unmatchedSourceEntries.keySet());
68 return out;
69 }
70
71 public Collection<T> getUnmatchedSourceEntries() {
72 return m_unmatchedSourceEntries.values();
73 }
74
75 public Collection<T> getUnmatchedSourceEntries(ClassEntry sourceClass) {
76 return m_unmatchedSourceEntries.get(sourceClass);
77 }
78
79 public Collection<T> getUnmatchedDestEntries() {
80 return m_unmatchedDestEntries.values();
81 }
82
83 public Collection<T> getUnmatchedDestEntries(ClassEntry destClass) {
84 return m_unmatchedDestEntries.get(destClass);
85 }
86
87 public Collection<T> getUnmatchableSourceEntries() {
88 return m_unmatchableSourceEntries.values();
89 }
90
91 public boolean hasSource(T sourceEntry) {
92 return m_matches.containsKey(sourceEntry) || m_unmatchedSourceEntries.containsValue(sourceEntry);
93 }
94
95 public boolean hasDest(T destEntry) {
96 return m_matches.containsValue(destEntry) || m_unmatchedDestEntries.containsValue(destEntry);
97 }
98
99 public BiMap<T, T> matches() {
100 return m_matches;
101 }
102
103 public boolean isMatchedSourceEntry(T sourceEntry) {
104 return m_matches.containsKey(sourceEntry);
105 }
106
107 public boolean isMatchedDestEntry(T destEntry) {
108 return m_matches.containsValue(destEntry);
109 }
110
111 public boolean isUnmatchableSourceEntry(T sourceEntry) {
112 return m_unmatchableSourceEntries.containsEntry(sourceEntry.getClassEntry(), sourceEntry);
113 }
114
115 public void makeMatch(T sourceEntry, T destEntry) {
116 boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
117 assert (wasRemoved);
118 wasRemoved = m_unmatchedDestEntries.remove(destEntry.getClassEntry(), destEntry);
119 assert (wasRemoved);
120 addMatch(sourceEntry, destEntry);
121 }
122
123 public boolean isMatched(T sourceEntry, T destEntry) {
124 T match = m_matches.get(sourceEntry);
125 return match != null && match.equals(destEntry);
126 }
127
128 public void unmakeMatch(T sourceEntry, T destEntry) {
129 boolean wasRemoved = m_matches.remove(sourceEntry) != null;
130 assert (wasRemoved);
131 wasRemoved = m_matchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
132 assert (wasRemoved);
133 addUnmatchedSourceEntry(sourceEntry);
134 addUnmatchedDestEntry(destEntry);
135 }
136
137 public void makeSourceUnmatchable(T sourceEntry) {
138 assert (!isMatchedSourceEntry(sourceEntry));
139 boolean wasRemoved = m_unmatchedSourceEntries.remove(sourceEntry.getClassEntry(), sourceEntry);
140 assert (wasRemoved);
141 addUnmatchableSourceEntry(sourceEntry);
142 }
143}