You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConstantNumber.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2004-2011 H2 Group.
  3. * Copyright 2011 James Moger.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.iciql.bytecode;
  18. import com.iciql.Query;
  19. import com.iciql.SQLStatement;
  20. /**
  21. * A literal number.
  22. */
  23. public class ConstantNumber implements Constant {
  24. private final String value;
  25. private final Type type;
  26. private final long longValue;
  27. private ConstantNumber(String value, long longValue, Type type) {
  28. this.value = value;
  29. this.longValue = longValue;
  30. this.type = type;
  31. }
  32. static ConstantNumber get(String v) {
  33. return new ConstantNumber(v, 0, Type.STRING);
  34. }
  35. static ConstantNumber get(int v) {
  36. return new ConstantNumber("" + v, v, Type.INT);
  37. }
  38. static ConstantNumber get(long v) {
  39. return new ConstantNumber("" + v, v, Type.LONG);
  40. }
  41. static ConstantNumber get(String s, long x, Type type) {
  42. return new ConstantNumber(s, x, type);
  43. }
  44. public int intValue() {
  45. return (int) longValue;
  46. }
  47. public String toString() {
  48. return value;
  49. }
  50. public <T> void appendSQL(SQLStatement stat, Query<T> query) {
  51. stat.appendSQL(toString());
  52. }
  53. public Constant.Type getType() {
  54. return type;
  55. }
  56. }