Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

BaseValue.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.impl.expr;
  14. import java.math.BigDecimal;
  15. import java.util.Date;
  16. import com.healthmarketscience.jackcess.expr.Value;
  17. import com.healthmarketscience.jackcess.expr.EvalContext;
  18. import com.healthmarketscience.jackcess.expr.EvalException;
  19. /**
  20. *
  21. * @author James Ahlborn
  22. */
  23. public abstract class BaseValue implements Value
  24. {
  25. public boolean isNull() {
  26. return(getType() == Type.NULL);
  27. }
  28. public boolean getAsBoolean() {
  29. throw invalidConversion(Value.Type.LONG);
  30. }
  31. public String getAsString() {
  32. throw invalidConversion(Value.Type.STRING);
  33. }
  34. public Date getAsDateTime(EvalContext ctx) {
  35. throw invalidConversion(Value.Type.DATE_TIME);
  36. }
  37. public Integer getAsLongInt() {
  38. throw invalidConversion(Value.Type.LONG);
  39. }
  40. public Double getAsDouble() {
  41. throw invalidConversion(Value.Type.DOUBLE);
  42. }
  43. public BigDecimal getAsBigDecimal() {
  44. throw invalidConversion(Value.Type.BIG_DEC);
  45. }
  46. private EvalException invalidConversion(Value.Type newType) {
  47. return new EvalException(
  48. getType() + " value cannot be converted to " + newType);
  49. }
  50. protected Integer roundToLongInt() {
  51. return getAsBigDecimal().setScale(0, BuiltinOperators.ROUND_MODE)
  52. .intValueExact();
  53. }
  54. @Override
  55. public String toString() {
  56. return "Value[" + getType() + "] '" + get() + "'";
  57. }
  58. }