aboutsummaryrefslogtreecommitdiff
path: root/java/com/xagasoft
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-02-13 16:53:22 +0000
committerMike Buland <eichlan@xagasoft.com>2012-02-13 16:53:22 +0000
commit3d872dc4a5f91ca9c1041526358ceb4aaa31d39c (patch)
treeceaeb797f86d3a2f7a4e0b4aaa28fe109f02488c /java/com/xagasoft
parent06f34a151f59343809154268da272022994fef45 (diff)
downloadlibgats-3d872dc4a5f91ca9c1041526358ceb4aaa31d39c.tar.gz
libgats-3d872dc4a5f91ca9c1041526358ceb4aaa31d39c.tar.bz2
libgats-3d872dc4a5f91ca9c1041526358ceb4aaa31d39c.tar.xz
libgats-3d872dc4a5f91ca9c1041526358ceb4aaa31d39c.zip
Trying a more sensible handling for get helpers in GatsDictionary, they throw
an exception now if the key isn't found. getInt and getFloat will both probably be complimented by getBigInt and getBigFloat or something like it later on, but we'll always return types from those helpers that can't contain a null, so exceptions it is.
Diffstat (limited to '')
-rw-r--r--java/com/xagasoft/gats/GatsDictionary.java28
-rw-r--r--java/com/xagasoft/gats/KeyNotFoundException.java23
2 files changed, 43 insertions, 8 deletions
diff --git a/java/com/xagasoft/gats/GatsDictionary.java b/java/com/xagasoft/gats/GatsDictionary.java
index 654dc6c..3517b68 100644
--- a/java/com/xagasoft/gats/GatsDictionary.java
+++ b/java/com/xagasoft/gats/GatsDictionary.java
@@ -147,9 +147,12 @@ public class GatsDictionary extends GatsObject implements Map<String,GatsObject>
147 * key specified does not appear in the GatsDictionary or is not the correct 147 * key specified does not appear in the GatsDictionary or is not the correct
148 * type you will get the expected exception. 148 * type you will get the expected exception.
149 */ 149 */
150 public long getInt( String key ) 150 public long getInt( String key ) throws KeyNotFoundException
151 { 151 {
152 return ((GatsInteger)hValue.get( key )).getValue(); 152 GatsInteger ret = (GatsInteger)hValue.get( key );
153 if( ret == null )
154 throw new KeyNotFoundException( this, key );
155 return ret.getValue();
153 } 156 }
154 157
155 /** 158 /**
@@ -158,9 +161,12 @@ public class GatsDictionary extends GatsObject implements Map<String,GatsObject>
158 * key specified does not appear in the GatsDictionary or is not the correct 161 * key specified does not appear in the GatsDictionary or is not the correct
159 * type you will get the expected exception. 162 * type you will get the expected exception.
160 */ 163 */
161 public double getFloat( String key ) 164 public double getFloat( String key ) throws KeyNotFoundException
162 { 165 {
163 return ((GatsFloat)hValue.get( key )).getValue(); 166 GatsFloat ret = (GatsFloat)hValue.get( key );
167 if( ret == null )
168 throw new KeyNotFoundException( this, key );
169 return ret.getValue();
164 } 170 }
165 171
166 /** 172 /**
@@ -169,9 +175,12 @@ public class GatsDictionary extends GatsObject implements Map<String,GatsObject>
169 * key specified does not appear in the GatsDictionary or is not the correct 175 * key specified does not appear in the GatsDictionary or is not the correct
170 * type you will get the expected exception. 176 * type you will get the expected exception.
171 */ 177 */
172 public boolean getBool( String key ) 178 public boolean getBool( String key ) throws KeyNotFoundException
173 { 179 {
174 return ((GatsBoolean)hValue.get( key )).getValue(); 180 GatsBoolean ret = (GatsBoolean)hValue.get( key );
181 if( ret == null )
182 throw new KeyNotFoundException( this, key );
183 return ret.getValue();
175 } 184 }
176 185
177 /** 186 /**
@@ -180,9 +189,12 @@ public class GatsDictionary extends GatsObject implements Map<String,GatsObject>
180 * key specified does not appear in the GatsDictionary or is not the correct 189 * key specified does not appear in the GatsDictionary or is not the correct
181 * type you will get the expected exception. 190 * type you will get the expected exception.
182 */ 191 */
183 public byte[] getString( String key ) 192 public byte[] getString( String key ) throws KeyNotFoundException
184 { 193 {
185 return ((GatsString)hValue.get( key )).getValue(); 194 GatsString ret = (GatsString)hValue.get( key );
195 if( ret == null )
196 throw new KeyNotFoundException( this, key );
197 return ret.getValue();
186 } 198 }
187 199
188 /** 200 /**
diff --git a/java/com/xagasoft/gats/KeyNotFoundException.java b/java/com/xagasoft/gats/KeyNotFoundException.java
new file mode 100644
index 0000000..d46fc47
--- /dev/null
+++ b/java/com/xagasoft/gats/KeyNotFoundException.java
@@ -0,0 +1,23 @@
1package com.xagasoft.gats;
2
3public class KeyNotFoundException extends Exception
4{
5 private Object oSrc = null;
6 private String sKey = null;
7
8 public KeyNotFoundException( Object oSrc, String sKey )
9 {
10 this.oSrc = oSrc;
11 this.sKey = sKey;
12 }
13
14 public Object getSource()
15 {
16 return oSrc;
17 }
18
19 public String getKey()
20 {
21 return sKey;
22 }
23}