Compare commits
7 Commits
5bd19b924a
...
a9df6f8c0e
Author | SHA1 | Date | |
---|---|---|---|
a9df6f8c0e | |||
6585750e65 | |||
1b8a5634b3 | |||
ecdd0a616a | |||
dc28befe88 | |||
73b7827e5f | |||
6868a81c59 |
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
public abstract
|
||||
class BaseComparablePropertyValidator<TObj,
|
||||
TProperty extends Comparable<TProperty>,
|
||||
TPropertyValidator extends BaseComparablePropertyValidator<TObj, TProperty, TPropertyValidator>>
|
||||
extends BasePropertyValidator<TObj, TProperty, TPropertyValidator> {
|
||||
|
||||
BaseComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
public TPropertyValidator inRange(Range<TProperty> range) {
|
||||
withRule(value -> value != null && range.contains(value),
|
||||
convertExceptionCreator("The value is not in " + range.toString()));
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
public TPropertyValidator inRange(Range<TProperty> range, String errMsg) {
|
||||
withRule(value -> value != null && range.contains(value), convertExceptionCreator(errMsg));
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator inRange(
|
||||
Range<TProperty> range,
|
||||
Supplier<E> exceptionCreator) {
|
||||
withRule(value -> value != null && range.contains(value), exceptionCreator);
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator inRange(
|
||||
Range<TProperty> range,
|
||||
Function<TProperty, E> exceptionCreator) {
|
||||
withRule(value -> value != null && range.contains(value), exceptionCreator);
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
static <V> Function<V, IllegalArgumentException> convertExceptionCreator(String errMsg) {
|
||||
return value -> new IllegalArgumentException(errMsg);
|
||||
}
|
||||
|
||||
static <V, E extends RuntimeException> Function<V, E> convertExceptionCreator(Supplier<E> exceptionSupplier) {
|
||||
return value -> exceptionSupplier.get();
|
||||
}
|
||||
}
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2024-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -113,46 +129,46 @@ public abstract class BasePropertyValidator< //
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
// ===== isTrue =====
|
||||
// ===== must =====
|
||||
|
||||
public TPropertyValidator isTrue(Predicate<? super TProperty> condition) {
|
||||
return isTrue(condition, "无效的用户输入");
|
||||
public TPropertyValidator must(Predicate<? super TProperty> condition) {
|
||||
return must(condition, "无效的用户输入");
|
||||
}
|
||||
|
||||
public TPropertyValidator isTrue(Predicate<? super TProperty> condition, String errMsg) {
|
||||
return isTrue(condition, convertExceptionCreator(errMsg));
|
||||
public TPropertyValidator must(Predicate<? super TProperty> condition, String errMsg) {
|
||||
return must(condition, convertExceptionCreator(errMsg));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator isTrue(
|
||||
public <E extends RuntimeException> TPropertyValidator must(
|
||||
Predicate<? super TProperty> condition,
|
||||
Supplier<E> exceptionCreator) {
|
||||
return isTrue(condition, convertExceptionCreator(exceptionCreator));
|
||||
return must(condition, convertExceptionCreator(exceptionCreator));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator isTrue(
|
||||
public <E extends RuntimeException> TPropertyValidator must(
|
||||
Predicate<? super TProperty> condition,
|
||||
Function<TProperty, E> exceptionCreator) {
|
||||
withRule(condition, exceptionCreator);
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
// ===== isTrue =====
|
||||
// ===== must =====
|
||||
|
||||
public TPropertyValidator isTrue(Collection<Predicate<? super TProperty>> conditions) {
|
||||
return isTrue(conditions, "无效的用户输入");
|
||||
public TPropertyValidator must(Collection<Predicate<? super TProperty>> conditions) {
|
||||
return must(conditions, "无效的用户输入");
|
||||
}
|
||||
|
||||
public TPropertyValidator isTrue(Collection<Predicate<? super TProperty>> conditions, String errMsg) {
|
||||
return isTrue(conditions, convertExceptionCreator(errMsg));
|
||||
public TPropertyValidator must(Collection<Predicate<? super TProperty>> conditions, String errMsg) {
|
||||
return must(conditions, convertExceptionCreator(errMsg));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator isTrue(
|
||||
public <E extends RuntimeException> TPropertyValidator must(
|
||||
Collection<Predicate<? super TProperty>> conditions,
|
||||
Supplier<E> exceptionCreator) {
|
||||
return isTrue(conditions, convertExceptionCreator(exceptionCreator));
|
||||
return must(conditions, convertExceptionCreator(exceptionCreator));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator isTrue(
|
||||
public <E extends RuntimeException> TPropertyValidator must(
|
||||
Collection<Predicate<? super TProperty>> conditions,
|
||||
Function<TProperty, E> exceptionCreator) {
|
||||
for (Predicate<? super TProperty> condition : conditions) {
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2022-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -51,8 +67,8 @@ public abstract class BaseValidator<T> {
|
||||
return validator;
|
||||
}
|
||||
|
||||
protected final <R extends Comparable<R>> DefaultComparablePropertyValidator<T, R> ruleForComparable(Function<T, R> getter) {
|
||||
DefaultComparablePropertyValidator<T, R> validator = new DefaultComparablePropertyValidator<>(getter);
|
||||
protected final <R extends Comparable<R>> ComparablePropertyValidator<T, R> ruleForComparable(Function<T, R> getter) {
|
||||
ComparablePropertyValidator<T, R> validator = new ComparablePropertyValidator<>(getter);
|
||||
this.rules.add(validator::validate);
|
||||
return validator;
|
||||
}
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -1,49 +1,32 @@
|
||||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
|
||||
public abstract
|
||||
class ComparablePropertyValidator<TObj,
|
||||
TProperty extends Comparable<TProperty>,
|
||||
TPropertyValidator extends ComparablePropertyValidator<TObj, TProperty, TPropertyValidator>>
|
||||
extends BasePropertyValidator<TObj, TProperty, TPropertyValidator> {
|
||||
public class ComparablePropertyValidator<TObj, TProperty extends Comparable<TProperty>>
|
||||
extends BaseComparablePropertyValidator<TObj, TProperty, ComparablePropertyValidator<TObj, TProperty>> {
|
||||
|
||||
ComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
public TPropertyValidator between(Range<TProperty> range) {
|
||||
withRule(range::contains, convertExceptionCreator("The value is not in " + range.toString()));
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
public TPropertyValidator between(Range<TProperty> range, String errMsg) {
|
||||
withRule(range::contains, convertExceptionCreator(errMsg));
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator between(
|
||||
Range<TProperty> range,
|
||||
Supplier<E> exceptionCreator) {
|
||||
withRule(range::contains, exceptionCreator);
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> TPropertyValidator between(
|
||||
Range<TProperty> range,
|
||||
Function<TProperty, E> exceptionCreator) {
|
||||
withRule(range::contains, exceptionCreator);
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
static <V> Function<V, IllegalArgumentException> convertExceptionCreator(String errMsg) {
|
||||
return value -> new IllegalArgumentException(errMsg);
|
||||
}
|
||||
|
||||
static <V, E extends RuntimeException> Function<V, E> convertExceptionCreator(Supplier<E> exceptionSupplier) {
|
||||
return value -> exceptionSupplier.get();
|
||||
@Override
|
||||
protected ComparablePropertyValidator<TObj, TProperty> thisObject() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class DefaultComparablePropertyValidator<TObj, TProperty extends Comparable<TProperty>>
|
||||
extends ComparablePropertyValidator<TObj, TProperty, DefaultComparablePropertyValidator<TObj, TProperty>> {
|
||||
|
||||
DefaultComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultComparablePropertyValidator<TObj, TProperty> thisObject() {
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,9 +1,25 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DoublePropertyValidator<DTO> extends ComparablePropertyValidator<DTO, Double, DoublePropertyValidator<DTO>> {
|
||||
public class DoublePropertyValidator<DTO> extends BaseComparablePropertyValidator<DTO, Double, DoublePropertyValidator<DTO>> {
|
||||
|
||||
DoublePropertyValidator(Function<DTO, Double> getter) {
|
||||
super(getter);
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,25 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class IntPropertyValidator<DTO> extends ComparablePropertyValidator<DTO, Integer, IntPropertyValidator<DTO>> {
|
||||
public class IntPropertyValidator<DTO> extends BaseComparablePropertyValidator<DTO, Integer, IntPropertyValidator<DTO>> {
|
||||
|
||||
IntPropertyValidator(Function<DTO, Integer> getter) {
|
||||
super(getter);
|
||||
|
@ -1,9 +1,25 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class LongPropertyValidator<DTO> extends ComparablePropertyValidator<DTO, Long, LongPropertyValidator<DTO>> {
|
||||
public class LongPropertyValidator<DTO> extends BaseComparablePropertyValidator<DTO, Long, LongPropertyValidator<DTO>> {
|
||||
|
||||
LongPropertyValidator(Function<DTO, Long> getter) {
|
||||
super(getter);
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2024-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -20,7 +36,7 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
|
||||
*
|
||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
||||
*/
|
||||
public class StringPropertyValidator<DTO> extends ComparablePropertyValidator<DTO, String, StringPropertyValidator<DTO>> {
|
||||
public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidator<DTO, String, StringPropertyValidator<DTO>> {
|
||||
|
||||
StringPropertyValidator(Function<DTO, String> getter) {
|
||||
super(getter);
|
||||
@ -162,28 +178,29 @@ public class StringPropertyValidator<DTO> extends ComparablePropertyValidator<DT
|
||||
// ================================
|
||||
|
||||
// ================================
|
||||
// #region - email
|
||||
// #region - emailAddress
|
||||
// ================================
|
||||
|
||||
public StringPropertyValidator<DTO> email() {
|
||||
return email("The value is not an email address.");
|
||||
public StringPropertyValidator<DTO> emailAddress() {
|
||||
return emailAddress("The value is not an email address.");
|
||||
}
|
||||
|
||||
public StringPropertyValidator<DTO> email(String errMsg) {
|
||||
return email(convertExceptionCreator(errMsg));
|
||||
public StringPropertyValidator<DTO> emailAddress(String errMsg) {
|
||||
return emailAddress(convertExceptionCreator(errMsg));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> StringPropertyValidator<DTO> email(Supplier<E> exceptionCreator) {
|
||||
return email(convertExceptionCreator(exceptionCreator));
|
||||
public <E extends RuntimeException> StringPropertyValidator<DTO> emailAddress(
|
||||
Supplier<E> exceptionCreator) {
|
||||
return emailAddress(convertExceptionCreator(exceptionCreator));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> StringPropertyValidator<DTO> email(Function<String, E> exceptionCreator) {
|
||||
// TODO [优化] 优化 email 校验
|
||||
public <E extends RuntimeException> StringPropertyValidator<DTO> emailAddress(
|
||||
Function<String, E> exceptionCreator) {
|
||||
return matches(PatternConsts.EMAIL, exceptionCreator);
|
||||
}
|
||||
|
||||
// ================================
|
||||
// #endregion - email
|
||||
// #endregion - emailAddress
|
||||
// ================================
|
||||
|
||||
// ================================
|
||||
@ -245,7 +262,8 @@ public class StringPropertyValidator<DTO> extends ComparablePropertyValidator<DT
|
||||
|
||||
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int length,
|
||||
Function<String, E> exceptionCreator) {
|
||||
AssertTools.checkArgument(length >= 0, "The minimum value must be less than the maximum value.");
|
||||
AssertTools.checkArgument(length >= 0,
|
||||
"The required length must be greater than or equal to 0.");
|
||||
withRule(s -> s != null && s.length() == length, exceptionCreator);
|
||||
return this;
|
||||
}
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2022-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2022-2025 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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 xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
@ -37,7 +37,7 @@ class BaseValidatorTest {
|
||||
int thisYear = Year.now().getValue();
|
||||
|
||||
ruleForString(RegisterCommand::getUsername)
|
||||
.isTrue(PredicateTools.<String>from(Objects::nonNull)
|
||||
.must(PredicateTools.<String>from(Objects::nonNull)
|
||||
.and(StringTools::isNotEmpty)
|
||||
.and(StringTools::isNotBlank)
|
||||
.and(username -> RegexTools.matches(username, PatternConsts.USERNAME)),
|
||||
@ -56,11 +56,11 @@ class BaseValidatorTest {
|
||||
|
||||
ruleForComparable(RegisterCommand::getYearOfBirth)
|
||||
.notNull()
|
||||
.between(Range.closed(thisYear - 60, thisYear - 18));
|
||||
.inRange(Range.closed(thisYear - 60, thisYear - 18));
|
||||
|
||||
ruleForInt(RegisterCommand::getYearOfBirth)
|
||||
.notNull()
|
||||
.between(Range.closed(thisYear - 60, thisYear - 18));
|
||||
.inRange(Range.closed(thisYear - 60, thisYear - 18));
|
||||
|
||||
withRule(registerCommand -> Objects.equals(registerCommand.getPassword(), registerCommand.getPassword2()),
|
||||
"两次输入的密码不一致");
|
||||
|
Loading…
x
Reference in New Issue
Block a user