summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/SourceIndex.java
blob: a4b5329b40ca3bd144a1c9c1e1e786c4a783d891 (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
/*******************************************************************************
 * Copyright (c) 2014 Jeff Martin.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Jeff Martin - initial API and implementation
 ******************************************************************************/
package cuchaz.enigma.analysis;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import jsyntaxpane.Token;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;

public class SourceIndex implements Iterable<Map.Entry<Object,Token>>
{
	private BiMap<Object,Token> m_entryToToken;
	private BiMap<Token,Object> m_tokenToEntry;
	
	public SourceIndex( )
	{
		m_entryToToken = HashBiMap.create();
		m_tokenToEntry = m_entryToToken.inverse();
	}
	
	public void add( Object entry, Token token )
	{
		m_entryToToken.put( entry, token );
	}
	
	public Iterator<Map.Entry<Object,Token>> iterator( )
	{
		return m_entryToToken.entrySet().iterator();
	}
	
	public Set<Token> tokens( )
	{
		return m_entryToToken.values();
	}
	
	public Object getEntry( Token token )
	{
		return m_tokenToEntry.get( token );
	}
	
	public Object getToken( Object entry )
	{
		return m_entryToToken.get( entry );
	}
}