@Test public void testConvertStringWithInfinity() throws Exception { IntRhsFunction f = new IntRhsFunction(); try { f.execute(rhsFuncContext, Symbols.asList(syms, Double.toString(Double.POSITIVE_INFINITY))); fail("Infinity can't be cast to an integer."); } catch (RhsFunctionException e) { } }
public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkArgumentCount(this, arguments); final Symbol arg = arguments.get(0); final IntegerSymbol intSym = arg.asInteger(); if(intSym != null) { return intSym; } final DoubleSymbol doubleSym = arg.asDouble(); if(doubleSym != null) { return context.getSymbols().createInteger((long) doubleSym.getValue()); } if(arg.asIdentifier() != null) { throw new RhsFunctionException("Identifier passed to int RHS function: " + arg); } final String string = arg.toString(); try { return context.getSymbols().createInteger(parseString(string)); } catch(NumberFormatException e) { throw new RhsFunctionException(arg + " is not a valid number."); } }
IntRhsFunction extends AbstractRhsFunctionHandler { public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkArgumentCount(this, arguments); final Symbol arg = arguments.get(0); final IntegerSymbol intSym = arg.asInteger(); if(intSym != null) { return intSym; } final DoubleSymbol doubleSym = arg.asDouble(); if(doubleSym != null) { return context.getSymbols().createInteger((long) doubleSym.getValue()); } if(arg.asIdentifier() != null) { throw new RhsFunctionException("Identifier passed to int RHS function: " + arg); } final String string = arg.toString(); try { return context.getSymbols().createInteger(parseString(string)); } catch(NumberFormatException e) { throw new RhsFunctionException(arg + " is not a valid number."); } } }
IntRhsFunction extends AbstractRhsFunctionHandler { public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkArgumentCount(this, arguments); final Symbol arg = arguments.get(0); final IntegerSymbol intSym = arg.asInteger(); if(intSym != null) { return intSym; } final DoubleSymbol doubleSym = arg.asDouble(); if(doubleSym != null) { return context.getSymbols().createInteger((long) doubleSym.getValue()); } if(arg.asIdentifier() != null) { throw new RhsFunctionException("Identifier passed to int RHS function: " + arg); } final String string = arg.toString(); try { return context.getSymbols().createInteger(parseString(string)); } catch(NumberFormatException e) { throw new RhsFunctionException(arg + " is not a valid number."); } } IntRhsFunction(); }
IntRhsFunction extends AbstractRhsFunctionHandler { public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkArgumentCount(this, arguments); final Symbol arg = arguments.get(0); final IntegerSymbol intSym = arg.asInteger(); if(intSym != null) { return intSym; } final DoubleSymbol doubleSym = arg.asDouble(); if(doubleSym != null) { return context.getSymbols().createInteger((long) doubleSym.getValue()); } if(arg.asIdentifier() != null) { throw new RhsFunctionException("Identifier passed to int RHS function: " + arg); } final String string = arg.toString(); try { return context.getSymbols().createInteger(parseString(string)); } catch(NumberFormatException e) { throw new RhsFunctionException(arg + " is not a valid number."); } } IntRhsFunction(); Symbol execute(RhsFunctionContext context, List<Symbol> arguments); }
IntRhsFunction extends AbstractRhsFunctionHandler { public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { RhsFunctions.checkArgumentCount(this, arguments); final Symbol arg = arguments.get(0); final IntegerSymbol intSym = arg.asInteger(); if(intSym != null) { return intSym; } final DoubleSymbol doubleSym = arg.asDouble(); if(doubleSym != null) { return context.getSymbols().createInteger((long) doubleSym.getValue()); } if(arg.asIdentifier() != null) { throw new RhsFunctionException("Identifier passed to int RHS function: " + arg); } final String string = arg.toString(); try { return context.getSymbols().createInteger(parseString(string)); } catch(NumberFormatException e) { throw new RhsFunctionException(arg + " is not a valid number."); } } IntRhsFunction(); Symbol execute(RhsFunctionContext context, List<Symbol> arguments);  }