summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/convert/FieldMatches.java
diff options
context:
space:
mode:
authorGravatar Michael Smith2015-05-21 23:30:00 +0100
committerGravatar Michael Smith2015-05-21 23:30:00 +0100
commite3f452250e51b7271f3989c7dfd12e4422934942 (patch)
tree5aa482f9a6e21eb318a3e23e7d8274d77c73faf6 /src/cuchaz/enigma/convert/FieldMatches.java
downloadenigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.gz
enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.xz
enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.zip
Support Gradle alongside SSJB
This makes builds faster, simpler and better automated but still keeps Cuchaz happy. :)
Diffstat (limited to 'src/cuchaz/enigma/convert/FieldMatches.java')
-rw-r--r--src/cuchaz/enigma/convert/FieldMatches.java155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/FieldMatches.java b/src/cuchaz/enigma/convert/FieldMatches.java
new file mode 100644
index 0000000..8439a84
--- /dev/null
+++ b/src/cuchaz/enigma/convert/FieldMatches.java
@@ -0,0 +1,155 @@
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 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.convert;
12
13import java.util.Collection;
14import java.util.Set;
15
16import com.google.common.collect.BiMap;
17import com.google.common.collect.HashBiMap;
18import com.google.common.collect.HashMultimap;
19import com.google.common.collect.Multimap;
20import com.google.common.collect.Sets;
21
22import cuchaz.enigma.mapping.ClassEntry;
23import cuchaz.enigma.mapping.FieldEntry;
24
25
26public class FieldMatches {
27
28 private BiMap<FieldEntry,FieldEntry> m_matches;
29 private Multimap<ClassEntry,FieldEntry> m_matchedSourceFields;
30 private Multimap<ClassEntry,FieldEntry> m_unmatchedSourceFields;
31 private Multimap<ClassEntry,FieldEntry> m_unmatchedDestFields;
32 private Multimap<ClassEntry,FieldEntry> m_unmatchableSourceFields;
33
34 public FieldMatches() {
35 m_matches = HashBiMap.create();
36 m_matchedSourceFields = HashMultimap.create();
37 m_unmatchedSourceFields = HashMultimap.create();
38 m_unmatchedDestFields = HashMultimap.create();
39 m_unmatchableSourceFields = HashMultimap.create();
40 }
41
42 public void addMatch(FieldEntry srcField, FieldEntry destField) {
43 boolean wasAdded = m_matches.put(srcField, destField) == null;
44 assert (wasAdded);
45 wasAdded = m_matchedSourceFields.put(srcField.getClassEntry(), srcField);
46 assert (wasAdded);
47 }
48
49 public void addUnmatchedSourceField(FieldEntry fieldEntry) {
50 boolean wasAdded = m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry);
51 assert (wasAdded);
52 }
53
54 public void addUnmatchedSourceFields(Iterable<FieldEntry> fieldEntries) {
55 for (FieldEntry fieldEntry : fieldEntries) {
56 addUnmatchedSourceField(fieldEntry);
57 }
58 }
59
60 public void addUnmatchedDestField(FieldEntry fieldEntry) {
61 boolean wasAdded = m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry);
62 assert (wasAdded);
63 }
64
65 public void addUnmatchedDestFields(Iterable<FieldEntry> fieldEntries) {
66 for (FieldEntry fieldEntry : fieldEntries) {
67 addUnmatchedDestField(fieldEntry);
68 }
69 }
70
71 public void addUnmatchableSourceField(FieldEntry sourceField) {
72 boolean wasAdded = m_unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField);
73 assert (wasAdded);
74 }
75
76 public Set<ClassEntry> getSourceClassesWithUnmatchedFields() {
77 return m_unmatchedSourceFields.keySet();
78 }
79
80 public Collection<ClassEntry> getSourceClassesWithoutUnmatchedFields() {
81 Set<ClassEntry> out = Sets.newHashSet();
82 out.addAll(m_matchedSourceFields.keySet());
83 out.removeAll(m_unmatchedSourceFields.keySet());
84 return out;
85 }
86
87 public Collection<FieldEntry> getUnmatchedSourceFields() {
88 return m_unmatchedSourceFields.values();
89 }
90
91 public Collection<FieldEntry> getUnmatchedSourceFields(ClassEntry sourceClass) {
92 return m_unmatchedSourceFields.get(sourceClass);
93 }
94
95 public Collection<FieldEntry> getUnmatchedDestFields() {
96 return m_unmatchedDestFields.values();
97 }
98
99 public Collection<FieldEntry> getUnmatchedDestFields(ClassEntry destClass) {
100 return m_unmatchedDestFields.get(destClass);
101 }
102
103 public Collection<FieldEntry> getUnmatchableSourceFields() {
104 return m_unmatchableSourceFields.values();
105 }
106
107 public boolean hasSource(FieldEntry fieldEntry) {
108 return m_matches.containsKey(fieldEntry) || m_unmatchedSourceFields.containsValue(fieldEntry);
109 }
110
111 public boolean hasDest(FieldEntry fieldEntry) {
112 return m_matches.containsValue(fieldEntry) || m_unmatchedDestFields.containsValue(fieldEntry);
113 }
114
115 public BiMap<FieldEntry,FieldEntry> matches() {
116 return m_matches;
117 }
118
119 public boolean isMatchedSourceField(FieldEntry sourceField) {
120 return m_matches.containsKey(sourceField);
121 }
122
123 public boolean isMatchedDestField(FieldEntry destField) {
124 return m_matches.containsValue(destField);
125 }
126
127 public void makeMatch(FieldEntry sourceField, FieldEntry destField) {
128 boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField);
129 assert (wasRemoved);
130 wasRemoved = m_unmatchedDestFields.remove(destField.getClassEntry(), destField);
131 assert (wasRemoved);
132 addMatch(sourceField, destField);
133 }
134
135 public boolean isMatched(FieldEntry sourceField, FieldEntry destField) {
136 FieldEntry match = m_matches.get(sourceField);
137 return match != null && match.equals(destField);
138 }
139
140 public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) {
141 boolean wasRemoved = m_matches.remove(sourceField) != null;
142 assert (wasRemoved);
143 wasRemoved = m_matchedSourceFields.remove(sourceField.getClassEntry(), sourceField);
144 assert (wasRemoved);
145 addUnmatchedSourceField(sourceField);
146 addUnmatchedDestField(destField);
147 }
148
149 public void makeSourceUnmatchable(FieldEntry sourceField) {
150 assert(!isMatchedSourceField(sourceField));
151 boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField);
152 assert (wasRemoved);
153 addUnmatchableSourceField(sourceField);
154 }
155}