case STRING_LITERAL: s = stringLitteral(); left = new ConstantExpression(s); break; case DECIMAL_LITERAL: t = jj_consume_token(DECIMAL_LITERAL); left = ConstantExpression.createFromDecimal(t.image); break; case HEX_LITERAL: t = jj_consume_token(HEX_LITERAL); left = ConstantExpression.createFromHex(t.image); break; case OCTAL_LITERAL: t = jj_consume_token(OCTAL_LITERAL); left = ConstantExpression.createFromOctal(t.image); break; case FLOATING_POINT_LITERAL: t = jj_consume_token(FLOATING_POINT_LITERAL); left = ConstantExpression.createFloat(t.image); break; case TRUE:
@Override public String toString() { return "XQUERY " + ConstantExpression.encodeString(xpath); }
/** * Validates that the expression can be used in {@code ==} or {@code <>} expression. Cannot * not be NULL TRUE or FALSE literals. * * @param expr */ public static void checkEqualOperand(Expression expr) { if (expr instanceof ConstantExpression) { Object value = ((ConstantExpression) expr).getValue(); if (value == null) { throw new RuntimeException("'" + expr + "' cannot be compared."); } } }
public static ConstantExpression createFloat(String text) { Number value = new Double(text); return new ConstantExpression(value); }
public static ConstantExpression createFromOctal(String text) { Number value = Long.valueOf(Long.parseLong(text, 8)); long l = value.longValue(); if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) { value = Integer.valueOf(value.intValue()); } return new ConstantExpression(value); }
case STRING_LITERAL: s = stringLitteral(); left = new ConstantExpression(s); break; case DECIMAL_LITERAL: t = jj_consume_token(DECIMAL_LITERAL); left = ConstantExpression.createFromDecimal(t.image); break; case HEX_LITERAL: t = jj_consume_token(HEX_LITERAL); left = ConstantExpression.createFromHex(t.image); break; case OCTAL_LITERAL: t = jj_consume_token(OCTAL_LITERAL); left = ConstantExpression.createFromOctal(t.image); break; case FLOATING_POINT_LITERAL: t = jj_consume_token(FLOATING_POINT_LITERAL); left = ConstantExpression.createFloat(t.image); break; case TRUE:
public static ConstantExpression createFromHex(String text) { Number value = Long.valueOf(Long.parseLong(text.substring(2), 16)); long l = value.longValue(); if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) { value = Integer.valueOf(value.intValue()); } return new ConstantExpression(value); }
@Override public String toString() { return "XPATH " + ConstantExpression.encodeString(xpath); }
/** * Only Numeric expressions can be used in {@code >}, {@code >=}, {@code <} or {@code <=} expressions. * * @param expr */ public static void checkLessThanOperand(Expression expr) { if (expr instanceof ConstantExpression) { Object value = ((ConstantExpression) expr).getValue(); if (value instanceof Number) { return; } // Else it's boolean or a String.. throw new RuntimeException("Value '" + expr + "' cannot be compared."); } if (expr instanceof BooleanExpression) { throw new RuntimeException("Value '" + expr + "' cannot be compared."); } }
case STRING_LITERAL: s = stringLitteral(); left = new ConstantExpression(s); break; case DECIMAL_LITERAL: t = jj_consume_token(DECIMAL_LITERAL); left = ConstantExpression.createFromDecimal(t.image); break; case HEX_LITERAL: t = jj_consume_token(HEX_LITERAL); left = ConstantExpression.createFromHex(t.image); break; case OCTAL_LITERAL: t = jj_consume_token(OCTAL_LITERAL); left = ConstantExpression.createFromOctal(t.image); break; case FLOATING_POINT_LITERAL: t = jj_consume_token(FLOATING_POINT_LITERAL); left = ConstantExpression.createFloat(t.image); break; case TRUE:
public static ConstantExpression createFromDecimal(String text) { // Strip off the 'l' or 'L' if needed. if (text.endsWith("l") || text.endsWith("L")) { text = text.substring(0, text.length() - 1); } Number value; try { value = new Long(text); } catch (NumberFormatException e) { // The number may be too big to fit in a long. value = new BigDecimal(text); } long l = value.longValue(); if (Integer.MIN_VALUE <= l && l <= Integer.MAX_VALUE) { value = Integer.valueOf(value.intValue()); } return new ConstantExpression(value); }
/** * @see java.lang.Object#toString() */ @Override public String toString() { if (value == null) { return "NULL"; } if (value instanceof Boolean) { return ((Boolean) value).booleanValue() ? "TRUE" : "FALSE"; } if (value instanceof String) { return encodeString((String) value); } return value.toString(); }
/** * Validates that the expression can be used in {@code ==} or {@code <>} expression. Cannot * not be NULL TRUE or FALSE literals. * * @param expr */ public static void checkEqualOperand(Expression expr) { if (expr instanceof ConstantExpression) { Object value = ((ConstantExpression) expr).getValue(); if (value == null) { throw new RuntimeException("'" + expr + "' cannot be compared."); } } }
case STRING_LITERAL: s = stringLitteral(); left = new ConstantExpression(s); break; case DECIMAL_LITERAL: t = jj_consume_token(DECIMAL_LITERAL); left = ConstantExpression.createFromDecimal(t.image); break; case HEX_LITERAL: t = jj_consume_token(HEX_LITERAL); left = ConstantExpression.createFromHex(t.image); break; case OCTAL_LITERAL: t = jj_consume_token(OCTAL_LITERAL); left = ConstantExpression.createFromOctal(t.image); break; case FLOATING_POINT_LITERAL: t = jj_consume_token(FLOATING_POINT_LITERAL); left = ConstantExpression.createFloat(t.image); break; case TRUE:
public static ConstantExpression createFloat(String text) { Number value = new Double(text); return new ConstantExpression(value); }
@Override public String toString() { return "XQUERY " + ConstantExpression.encodeString(xpath); }
/** * Validates that the expression can be used in {@code ==} or {@code <>} expression. Cannot * not be NULL TRUE or FALSE literals. * * @param expr */ public static void checkEqualOperand(Expression expr) { if (expr instanceof ConstantExpression) { Object value = ((ConstantExpression) expr).getValue(); if (value == null) { throw new RuntimeException("'" + expr + "' cannot be compared."); } } }
case STRING_LITERAL: s = stringLitteral(); left = new ConstantExpression(s); break; case DECIMAL_LITERAL: t = jj_consume_token(DECIMAL_LITERAL); left = ConstantExpression.createFromDecimal(t.image); break; case HEX_LITERAL: t = jj_consume_token(HEX_LITERAL); left = ConstantExpression.createFromHex(t.image); break; case OCTAL_LITERAL: t = jj_consume_token(OCTAL_LITERAL); left = ConstantExpression.createFromOctal(t.image); break; case FLOATING_POINT_LITERAL: t = jj_consume_token(FLOATING_POINT_LITERAL); left = ConstantExpression.createFloat(t.image); break; case TRUE:
public static ConstantExpression createFloat(String text) { Number value = new Double(text); return new ConstantExpression(value); }
@Override public String toString() { return "XPATH " + ConstantExpression.encodeString(xpath); }