@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) + "'." ); } } });
@Override public Integer parseLiteral(Object input) { if (!(input instanceof IntValue)) { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' but was '" + typeName(input) + "'." ); } BigInteger value = ((IntValue) input).getValue(); if (value.compareTo(INT_MIN) < 0 || value.compareTo(INT_MAX) > 0) { throw new CoercingParseLiteralException( "Expected value to be in the Integer range but it was '" + value.toString() + "'" ); } return value.intValue(); } });
@Override public String parseLiteral(Object input) { if (input instanceof StringValue) { return ((StringValue) input).getValue(); } if (input instanceof IntValue) { return ((IntValue) input).getValue().toString(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'StringValue' but was '" + typeName(input) + "'." ); } });
private Builder(IntValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.value = existing.getValue(); }
@Override public Short parseLiteral(Object input) { if (!(input instanceof IntValue)) { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' but was '" + typeName(input) + "'." ); } BigInteger value = ((IntValue) input).getValue(); if (value.compareTo(SHORT_MIN) < 0 || value.compareTo(SHORT_MAX) > 0) { throw new CoercingParseLiteralException( "Expected value to be in the Short range but it was '" + value.toString() + "'" ); } return value.shortValue(); } });
@Override public Byte parseLiteral(Object input) { if (!(input instanceof IntValue)) { throw new CoercingParseLiteralException( "Expected AST type 'IntValue' but was '" + typeName(input) + "'." ); } BigInteger value = ((IntValue) input).getValue(); if (value.compareTo(BYTE_MIN) < 0 || value.compareTo(BYTE_MAX) > 0) { throw new CoercingParseLiteralException( "Expected value to be in the Byte range but it was '" + value.toString() + "'" ); } return value.byteValue(); } });
@Override public Long parseLiteral(Object input) { if (input instanceof StringValue) { try { return Long.parseLong(((StringValue) input).getValue()); } catch (NumberFormatException e) { throw new CoercingParseLiteralException( "Expected value to be a Long but it was '" + String.valueOf(input) + "'" ); } } else if (input instanceof IntValue) { BigInteger value = ((IntValue) input).getValue(); if (value.compareTo(LONG_MIN) < 0 || value.compareTo(LONG_MAX) > 0) { throw new CoercingParseLiteralException( "Expected value to be in the Long range but it was '" + value.toString() + "'" ); } return value.longValue(); } throw new CoercingParseLiteralException( "Expected AST type 'IntValue' or 'StringValue' but was '" + typeName(input) + "'." ); } });
@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 String parseLiteral(Object o) { if (o instanceof StringValue) { return ((StringValue) o).getValue(); } else if (o instanceof IntValue) { return ((IntValue) o).getValue().toString(); } // Unexpected object, try to use the toString. log.debug("Found unexpected object type: {}", o.getClass()); return o.toString(); } }
@Override public String parseLiteral(Object o) { if (o instanceof StringValue) { return ((StringValue) o).getValue(); } else if (o instanceof IntValue) { return ((IntValue) o).getValue().toString(); } // Unexpected object, try to use the toString. log.debug("Found unexpected object type: {}", o.getClass()); return o.toString(); } }
@Override public Object parseLiteral(Object input) { if (input instanceof StringValue) { return parseStringToDate(((StringValue) input).getValue()); } else if (input instanceof IntValue) { BigInteger value = ((IntValue) input).getValue(); return new java.sql.Date(value.longValue()); } return null; }
@Override public Object parseLiteral(Object input) { if (input instanceof StringValue) { return parseStringToTimestamp(((StringValue) input).getValue()); } else if (input instanceof IntValue) { BigInteger value = ((IntValue) input).getValue(); return new java.sql.Date(value.longValue()); } return null; }
private Builder(IntValue 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 BigIntegerNode(((IntValue) input).getValue()); } else { throw new CoercingParseLiteralException(errorMessage(input, IntValue.class)); } } });
@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 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)); } } });
@Override public Object parseLiteral(Object input) { if (input instanceof IntValue) { try { return new IntNode(((IntValue) input).getValue().intValueExact()); } catch (ArithmeticException e) { throw new CoercingParseLiteralException(input + " does not fit into an int without a loss of precision"); } } else { throw new CoercingParseLiteralException(errorMessage(input, IntValue.class)); } } });
@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)); } } });