-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBasicStructure.java
71 lines (61 loc) · 1.63 KB
/
BasicStructure.java
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
/*
Written 1999 by Douglas Greiman.
This software may be used and distributed according to the terms
of the GNU Public License, incorporated herein by reference.
*/
package duggelz.jape;
import java.util.Hashtable;
public abstract class BasicStructure implements Structure
{
// Instance data
public Hashtable fields;
public byte[] data;
public Structure nextStructure;
// Instance methods
public BasicStructure(Hashtable classFields) {
this.fields = classFields;
}
public void chain(Structure nextStructure) {
this.nextStructure = nextStructure;
}
public String get(String name) {
Field field = (Field) fields.get(name);
if( field == null ) {
if( this.nextStructure != null ) {
return this.nextStructure.get(name);
} else {
return null;
}
}
return field.get(this.data);
}
public int getInt(String name) {
Field field = (Field) fields.get(name);
if( field == null ) {
if( this.nextStructure != null ) {
return this.nextStructure.getInt(name);
} else {
return 0;
}
}
return field.getInt(this.data);
}
public void set(String name, String value) {
Field field = (Field) fields.get(name);
if( field != null ) {
field.set(this.data, value);
}
if( this.nextStructure != null ) {
this.nextStructure.set(name, value);
}
}
public void setInt(String name, int value) {
Field field = (Field) fields.get(name);
if( field != null ) {
field.setInt(this.data, value);
}
if( this.nextStructure != null ) {
this.nextStructure.setInt(name, value);
}
}
}