Revision 44444

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/ExpressionUtils.java
224 224
        File f = new File(r);
225 225
        return f;
226 226
    }
227
    
227

  
228
    public static int parseInt(String s) throws NumberFormatException {
229
        if( StringUtils.isBlank(s) ) {
230
            throw new NumberFormatException("Can't get integer from a blank string.");
231
        }
232
        MutableSymbolTable symbolTable = createSymbolTable();
233
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
234
        Object x;
235
        try {
236
            x = manager.evaluate(symbolTable, s);
237
            if( x instanceof Number ) {
238
                return ((Number) x).intValue();
239
            }
240
        } catch(Exception ex) {
241
            NumberFormatException ex1 = new NumberFormatException("Can't get integer from '"+s+"'.");
242
            ex1.initCause(ex);
243
            throw ex;
244
        }
245
        if( x == null ) {
246
            throw new NumberFormatException("Can't get integer from '"+s+"' value is null.");
247
        }
248
        throw new NumberFormatException("Can't get integer from '"+s+"' value is a "+x.getClass().getSimpleName()+".");
249
    }
250

  
251
    public static long parseLong(String s) throws NumberFormatException {
252
        if( StringUtils.isBlank(s) ) {
253
            throw new NumberFormatException("Can't get long from a blank string.");
254
        }
255
        MutableSymbolTable symbolTable = createSymbolTable();
256
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
257
        Object x;
258
        try {
259
            x = manager.evaluate(symbolTable, s);
260
            if( x instanceof Number ) {
261
                return ((Number) x).longValue();
262
            }
263
        } catch(Exception ex) {
264
            NumberFormatException ex1 = new NumberFormatException("Can't get long from '"+s+"'.");
265
            ex1.initCause(ex);
266
            throw ex;
267
        }
268
        if( x == null ) {
269
            throw new NumberFormatException("Can't get long from '"+s+"' value is null.");
270
        }
271
        throw new NumberFormatException("Can't get long from '"+s+"' value is a "+x.getClass().getSimpleName()+".");
272
    }
273

  
274
    public static double parseDouble(String s) throws NumberFormatException {
275
        if( StringUtils.isBlank(s) ) {
276
            throw new NumberFormatException("Can't get double from a blank string.");
277
        }
278
        MutableSymbolTable symbolTable = createSymbolTable();
279
        ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager();
280
        Object x;
281
        try {
282
            x = manager.evaluate(symbolTable, s);
283
            if( x instanceof Number ) {
284
                return ((Number) x).doubleValue();
285
            }
286
        } catch(Exception ex) {
287
            NumberFormatException ex1 = new NumberFormatException("Can't get double from '"+s+"'.");
288
            ex1.initCause(ex);
289
            throw ex;
290
        }
291
        if( x == null ) {
292
            throw new NumberFormatException("Can't get double from '"+s+"' value is null.");
293
        }
294
        throw new NumberFormatException("Can't get double from '"+s+"' value is a "+x.getClass().getSimpleName()+".");
295
    }
228 296
}

Also available in: Unified diff