Skip to content

Remove unneeded public modifiers, format and tidy #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum RegexFlag {
// JDK flag value
private final int value;

private RegexFlag(int value) {
RegexFlag(int value) {
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ default boolean validate(T value, ValidationRequest req) {
}

default ValidationAdapter<T> list(ValidationContext ctx, Class<?> clazz) {

final var after = ctx.<Object>adapter(clazz);
return (value, req, propertyName) -> {
if (validate(value, req, propertyName)) {
Expand All @@ -25,7 +24,6 @@ default ValidationAdapter<T> list(ValidationContext ctx, Class<?> clazz) {
}

default ValidationAdapter<T> map(ValidationContext ctx, Class<?> clazz) {

final var after = ctx.<Object>adapter(clazz);
return (value, req, propertyName) -> {
if (validate(value, req, propertyName)) {
Expand All @@ -37,7 +35,6 @@ default ValidationAdapter<T> map(ValidationContext ctx, Class<?> clazz) {
}

default ValidationAdapter<T> array(ValidationContext ctx, Class<?> clazz) {

final var after = ctx.<Object>adapter(clazz);
return (value, req, propertyName) -> {
if (validate(value, req, propertyName)) {
Expand All @@ -48,7 +45,6 @@ default ValidationAdapter<T> array(ValidationContext ctx, Class<?> clazz) {
}

private boolean validateAll(Collection<T> value, ValidationRequest req, String propertyName) {

if (value == null) {
return true;
}
Expand All @@ -67,7 +63,6 @@ private boolean validateAll(Collection<T> value, ValidationRequest req, String p
}

private boolean validateArray(T[] value, ValidationRequest req, String propertyName) {

if (value == null) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,57 @@

public interface ValidationContext {

/**
* Return the adapter for the given type.
*/
<T> ValidationAdapter<T> adapter(Class<T> cls);
/**
* Return the adapter for the given type.
*/
<T> ValidationAdapter<T> adapter(Class<T> cls);

/**
* Return the adapter for the given type.
*/
<T> ValidationAdapter<T> adapter(Type type);
/**
* Return the adapter for the given type.
*/
<T> ValidationAdapter<T> adapter(Type type);

/**
* Return the adapter for the given annotation with attributes.
*/
<T> ValidationAdapter<T> adapter(Class<? extends Annotation> cls, Map<String, Object> attributes);
/**
* Return the adapter for the given annotation with attributes.
*/
<T> ValidationAdapter<T> adapter(Class<? extends Annotation> cls, Map<String, Object> attributes);

/**
* Return the message object held by a validation adapter
*/
Message message(Map<String, Object> attributes);
/**
* Return the message object held by a validation adapter
*/
Message message(Map<String, Object> attributes);

interface Message {

interface Message {
String template();

String template();
Map<String, Object> attributes();
}

Map<String, Object> attributes();
}
/**
* Factory for creating a ValidationAdapter for a given type.
*/
interface AdapterFactory {

/**
* Factory for creating a ValidationAdapter for a given type.
* Create and return a ValidationAdapter given the type and annotations or return null.
*
* <p>Returning null means that the adapter could be created by another factory.
*/
interface AdapterFactory {
ValidationAdapter<?> create(Type type, ValidationContext ctx);
}

/**
* Create and return a ValidationAdapter given the type and annotations or return null.
*
* <p>Returning null means that the adapter could be created by another factory.
*/
ValidationAdapter<?> create(Type type, ValidationContext ctx);
}
/**
* Factory for creating a ValidationAdapter for a given annotation.
*/
interface AnnotationFactory {

/**
* Factory for creating a ValidationAdapter for a given annotation.
* Create and return a ValidationAdapter given the type and annotations or return null.
*
* <p>Returning null means that the adapter could be created by another factory.
*/
interface AnnotationFactory {

/**
* Create and return a ValidationAdapter given the type and annotations or return null.
*
* <p>Returning null means that the adapter could be created by another factory.
*/
ValidationAdapter<?> create(
Class<? extends Annotation> annotationType, ValidationContext ctx, Map<String, Object> attributes);
}
ValidationAdapter<?> create(
Class<? extends Annotation> annotationType, ValidationContext ctx, Map<String, Object> attributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

public interface ValidationRequest {

void addViolation(String msg, String propertyName);

void addViolation(ValidationContext.Message msg, String propertyName);

void pushPath(String path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class DLocaleResolver implements LocaleResolver {
private final Locale defaultLocale;
private final Set<Locale> otherLocales = new HashSet<>();

public DLocaleResolver(Locale defaultLocale, Locale... others) {
DLocaleResolver(Locale defaultLocale, Locale... others) {
this.defaultLocale = defaultLocale;
Collections.addAll(otherLocales, others);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ private String currentPath() {
return joiner.toString();
}


@Override
public void addViolation(String msg, String propertyName) {
violations.add(new ConstraintViolation(currentPath(), propertyName, msg));
}

@Override
public void addViolation(ValidationContext.Message msg, String propertyName) {
String message = validator.interpolate(msg, locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

final class DResourceBundleManager {


private final Map<Locale, ResourceBundle> map = new HashMap<>();

DResourceBundleManager(String name, LocaleResolver localeResolver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class DValidator implements Validator, ValidationContext {
this.builder = new CoreAdapterBuilder(this, factories, annotationFactories);
}

public MessageInterpolator interpolator() {
MessageInterpolator interpolator() {
return this.interpolator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static final class PatternAdapter implements ValidationAdapter<CharSeque
private final Predicate<String> pattern;

@SuppressWarnings("unchecked")
public PatternAdapter(ValidationContext.Message message, Map<String, Object> attributes) {
PatternAdapter(ValidationContext.Message message, Map<String, Object> attributes) {
this.message = message;
int flags = 0;

Expand Down Expand Up @@ -68,7 +68,7 @@ private static final class SizeAdapter implements ValidationAdapter<Object> {
private final int min;
private final int max;

public SizeAdapter(ValidationContext.Message message, Map<String, Object> attributes) {
SizeAdapter(ValidationContext.Message message, Map<String, Object> attributes) {
this.message = message;
this.min = (int) attributes.get("min");
this.max = (int) attributes.get("max");
Expand Down Expand Up @@ -121,7 +121,7 @@ private static final class NotBlankAdapter implements ValidationAdapter<CharSequ

private final ValidationContext.Message message;

public NotBlankAdapter(ValidationContext.Message message) {
NotBlankAdapter(ValidationContext.Message message) {
this.message = message;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ private static final class NotEmptyAdapter implements ValidationAdapter<Object>

private final ValidationContext.Message message;

public NotEmptyAdapter(ValidationContext.Message message) {
NotEmptyAdapter(ValidationContext.Message message) {
this.message = message;
}

Expand All @@ -170,7 +170,6 @@ public boolean validate(Object value, ValidationRequest req, String propertyName
return false;
}
} else if (value.getClass().isArray()) {

final var len = Array.getLength(value);
if (len == 0) {
req.addViolation(message, propertyName);
Expand All @@ -182,13 +181,12 @@ public boolean validate(Object value, ValidationRequest req, String propertyName
}
}

// AssertFalse/AssertTrue
private static final class AssertBooleanAdapter implements ValidationAdapter<Boolean> {

private final ValidationContext.Message message;
private final Boolean assertBool;

public AssertBooleanAdapter(ValidationContext.Message message, Boolean assertBool) {
AssertBooleanAdapter(ValidationContext.Message message, Boolean assertBool) {
this.message = message;
this.assertBool = assertBool;
}
Expand All @@ -207,7 +205,7 @@ private static final class NotNullAdapter implements ValidationAdapter<Object> {

private final ValidationContext.Message message;

public NotNullAdapter(ValidationContext.Message message) {
NotNullAdapter(ValidationContext.Message message) {
this.message = message;
}

Expand All @@ -225,7 +223,7 @@ private static final class NullAdapter implements ValidationAdapter<Object> {

private final ValidationContext.Message message;

public NullAdapter(ValidationContext.Message message) {
NullAdapter(ValidationContext.Message message) {
this.message = message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Marko Bekhta
* @author Guillaume Smet
*/
public final class DomainNameUtil {
final class DomainNameUtil {

/**
* This is the maximum length of a domain name. But be aware that each label (parts separated by a
Expand Down Expand Up @@ -54,7 +54,7 @@ private DomainNameUtil() {}
* @param domain domain to check for validity
* @return {@code true} if the provided string is a valid domain, {@code false} otherwise
*/
public static boolean isValidEmailDomainAddress(String domain) {
static boolean isValidEmailDomainAddress(String domain) {
return isValidDomainAddress(domain, EMAIL_DOMAIN_PATTERN);
}

Expand All @@ -64,7 +64,7 @@ public static boolean isValidEmailDomainAddress(String domain) {
* @param domain the domain to check for validity
* @return {@code true} if the provided string is a valid domain, {@code false} otherwise
*/
public static boolean isValidDomainAddress(String domain) {
static boolean isValidDomainAddress(String domain) {
return isValidDomainAddress(domain, DOMAIN_PATTERN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ final class EmailAdapter implements ValidationAdapter<CharSequence> {
"(?:[a-z0-9!#$%&'*.(),<>\\[\\]:; @+/=?^_`{|}~\u0080-\uFFFF-]|\\\\\\\\|\\\\\\\")";
/** Regular expression for the local part of an email address (everything before '@') */
private static final Pattern LOCAL_PART_PATTERN =
Pattern.compile(
"(?:"
+ LOCAL_PART_ATOM
+ "+|\""
+ LOCAL_PART_INSIDE_QUOTES_ATOM
+ "+\")"
+ "(?:\\."
+ "(?:"
+ LOCAL_PART_ATOM
+ "+|\""
+ LOCAL_PART_INSIDE_QUOTES_ATOM
+ "+\")"
+ ")*",
CASE_INSENSITIVE);
Pattern.compile(
"(?:"
+ LOCAL_PART_ATOM
+ "+|\""
+ LOCAL_PART_INSIDE_QUOTES_ATOM
+ "+\")"
+ "(?:\\."
+ "(?:"
+ LOCAL_PART_ATOM
+ "+|\""
+ LOCAL_PART_INSIDE_QUOTES_ATOM
+ "+\")"
+ ")*",
CASE_INSENSITIVE);

private final ValidationContext.Message message;
private final Predicate<String> pattern;

@SuppressWarnings("unchecked")
public EmailAdapter(ValidationContext.Message message, Map<String, Object> attributes) {
EmailAdapter(ValidationContext.Message message, Map<String, Object> attributes) {
this.message = message;
int flags = 0;
var regex = (String) attributes.get("regexp");
Expand Down
Loading