/* * Copyright 2000-2016 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; import java.io.Serializable; import java.util.Objects; import java.util.function.Function; import java.util.function.Predicate; /** * A functional interface for validating user input or other potentially invalid * data. When a validator instance is applied to a value of the corresponding * type, it returns a result signifying that the value either passed or * failed the validation. *
* For instance, the following validator checks if a number is positive: * *
* Validator<Integer> v = num -> { * if (num >= 0) * return Result.ok(num); * else * return Result.error("number must be positive"); * }; ** * @author Vaadin Ltd. * * @param
* For instance, the following chained validator checks if a number is * between 0 and 10, inclusive: * *
* Validator<Integer> v = Validator.from(num -> num >= 0, "number must be >= 0") * .chain(Validator.from(num -> num <= 10, "number must be <= 10")); ** * @param next * the validator to apply next, not null * @return a chained validator * * @see #from(Predicate, String) */ public default Validator
* For instance, the following validator checks if a number is between 0 and * 10, inclusive: * *
* Validator<Integer> v = Validator.from(num -> num >= 0 && num <= 10, * "number must be between 0 and 10"); ** * @param