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.

DoubleValidator.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.data.validator;
  17. /**
  18. * String validator for a double precision floating point number. See
  19. * {@link com.vaadin.data.validator.AbstractStringValidator} for more
  20. * information.
  21. *
  22. * @author Vaadin Ltd.
  23. * @since 5.4
  24. * @deprecated As of 7.0. Use an Double converter on the field instead.
  25. */
  26. @Deprecated
  27. @SuppressWarnings("serial")
  28. public class DoubleValidator extends AbstractStringValidator {
  29. /**
  30. * Creates a validator for checking that a string can be parsed as an
  31. * double.
  32. *
  33. * @param errorMessage
  34. * the message to display in case the value does not validate.
  35. * @deprecated As of 7.0. Use a Double converter on the field instead
  36. * and/or use a {@link DoubleRangeValidator} for validating that
  37. * the value is inside a given range.
  38. */
  39. @Deprecated
  40. public DoubleValidator(String errorMessage) {
  41. super(errorMessage);
  42. }
  43. @Override
  44. protected boolean isValidValue(String value) {
  45. try {
  46. Double.parseDouble(value);
  47. return true;
  48. } catch (Exception e) {
  49. return false;
  50. }
  51. }
  52. @Override
  53. public void validate(Object value) throws InvalidValueException {
  54. if (value != null && value instanceof Double) {
  55. // Allow Doubles to pass through the validator for easier
  56. // migration. Otherwise a TextField connected to an double property
  57. // with a DoubleValidator will fail.
  58. return;
  59. }
  60. super.validate(value);
  61. }
  62. }