summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/mapping/ConstructorEntry.java
blob: d99d1c35d104157368888ace708331ada290a4d2 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
 * 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 ConstructorEntry implements BehaviorEntry, Serializable
{
	private static final long serialVersionUID = -868346075317366758L;
	
	private ClassEntry m_classEntry;
	private String m_signature;
	
	public ConstructorEntry( ClassEntry classEntry )
	{
		this( classEntry, null );
	}
	
	public ConstructorEntry( ClassEntry classEntry, String signature )
	{
		if( classEntry == null )
		{
			throw new IllegalArgumentException( "Class cannot be null!" );
		}
		
		m_classEntry = classEntry;
		m_signature = signature;
	}
	
	public ConstructorEntry( ConstructorEntry other )
	{
		m_classEntry = new ClassEntry( other.m_classEntry );
		m_signature = other.m_signature;
	}
	
	public ConstructorEntry( ConstructorEntry other, String newClassName )
	{
		m_classEntry = new ClassEntry( newClassName );
		m_signature = other.m_signature;
	}
	
	@Override
	public ClassEntry getClassEntry( )
	{
		return m_classEntry;
	}
	
	@Override
	public String getName( )
	{
		if( isStatic() )
		{
			return "<clinit>";
		}
		return "<init>";
	}
	
	public boolean isStatic( )
	{
		return m_signature == null;
	}
	
	@Override
	public String getSignature( )
	{
		return m_signature;
	}
	
	@Override
	public String getClassName( )
	{
		return m_classEntry.getName();
	}
	
	@Override
	public ConstructorEntry cloneToNewClass( ClassEntry classEntry )
	{
		return new ConstructorEntry( this, classEntry.getName() );
	}
	
	@Override
	public int hashCode( )
	{
		if( isStatic() )
		{
			return Util.combineHashesOrdered( m_classEntry );
		}
		else
		{
			return Util.combineHashesOrdered( m_classEntry, m_signature );
		}
	}
	
	@Override
	public boolean equals( Object other )
	{
		if( other instanceof ConstructorEntry )
		{
			return equals( (ConstructorEntry)other );
		}
		return false;
	}
	
	public boolean equals( ConstructorEntry other )
	{
		if( isStatic() != other.isStatic() )
		{
			return false;
		}
		
		if( isStatic() )
		{
			return m_classEntry.equals( other.m_classEntry );
		}
		else
		{
			return m_classEntry.equals( other.m_classEntry ) && m_signature.equals( other.m_signature );
		}
	}
	
	@Override
	public String toString( )
	{
		if( isStatic() )
		{
			return m_classEntry.getName() + "." + getName();
		}
		else
		{
			return m_classEntry.getName() + "." + getName() + m_signature;
		}
	}
}