-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathChoiceField.java
53 lines (43 loc) · 1.14 KB
/
ChoiceField.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
/*
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.*;
public class ChoiceField implements Field
{
private Field baseField;
private String[] list;
private Hashtable table;
public ChoiceField(Field baseField, Hashtable table)
{
this.baseField = baseField;
this.list = list;
this.table = table;
}
public String get(byte[] data)
{
int value = this.baseField.getInt(data);
String str = (String) this.table.get(new Integer(value));
return str;
}
public int getInt(byte[] data)
{
int value = this.baseField.getInt(data);
return value;
}
public void set(byte[] data, String str) throws NumberFormatException
{
Integer val = (Integer) this.table.get(str);
if( val == null ) {
return;
}
int value = val.intValue();
this.setInt(data, value);
}
public void setInt(byte[] data, int value) throws NumberFormatException
{
this.baseField.setInt(data, value);
}
}