summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/mapping/ArgumentEntry.java
blob: 0c25c4d3174ebc175757c65c8bcdf52f0a5ba2ae (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
 * 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.mapping;

import java.io.Serializable;

import cuchaz.enigma.Util;

public class ArgumentEntry implements Entry, Serializable
{
	private static final long serialVersionUID = 4472172468162696006L;
	
	private MethodEntry m_methodEntry;
	private int m_index;
	private String m_name;
	
	public ArgumentEntry( MethodEntry methodEntry, int index, String name )
	{
		if( methodEntry == null )
		{
			throw new IllegalArgumentException( "Method cannot be null!" );
		}
		if( index < 0 )
		{
			throw new IllegalArgumentException( "Index must be non-negative!" );
		}
		if( name == null )
		{
			throw new IllegalArgumentException( "Argument name cannot be null!" );
		}
		
		m_methodEntry = methodEntry;
		m_index = index;
		m_name = name;
	}
	
	public ArgumentEntry( ArgumentEntry other )
	{
		m_methodEntry = new MethodEntry( other.m_methodEntry );
		m_index = other.m_index;
		m_name = other.m_name;
	}
	
	public MethodEntry getMethodEntry( )
	{
		return m_methodEntry;
	}
	
	public int getIndex( )
	{
		return m_index;
	}
	
	@Override
	public String getName( )
	{
		return m_name;
	}
	
	public ClassEntry getClassEntry( )
	{
		return m_methodEntry.getClassEntry();
	}
	
	@Override
	public String getClassName( )
	{
		return m_methodEntry.getClassName();
	}
	
	public String getMethodName( )
	{
		return m_methodEntry.getName();
	}
	
	public String getMethodSignature( )
	{
		return m_methodEntry.getSignature();
	}
	
	@Override
	public int hashCode( )
	{
		return Util.combineHashesOrdered( m_methodEntry, Integer.valueOf( m_index ).hashCode(), m_name.hashCode() );
	}
	
	@Override
	public boolean equals( Object other )
	{
		if( other instanceof ArgumentEntry )
		{
			return equals( (ArgumentEntry)other );
		}
		return false;
	}
	
	public boolean equals( ArgumentEntry other )
	{
		return m_methodEntry.equals( other.m_methodEntry )
			&& m_index == other.m_index
			&& m_name.equals( other.m_name );
	}
	
	@Override
	public String toString( )
	{
		return m_methodEntry.toString() + "(" + m_index + ":" + m_name + ")";
	}
}