forked from mozilla/rhino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstantEntry.java
More file actions
57 lines (51 loc) · 1.59 KB
/
ConstantEntry.java
File metadata and controls
57 lines (51 loc) · 1.59 KB
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
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.classfile;
final class ConstantEntry {
private int type;
private int intval;
private long longval;
private String str1;
private String str2;
private int hashcode;
ConstantEntry(int type, int intval, String str1, String str2) {
this.type = type;
this.intval = intval;
this.str1 = str1;
this.str2 = str2;
hashcode = type ^ intval + str1.hashCode() * str2.hashCode();
}
@Override
public int hashCode() {
return hashcode;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof ConstantEntry)) {
return false;
}
ConstantEntry entry = (ConstantEntry) obj;
if (type != entry.type) {
return false;
}
switch (type) {
case ConstantPool.CONSTANT_Integer:
case ConstantPool.CONSTANT_Float:
return intval == entry.intval;
case ConstantPool.CONSTANT_Long:
case ConstantPool.CONSTANT_Double:
return longval == entry.longval;
case ConstantPool.CONSTANT_NameAndType:
return str1.equals(entry.str1) && str2.equals(entry.str2);
case ConstantPool.CONSTANT_InvokeDynamic:
return intval == entry.intval
&& str1.equals(entry.str1)
&& str2.equals(entry.str2);
default:
throw new RuntimeException("unsupported constant type");
}
}
}