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.

Value.java 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright (c) 2016 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.expr;
  14. import java.math.BigDecimal;
  15. import java.util.Date;
  16. /**
  17. *
  18. * @author James Ahlborn
  19. */
  20. public interface Value
  21. {
  22. public enum Type
  23. {
  24. NULL, STRING, DATE, TIME, DATE_TIME, LONG, DOUBLE, BIG_DEC;
  25. public boolean isNumeric() {
  26. return inRange(LONG, BIG_DEC);
  27. }
  28. public boolean isIntegral() {
  29. // note when BOOLEAN is converted to number, it is integral
  30. return (this == LONG);
  31. }
  32. public boolean isTemporal() {
  33. return inRange(DATE, DATE_TIME);
  34. }
  35. public Type getPreferredFPType() {
  36. return((ordinal() <= DOUBLE.ordinal()) ? DOUBLE : BIG_DEC);
  37. }
  38. public Type getPreferredNumericType() {
  39. if(isNumeric()) {
  40. return this;
  41. }
  42. if(isTemporal()) {
  43. return ((this == DATE) ? LONG : DOUBLE);
  44. }
  45. return null;
  46. }
  47. private boolean inRange(Type start, Type end) {
  48. return ((start.ordinal() <= ordinal()) && (ordinal() <= end.ordinal()));
  49. }
  50. }
  51. public Type getType();
  52. public Object get();
  53. public boolean isNull();
  54. public boolean getAsBoolean();
  55. public String getAsString();
  56. public Date getAsDateTime(EvalContext ctx);
  57. public Long getAsLong();
  58. public Double getAsDouble();
  59. public BigDecimal getAsBigDecimal();
  60. }