summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/convert/ClassForest.java
blob: 4542fb33949a5e2856ea7bff9802834e36bf364b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*******************************************************************************
 * Copyright (c) 2015 Jeff Martin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public
 * License v3.0 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Contributors:
 * Jeff Martin - initial API and implementation
 ******************************************************************************/

package cuchaz.enigma.convert;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import cuchaz.enigma.mapping.ClassEntry;

import java.util.Collection;

public class ClassForest {

	private ClassIdentifier identifier;
	private Multimap<ClassIdentity, ClassEntry> forest;

	public ClassForest(ClassIdentifier identifier) {
		this.identifier = identifier;
		this.forest = HashMultimap.create();
	}

	public void addAll(Iterable<ClassEntry> entries) {
		for (ClassEntry entry : entries) {
			add(entry);
		}
	}

	public void add(ClassEntry entry) {
		try {
			this.forest.put(this.identifier.identify(entry), entry);
		} catch (ClassNotFoundException ex) {
			throw new Error("Unable to find class " + entry.getName());
		}
	}

	public Collection<ClassIdentity> identities() {
		return this.forest.keySet();
	}

	public Collection<ClassEntry> classes() {
		return this.forest.values();
	}

	public Collection<ClassEntry> getClasses(ClassIdentity identity) {
		return this.forest.get(identity);
	}

	public boolean containsIdentity(ClassIdentity identity) {
		return this.forest.containsKey(identity);
	}
}