@Override public Double parseLiteral(Object input) { if (input instanceof IntValue) { return ((IntValue) input).getValue().doubleValue(); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue().doubleValue(); } else { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } } });
private Builder(FloatValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); }
@Override public BigDecimal parseLiteral(Object input) { if (input instanceof StringValue) { try { return new BigDecimal(((StringValue) input).getValue()); } catch (NumberFormatException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigDecimal' : '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { return new BigDecimal(((IntValue) input).getValue()); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } });
@Override public BigInteger parseLiteral(Object input) { if (input instanceof StringValue) { try { return new BigDecimal(((StringValue) input).getValue()).toBigIntegerExact(); } catch (NumberFormatException | ArithmeticException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { return ((IntValue) input).getValue(); } else if (input instanceof FloatValue) { try { return ((FloatValue) input).getValue().toBigIntegerExact(); } catch (ArithmeticException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" ); } } throw new CoercingParseLiteralException( "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } });
private String value(Value value) { String argSep = compactMode ? "," : ", "; if (value instanceof IntValue) { return valueOf(((IntValue) value).getValue()); } else if (value instanceof FloatValue) { return valueOf(((FloatValue) value).getValue()); } else if (value instanceof StringValue) { return wrap("\"", valueOf(((StringValue) value).getValue()), "\""); } else if (value instanceof EnumValue) { return valueOf(((EnumValue) value).getName()); } else if (value instanceof BooleanValue) { return valueOf(((BooleanValue) value).isValue()); } else if (value instanceof NullValue) { return "null"; } else if (value instanceof ArrayValue) { return "[" + join(((ArrayValue) value).getValues(), argSep) + "]"; } else if (value instanceof ObjectValue) { return "{" + join(((ObjectValue) value).getObjectFields(), argSep) + "}"; } else if (value instanceof VariableReference) { return "$" + ((VariableReference) value).getName(); } return ""; }
@Override public Object parseLiteral(Object input) { return ((FloatValue) input).getValue().doubleValue(); } });
@Override public Double parseLiteral(Object input) { if (input instanceof IntValue) { return ((IntValue) input).getValue().doubleValue(); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue().doubleValue(); } else { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } } });
private Builder(FloatValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); }
@Override public Object parseLiteral(Object input) { if (input instanceof IntValue) { return new DoubleNode(((IntValue) input).getValue().doubleValue()); } if (input instanceof FloatValue) { return new DoubleNode(((FloatValue) input).getValue().doubleValue()); } else { throw new CoercingParseLiteralException(errorMessage(input, IntValue.class, FloatValue.class)); } } });
@Override public BigDecimal parseLiteral(Object input) { if (input instanceof StringValue) { try { return new BigDecimal(((StringValue) input).getValue()); } catch (NumberFormatException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigDecimal' : '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { return new BigDecimal(((IntValue) input).getValue()); } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } });
@Override public BigInteger parseLiteral(Object input) { if (input instanceof StringValue) { try { return new BigDecimal(((StringValue) input).getValue()).toBigIntegerExact(); } catch (NumberFormatException | ArithmeticException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { return ((IntValue) input).getValue(); } else if (input instanceof FloatValue) { try { return ((FloatValue) input).getValue().toBigIntegerExact(); } catch (ArithmeticException e) { throw new CoercingParseLiteralException( "Unable to turn AST input into a 'BigInteger' : '" + String.valueOf(input) + "'" ); } } throw new CoercingParseLiteralException( "Expected AST type 'IntValue', 'StringValue' or 'FloatValue' but was '" + typeName(input) + "'." ); } });
return new JsonPrimitive(((FloatValue) value).getValue());
@Override public Object parseLiteral(Object input) { if (input instanceof IntValue) { return new FloatNode(((IntValue) input).getValue().floatValue()); } if (input instanceof FloatValue) { return new FloatNode(((FloatValue) input).getValue().floatValue()); } else { throw new CoercingParseLiteralException(errorMessage(input, IntValue.class, FloatValue.class)); } } });
return ((FloatValue) value).getValue();
return ((FloatValue) value).getValue();
return ((FloatValue) value).getValue();
return ((BooleanValue) value).isValue(); } else if (value instanceof FloatValue) { return ((FloatValue) value).getValue();
@Override public Object parseLiteral(Object input) { if (input instanceof IntValue) { return JsonNodeFactory.instance.numberNode(((IntValue) input).getValue()); } else if (input instanceof FloatValue) { return JsonNodeFactory.instance.numberNode(((FloatValue) input).getValue()); } else { throw new CoercingParseLiteralException(errorMessage(input, IntValue.class, FloatValue.class)); } } });
private String value(Value value) { String argSep = compactMode ? "," : ", "; if (value instanceof IntValue) { return valueOf(((IntValue) value).getValue()); } else if (value instanceof FloatValue) { return valueOf(((FloatValue) value).getValue()); } else if (value instanceof StringValue) { return wrap("\"", valueOf(((StringValue) value).getValue()), "\""); } else if (value instanceof EnumValue) { return valueOf(((EnumValue) value).getName()); } else if (value instanceof BooleanValue) { return valueOf(((BooleanValue) value).isValue()); } else if (value instanceof NullValue) { return "null"; } else if (value instanceof ArrayValue) { return "[" + join(((ArrayValue) value).getValues(), argSep) + "]"; } else if (value instanceof ObjectValue) { return "{" + join(((ObjectValue) value).getObjectFields(), argSep) + "}"; } else if (value instanceof VariableReference) { return "$" + ((VariableReference) value).getName(); } return ""; }
return JsonNodeFactory.instance.numberNode(((FloatValue) value).getValue());