diff options
Diffstat (limited to 'src/main/java/org/gnunet/construct/ReflectUtil.java')
-rw-r--r-- | src/main/java/org/gnunet/construct/ReflectUtil.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/org/gnunet/construct/ReflectUtil.java b/src/main/java/org/gnunet/construct/ReflectUtil.java index 1115641..b05a829 100644 --- a/src/main/java/org/gnunet/construct/ReflectUtil.java +++ b/src/main/java/org/gnunet/construct/ReflectUtil.java | |||
@@ -78,7 +78,7 @@ public class ReflectUtil { | |||
78 | * An enumeration of all built-in type that can store integers. | 78 | * An enumeration of all built-in type that can store integers. |
79 | */ | 79 | */ |
80 | public enum NumFieldType { | 80 | public enum NumFieldType { |
81 | BIGNUM, BYTE_PRIM, SHORT_PRIM, INT_PRIM, LONG_PRIM, CHAR_PRIM | 81 | BIGNUM, BYTE_PRIM, SHORT_PRIM, INT_PRIM, LONG_PRIM, BOOLEAN, CHAR_PRIM |
82 | } | 82 | } |
83 | 83 | ||
84 | /** | 84 | /** |
@@ -107,6 +107,8 @@ public class ReflectUtil { | |||
107 | targetType = NumFieldType.CHAR_PRIM; | 107 | targetType = NumFieldType.CHAR_PRIM; |
108 | } else if (f.getType().equals(BigInteger.class)) { | 108 | } else if (f.getType().equals(BigInteger.class)) { |
109 | targetType = NumFieldType.BIGNUM; | 109 | targetType = NumFieldType.BIGNUM; |
110 | } else if (f.getType().equals(Boolean.TYPE)) { | ||
111 | targetType = NumFieldType.BOOLEAN; | ||
110 | } else { | 112 | } else { |
111 | throw new AssertionError( | 113 | throw new AssertionError( |
112 | "expected numeric type, got: " + f.getType()); | 114 | "expected numeric type, got: " + f.getType()); |
@@ -134,6 +136,9 @@ public class ReflectUtil { | |||
134 | case BIGNUM: | 136 | case BIGNUM: |
135 | targetField.set(obj, BigInteger.valueOf(val)); | 137 | targetField.set(obj, BigInteger.valueOf(val)); |
136 | break; | 138 | break; |
139 | case BOOLEAN: | ||
140 | targetField.setBoolean(obj, (val != 0)); | ||
141 | break; | ||
137 | } | 142 | } |
138 | } catch (IllegalArgumentException e) { | 143 | } catch (IllegalArgumentException e) { |
139 | throw new AssertionError("cannot access field"); | 144 | throw new AssertionError("cannot access field"); |
@@ -163,8 +168,10 @@ public class ReflectUtil { | |||
163 | return targetField.getByte(obj); | 168 | return targetField.getByte(obj); |
164 | case CHAR_PRIM: | 169 | case CHAR_PRIM: |
165 | return targetField.getChar(obj); | 170 | return targetField.getChar(obj); |
171 | case BOOLEAN: | ||
172 | return targetField.getBoolean(obj) ? 1 : 0; | ||
166 | case BIGNUM: | 173 | case BIGNUM: |
167 | throw new RuntimeException("get() called on NumField that is a BigInteger"); | 174 | throw new RuntimeException("get() called on NumField that is a BigInteger (getBig() must be used instead)"); |
168 | default: | 175 | default: |
169 | throw new AssertionError("unreachable"); | 176 | throw new AssertionError("unreachable"); |
170 | } | 177 | } |