Skip to content

Remove the unused context message() methods #43

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 2 commits 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 @@ -21,22 +21,10 @@ public interface ValidationContext {
*/
<T> ValidationAdapter<T> adapter(Class<? extends Annotation> cls, Map<String, Object> attributes);

/**
* Return the message to use given the global key and attributes.
* @param key Used to lookup the fallback default message format to use
* @param attributes Attributes that could contain user defined message to use
*/
String message(String key, Map<String, Object> attributes);

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

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

interface Message {

Expand Down
24 changes: 1 addition & 23 deletions validator/src/main/java/io/avaje/validation/core/DValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,14 @@ private <T> ValidationType<T> typeWithCache(Type type) {
}

@Override
public String message(String key, Map<String, Object> attributes) {
String msg = (String)attributes.get("message");
if (msg == null) {
// lookup default message for the given key
msg = key+"-todo-lookupDefaultMessage";
}
return msg;
}

@Override
public Message message2(Map<String, Object> attributes) {
public Message message(Map<String, Object> attributes) {
final String keyOrTemplate = (String)attributes.get("message");

// if configured to support only 1 Locale then we can do the lookup and message translation once and early
// otherwise we defer as the final message is locale specific
return new DMessage(keyOrTemplate, attributes);
}

@Override
public Message message2(String defaultKey, Map<String, Object> attributes) {
String keyOrTemplate = (String)attributes.get("message");
if (keyOrTemplate == null) {
// lookup default message for the given key
keyOrTemplate = defaultKey;
}
// if configured to support only 1 Locale then we can do the lookup and message translation once and early
// otherwise we defer as the final message is locale specific
return new DMessage(keyOrTemplate, attributes);
}

@Override
public <T> ValidationAdapter<T> adapter(Class<T> cls) {
final Type cacheKey = canonicalizeClass(requireNonNull(cls));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;

Expand All @@ -18,19 +17,19 @@ private BasicAdapters() {}

public static final ValidationContext.AnnotationFactory FACTORY = (annotationType, context, attributes) ->
switch (annotationType.getSimpleName()) {
case "Email" -> new EmailAdapter(context.message2(attributes), attributes);
case "Null" -> new NullAdapter(context.message2(attributes));
case "NotNull", "NonNull" -> new NotNullAdapter(context.message2(attributes));
case "AssertTrue" -> new AssertBooleanAdapter(context.message2(attributes), false);
case "AssertFalse" -> new AssertBooleanAdapter(context.message2(attributes), true);
case "NotBlank" -> new NotBlankAdapter(context.message2(attributes));
case "NotEmpty" -> new NotEmptyAdapter(context.message2(attributes));
case "Past" -> new FuturePastAdapter(context.message2(attributes), true, false);
case "PastOrPresent" -> new FuturePastAdapter(context.message2(attributes), true, true);
case "Future" -> new FuturePastAdapter(context.message2(attributes), false, false);
case "FutureOrPresent" -> new FuturePastAdapter(context.message2(attributes), false, true);
case "Pattern" -> new PatternAdapter(context.message2(attributes), attributes);
case "Size" -> new SizeAdapter(context.message2(attributes), attributes);
case "Email" -> new EmailAdapter(context.message(attributes), attributes);
case "Null" -> new NullAdapter(context.message(attributes));
case "NotNull", "NonNull" -> new NotNullAdapter(context.message(attributes));
case "AssertTrue" -> new AssertBooleanAdapter(context.message(attributes), false);
case "AssertFalse" -> new AssertBooleanAdapter(context.message(attributes), true);
case "NotBlank" -> new NotBlankAdapter(context.message(attributes));
case "NotEmpty" -> new NotEmptyAdapter(context.message(attributes));
case "Past" -> new FuturePastAdapter(context.message(attributes), true, false);
case "PastOrPresent" -> new FuturePastAdapter(context.message(attributes), true, true);
case "Future" -> new FuturePastAdapter(context.message(attributes), false, false);
case "FutureOrPresent" -> new FuturePastAdapter(context.message(attributes), false, true);
case "Pattern" -> new PatternAdapter(context.message(attributes), attributes);
case "Size" -> new SizeAdapter(context.message(attributes), attributes);
default -> null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ private NumberAdapters() {}
public static final ValidationContext.AnnotationFactory FACTORY =
(annotationType, context, attributes) ->
switch (annotationType.getSimpleName()) {
case "Digits" -> new DigitsAdapter(context.message2(attributes), attributes);
case "Positive" -> new PositiveAdapter(context.message2(attributes));
case "Digits" -> new DigitsAdapter(context.message(attributes), attributes);
case "Positive" -> new PositiveAdapter(context.message(attributes));
case "PositiveOrZero" -> new PositiveAdapter(
context.message2(attributes), true);
case "Negative" -> new NegativeAdapter(context.message2(attributes));
context.message(attributes), true);
case "Negative" -> new NegativeAdapter(context.message(attributes));
case "NegativeOrZero" -> new NegativeAdapter(
context.message2(attributes), true);
case "Max" -> new MaxAdapter(context.message2(attributes), attributes);
case "Min" -> new MinAdapter(context.message2(attributes), attributes);
context.message(attributes), true);
case "Max" -> new MaxAdapter(context.message(attributes), attributes);
case "Min" -> new MinAdapter(context.message(attributes), attributes);
case "DecimalMax" -> new DecimalMaxAdapter(
context.message2(attributes), attributes);
context.message(attributes), attributes);
case "DecimalMin" -> new DecimalMinAdapter(
context.message2(attributes), attributes);
context.message(attributes), attributes);

default -> null;
};
Expand Down