summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/analysis/EntryReference.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cuchaz/enigma/analysis/EntryReference.java89
1 files changed, 83 insertions, 6 deletions
diff --git a/src/cuchaz/enigma/analysis/EntryReference.java b/src/cuchaz/enigma/analysis/EntryReference.java
index f462210..869e08c 100644
--- a/src/cuchaz/enigma/analysis/EntryReference.java
+++ b/src/cuchaz/enigma/analysis/EntryReference.java
@@ -10,19 +10,96 @@
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.analysis; 11package cuchaz.enigma.analysis;
12 12
13import cuchaz.enigma.mapping.BehaviorEntry; 13import cuchaz.enigma.Util;
14import cuchaz.enigma.mapping.ClassEntry;
14import cuchaz.enigma.mapping.Entry; 15import cuchaz.enigma.mapping.Entry;
15 16
16public class EntryReference<T extends Entry> 17public class EntryReference<E extends Entry, C extends Entry>
17{ 18{
18 public T entry; 19 public E entry;
19 public BehaviorEntry caller; 20 public C context;
20 public int pos; 21 public int pos;
21 22
22 public EntryReference( T entry, BehaviorEntry caller, int pos ) 23 public EntryReference( E entry )
23 { 24 {
25 this( entry, null, -1 );
26 }
27
28 public EntryReference( E entry, C context, int pos )
29 {
30 if( entry == null )
31 {
32 throw new IllegalArgumentException( "Entry cannot be null!" );
33 }
34
24 this.entry = entry; 35 this.entry = entry;
25 this.caller = caller; 36 this.context = context;
26 this.pos = pos; 37 this.pos = pos;
27 } 38 }
39
40 public ClassEntry getClassEntry( )
41 {
42 if( context != null )
43 {
44 return context.getClassEntry();
45 }
46 return entry.getClassEntry();
47 }
48
49 @Override
50 public int hashCode( )
51 {
52 if( context != null )
53 {
54 return Util.combineHashesOrdered( entry.hashCode(), context.hashCode(), Integer.valueOf( pos ).hashCode() );
55 }
56 return entry.hashCode();
57 }
58
59 @Override
60 public boolean equals( Object other )
61 {
62 if( other instanceof EntryReference )
63 {
64 return equals( (EntryReference<?,?>)other );
65 }
66 return false;
67 }
68
69 public boolean equals( EntryReference<?,?> other )
70 {
71 // check entry first
72 boolean isEntrySame = entry.equals( other.entry );
73 if( !isEntrySame )
74 {
75 return false;
76 }
77
78 // check caller
79 if( context == null && other.context == null )
80 {
81 return true;
82 }
83 else if( context != null && other.context != null )
84 {
85 return context.equals( other.context ) && pos == other.pos;
86 }
87 return false;
88 }
89
90 @Override
91 public String toString( )
92 {
93 StringBuilder buf = new StringBuilder();
94 buf.append( entry );
95 if( context != null )
96 {
97 buf.append( " called from " );
98 buf.append( context );
99 buf.append( " (" );
100 buf.append( pos );
101 buf.append( ")" );
102 }
103 return buf.toString();
104 }
28} 105}