Fix code review points.
Change-Id: Ia1ef55ff7ef806f9b71cb97f8f09bd4c6ec97a41
--- /dev/null
+/*
+ * 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<BigDecimal> {
+
+ /**
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<BigInteger> {
+
+ /**
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<Byte> {
+
+ /**
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<Float> {
+
+ /**
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<Long> {
+
+ /**
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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<Short> {
+
+ /**
+ * 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);
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.data.validator;
+
+import java.math.BigDecimal;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.BigDecimalRangeValidator;
+
+public class TestBigDecimalRangeValidator extends TestCase {
+
+ private BigDecimalRangeValidator cleanValidator = new BigDecimalRangeValidator(
+ "no values", null, null);
+ private BigDecimalRangeValidator minValidator = new BigDecimalRangeValidator(
+ "no values", new BigDecimal(10.1), null);
+ private BigDecimalRangeValidator maxValidator = new BigDecimalRangeValidator(
+ "no values", null, new BigDecimal(100.1));
+ private BigDecimalRangeValidator minMaxValidator = new BigDecimalRangeValidator(
+ "no values", new BigDecimal(10.5), new BigDecimal(100.5));
+
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(new BigDecimal(-15.0)));
+ assertTrue("Didn't accept valid value",
+ minValidator.isValid(new BigDecimal(10.1)));
+ assertFalse("Accepted too small value",
+ minValidator.isValid(new BigDecimal(10.0)));
+ }
+
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(new BigDecimal(1120.0)));
+ assertTrue("Didn't accept valid value",
+ maxValidator.isValid(new BigDecimal(15.0)));
+ assertFalse("Accepted too large value",
+ maxValidator.isValid(new BigDecimal(100.6)));
+ }
+
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(new BigDecimal(10.5)));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(new BigDecimal(100.5)));
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid(new BigDecimal(10.4)));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid(new BigDecimal(100.6)));
+ }
+}
--- /dev/null
+package com.vaadin.tests.data.validator;
+
+import java.math.BigInteger;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.BigIntegerRangeValidator;
+
+public class TestBigIntegerRangeValidator extends TestCase {
+
+ private BigIntegerRangeValidator cleanValidator = new BigIntegerRangeValidator(
+ "no values", null, null);
+ private BigIntegerRangeValidator minValidator = new BigIntegerRangeValidator(
+ "no values", BigInteger.valueOf(10), null);
+ private BigIntegerRangeValidator maxValidator = new BigIntegerRangeValidator(
+ "no values", null, BigInteger.valueOf(100));
+ private BigIntegerRangeValidator minMaxValidator = new BigIntegerRangeValidator(
+ "no values", BigInteger.valueOf(10), BigInteger.valueOf(100));
+
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(BigInteger.valueOf(-15)));
+ assertTrue("Didn't accept valid value",
+ minValidator.isValid(BigInteger.valueOf(15)));
+ assertFalse("Accepted too small value",
+ minValidator.isValid(BigInteger.valueOf(9)));
+ }
+
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(BigInteger.valueOf(1120)));
+ assertTrue("Didn't accept valid value",
+ maxValidator.isValid(BigInteger.valueOf(15)));
+ assertFalse("Accepted too large value",
+ maxValidator.isValid(BigInteger.valueOf(120)));
+ }
+
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(BigInteger.valueOf(15)));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(BigInteger.valueOf(99)));
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid(BigInteger.valueOf(9)));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid(BigInteger.valueOf(110)));
+ }
+}
--- /dev/null
+package com.vaadin.tests.data.validator;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.ByteRangeValidator;
+
+public class TestByteRangeValidator extends TestCase {
+
+ private ByteRangeValidator cleanValidator = new ByteRangeValidator(
+ "no values", null, null);
+ private ByteRangeValidator minValidator = new ByteRangeValidator(
+ "no values", (byte) 10, null);
+ private ByteRangeValidator maxValidator = new ByteRangeValidator(
+ "no values", null, (byte) 100);
+ private ByteRangeValidator minMaxValidator = new ByteRangeValidator(
+ "no values", (byte) 10, (byte) 100);
+
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((byte) -15));
+ assertTrue("Didn't accept valid value", minValidator.isValid((byte) 15));
+ assertFalse("Accepted too small value", minValidator.isValid((byte) 9));
+ }
+
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((byte) 112));
+ assertTrue("Didn't accept valid value", maxValidator.isValid((byte) 15));
+ assertFalse("Accepted too large value",
+ maxValidator.isValid((byte) 120));
+ }
+
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((byte) 15));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((byte) 99));
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid((byte) 9));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid((byte) 110));
+ }
+}
--- /dev/null
+package com.vaadin.tests.data.validator;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.FloatRangeValidator;
+
+public class TestFloatRangeValidator extends TestCase {
+
+ private FloatRangeValidator cleanValidator = new FloatRangeValidator(
+ "no values", null, null);
+ private FloatRangeValidator minValidator = new FloatRangeValidator(
+ "no values", 10.1f, null);
+ private FloatRangeValidator maxValidator = new FloatRangeValidator(
+ "no values", null, 100.1f);
+ private FloatRangeValidator minMaxValidator = new FloatRangeValidator(
+ "no values", 10.5f, 100.5f);
+
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(-15.0f));
+ assertTrue("Didn't accept valid value", minValidator.isValid(10.1f));
+ assertFalse("Accepted too small value", minValidator.isValid(10.0f));
+ }
+
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(1120.0f));
+ assertTrue("Didn't accept valid value", maxValidator.isValid(15.0f));
+ assertFalse("Accepted too large value", maxValidator.isValid(100.6f));
+ }
+
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(10.5f));
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(100.5f));
+ assertFalse("Accepted too small value", minMaxValidator.isValid(10.4f));
+ assertFalse("Accepted too large value", minMaxValidator.isValid(100.6f));
+ }
+}
--- /dev/null
+package com.vaadin.tests.data.validator;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.LongRangeValidator;
+
+public class TestLongRangeValidator extends TestCase {
+
+ private LongRangeValidator cleanValidator = new LongRangeValidator(
+ "no values", null, null);
+ private LongRangeValidator minValidator = new LongRangeValidator(
+ "no values", 10l, null);
+ private LongRangeValidator maxValidator = new LongRangeValidator(
+ "no values", null, 100l);
+ private LongRangeValidator minMaxValidator = new LongRangeValidator(
+ "no values", 10l, 100l);
+
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(-15l));
+ assertTrue("Didn't accept valid value", minValidator.isValid(15l));
+ assertFalse("Accepted too small value", minValidator.isValid(9l));
+ }
+
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(1120l));
+ assertTrue("Didn't accept valid value", maxValidator.isValid(15l));
+ assertFalse("Accepted too large value", maxValidator.isValid(120l));
+ }
+
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(15l));
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(99l));
+ assertFalse("Accepted too small value", minMaxValidator.isValid(9l));
+ assertFalse("Accepted too large value", minMaxValidator.isValid(110l));
+ }
+}
--- /dev/null
+package com.vaadin.tests.data.validator;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.ShortRangeValidator;
+
+public class TestShortRangeValidator extends TestCase {
+
+ private ShortRangeValidator cleanValidator = new ShortRangeValidator(
+ "no values", null, null);
+ private ShortRangeValidator minValidator = new ShortRangeValidator(
+ "no values", (short) 10, null);
+ private ShortRangeValidator maxValidator = new ShortRangeValidator(
+ "no values", null, (short) 100);
+ private ShortRangeValidator minMaxValidator = new ShortRangeValidator(
+ "no values", (short) 10, (short) 100);
+
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((short) -15));
+ assertTrue("Didn't accept valid value",
+ minValidator.isValid((short) 15));
+ assertFalse("Accepted too small value", minValidator.isValid((short) 9));
+ }
+
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((short) 1120));
+ assertTrue("Didn't accept valid value",
+ maxValidator.isValid((short) 15));
+ assertFalse("Accepted too large value",
+ maxValidator.isValid((short) 120));
+ }
+
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((short) 15));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((short) 99));
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid((short) 9));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid((short) 110));
+ }
+}