From ca7dfd60d66bfdf32a15eccd6c7b5ae62baba39c Mon Sep 17 00:00:00 2001 From: "denis.magdenkov" Date: Sat, 6 Sep 2014 15:58:25 +0400 Subject: Add Range Validators (#14584) Fix code review points. Change-Id: Ia1ef55ff7ef806f9b71cb97f8f09bd4c6ec97a41 --- .../data/validator/BigDecimalRangeValidator.java | 50 ++++++++++++++++++++++ .../data/validator/BigIntegerRangeValidator.java | 50 ++++++++++++++++++++++ .../vaadin/data/validator/ByteRangeValidator.java | 46 ++++++++++++++++++++ .../vaadin/data/validator/FloatRangeValidator.java | 47 ++++++++++++++++++++ .../vaadin/data/validator/LongRangeValidator.java | 46 ++++++++++++++++++++ .../vaadin/data/validator/ShortRangeValidator.java | 47 ++++++++++++++++++++ 6 files changed, 286 insertions(+) create mode 100644 server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java create mode 100644 server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java create mode 100644 server/src/com/vaadin/data/validator/ByteRangeValidator.java create mode 100644 server/src/com/vaadin/data/validator/FloatRangeValidator.java create mode 100644 server/src/com/vaadin/data/validator/LongRangeValidator.java create mode 100644 server/src/com/vaadin/data/validator/ShortRangeValidator.java (limited to 'server/src/com/vaadin/data') diff --git a/server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java b/server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java new file mode 100644 index 0000000000..9b1d2bb565 --- /dev/null +++ b/server/src/com/vaadin/data/validator/BigDecimalRangeValidator.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.validator; + +import java.math.BigDecimal; + +/** + * Validator for validating that an {@link BigDecimal} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class BigDecimalRangeValidator extends RangeValidator { + + /** + * Creates a validator for checking that an BigDecimal is within a given + * range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public BigDecimalRangeValidator(String errorMessage, BigDecimal minValue, + BigDecimal maxValue) { + super(errorMessage, BigDecimal.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java b/server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java new file mode 100644 index 0000000000..bfe9dadc3f --- /dev/null +++ b/server/src/com/vaadin/data/validator/BigIntegerRangeValidator.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.validator; + +import java.math.BigInteger; + +/** + * Validator for validating that an {@link BigInteger} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class BigIntegerRangeValidator extends RangeValidator { + + /** + * Creates a validator for checking that an BigInteger is within a given + * range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public BigIntegerRangeValidator(String errorMessage, BigInteger minValue, + BigInteger maxValue) { + super(errorMessage, BigInteger.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/ByteRangeValidator.java b/server/src/com/vaadin/data/validator/ByteRangeValidator.java new file mode 100644 index 0000000000..c09a290d8a --- /dev/null +++ b/server/src/com/vaadin/data/validator/ByteRangeValidator.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.validator; + +/** + * Validator for validating that an {@link Byte} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class ByteRangeValidator extends RangeValidator { + + /** + * Creates a validator for checking that an Byte is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public ByteRangeValidator(String errorMessage, Byte minValue, Byte maxValue) { + super(errorMessage, Byte.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/FloatRangeValidator.java b/server/src/com/vaadin/data/validator/FloatRangeValidator.java new file mode 100644 index 0000000000..903c8c475f --- /dev/null +++ b/server/src/com/vaadin/data/validator/FloatRangeValidator.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.validator; + +/** + * Validator for validating that a {@link Float} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class FloatRangeValidator extends RangeValidator { + + /** + * Creates a validator for checking that an Float is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public FloatRangeValidator(String errorMessage, Float minValue, + Float maxValue) { + super(errorMessage, Float.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/LongRangeValidator.java b/server/src/com/vaadin/data/validator/LongRangeValidator.java new file mode 100644 index 0000000000..829b37e37b --- /dev/null +++ b/server/src/com/vaadin/data/validator/LongRangeValidator.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.validator; + +/** + * Validator for validating that an {@link Long} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class LongRangeValidator extends RangeValidator { + + /** + * Creates a validator for checking that an Long is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public LongRangeValidator(String errorMessage, Long minValue, Long maxValue) { + super(errorMessage, Long.class, minValue, maxValue); + } + +} diff --git a/server/src/com/vaadin/data/validator/ShortRangeValidator.java b/server/src/com/vaadin/data/validator/ShortRangeValidator.java new file mode 100644 index 0000000000..70e0b7c1e8 --- /dev/null +++ b/server/src/com/vaadin/data/validator/ShortRangeValidator.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.data.validator; + +/** + * Validator for validating that an {@link Short} is inside a given range. + * + * @author Vaadin Ltd. + * @since + */ +@SuppressWarnings("serial") +public class ShortRangeValidator extends RangeValidator { + + /** + * Creates a validator for checking that an Short is within a given range. + * + * By default the range is inclusive i.e. both minValue and maxValue are + * valid values. Use {@link #setMinValueIncluded(boolean)} or + * {@link #setMaxValueIncluded(boolean)} to change it. + * + * + * @param errorMessage + * the message to display in case the value does not validate. + * @param minValue + * The minimum value to accept or null for no limit + * @param maxValue + * The maximum value to accept or null for no limit + */ + public ShortRangeValidator(String errorMessage, Short minValue, + Short maxValue) { + super(errorMessage, Short.class, minValue, maxValue); + } + +} -- cgit v1.2.3