summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/SourceIndex.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/analysis/SourceIndex.java')
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndex.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java
new file mode 100644
index 0000000..a4b5329
--- /dev/null
+++ b/src/cuchaz/enigma/analysis/SourceIndex.java
@@ -0,0 +1,57 @@
1/*******************************************************************************
2 * Copyright (c) 2014 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Public License v3.0
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/gpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.analysis;
12
13import java.util.Iterator;
14import java.util.Map;
15import java.util.Set;
16
17import jsyntaxpane.Token;
18
19import com.google.common.collect.BiMap;
20import com.google.common.collect.HashBiMap;
21
22public class SourceIndex implements Iterable<Map.Entry<Object,Token>>
23{
24 private BiMap<Object,Token> m_entryToToken;
25 private BiMap<Token,Object> m_tokenToEntry;
26
27 public SourceIndex( )
28 {
29 m_entryToToken = HashBiMap.create();
30 m_tokenToEntry = m_entryToToken.inverse();
31 }
32
33 public void add( Object entry, Token token )
34 {
35 m_entryToToken.put( entry, token );
36 }
37
38 public Iterator<Map.Entry<Object,Token>> iterator( )
39 {
40 return m_entryToToken.entrySet().iterator();
41 }
42
43 public Set<Token> tokens( )
44 {
45 return m_entryToToken.values();
46 }
47
48 public Object getEntry( Token token )
49 {
50 return m_tokenToEntry.get( token );
51 }
52
53 public Object getToken( Object entry )
54 {
55 return m_entryToToken.get( entry );
56 }
57}