Skip to content

Commit 8453573

Browse files
committed
Tidy whitespace and format stuff
1 parent c271239 commit 8453573

File tree

8 files changed

+23
-54
lines changed

8 files changed

+23
-54
lines changed

validator/src/main/java/io/avaje/validation/core/BasicMessageInterpolator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ final class BasicMessageInterpolator implements MessageInterpolator {
66

77
@Override
88
public String interpolate(String template, Map<String, Object> attributes) {
9-
109
String result = template;
11-
1210
for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
1311
// needs work here to improve functionality, support local specific value formatting eg
1412
// Duration Max

validator/src/main/java/io/avaje/validation/core/CoreAdapterBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ <T> ValidationAdapter<T> build(Type type, Object cacheKey) {
5757
return result;
5858
}
5959
}
60-
throw new IllegalArgumentException(
61-
"No ValidationAdapter for " + type + ". Perhaps needs @ValidPojo or @ValidPojo.Import?");
60+
throw new IllegalArgumentException("No ValidationAdapter for " + type + ". Perhaps needs @ValidPojo or @ValidPojo.Import?");
6261
}
6362

6463
/** Build given type and annotations. */
6564
// TODO understand that lookup chain stuff
6665
@SuppressWarnings("unchecked")
6766
<T> ValidationAdapter<T> buildAnnotation(Class<? extends Annotation> cls, Map<String, Object> attributes) {
68-
6967
// Ask each factory to create the validation adapter.
7068
for (final ValidationContext.AnnotationFactory factory : annotationFactories) {
7169
final var result = (ValidationAdapter<T>) factory.create(cls, context, attributes);

validator/src/main/java/io/avaje/validation/core/DMessage.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ final class DMessage implements ValidationContext.Message {
99
private final String template;
1010
private final Map<String, Object> attributes;
1111

12-
// when true ... template includes ${validatedValue} the actual value, must be rendered at runtime
13-
boolean includesConstraintValue;
1412
DMessage(String template, Map<String, Object> attributes) {
1513
this.template = template;
1614
this.attributes = attributes;

validator/src/main/java/io/avaje/validation/core/DResourceBundleManager.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ final class DResourceBundleManager {
1717
private static final List<ResourceBundle> EMPTY = List.of();
1818
private static final String DEFAULT_BUNDLE = "io.avaje.validation.Messages";
1919

20-
DResourceBundleManager(
21-
List<String> names, List<ResourceBundle> providedBundles, LocaleResolver localeResolver) {
22-
20+
DResourceBundleManager(List<String> names, List<ResourceBundle> providedBundles, LocaleResolver localeResolver) {
2321
for (final var name : names) {
24-
2522
addBundle(name, localeResolver.defaultLocale());
26-
2723
for (final Locale locale : localeResolver.otherLocales()) {
28-
2924
addBundle(name, locale);
3025
}
3126
}
@@ -34,8 +29,9 @@ final class DResourceBundleManager {
3429
map.compute(
3530
bundle.getLocale(),
3631
(local, list) -> {
37-
if (list == null) list = new ArrayList<>();
38-
32+
if (list == null) {
33+
list = new ArrayList<>();
34+
}
3935
list.add(bundle);
4036
return list;
4137
});
@@ -52,17 +48,17 @@ private void addBundle(final String name, final Locale locale) {
5248
map.compute(
5349
locale,
5450
(local, list) -> {
55-
if (list == null) list = new ArrayList<>();
51+
if (list == null) {
52+
list = new ArrayList<>();
53+
}
5654
list.add(getBundle(name, local));
5755
return list;
5856
});
5957
}
6058

6159
@Nullable
6260
public String message(String template, Locale resolvedLocale) {
63-
6461
for (final var bundle : map.getOrDefault(resolvedLocale, EMPTY)) {
65-
6662
if (bundle.containsKey(template)) {
6763
return bundle.getString(template);
6864
}

validator/src/main/java/io/avaje/validation/core/DTemplateLookup.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ String lookup(String template, Locale resolvedLocale) {
1717
return template;
1818
}
1919
final String key = template.substring(1, template.length() - 1);
20-
21-
final String msg =
22-
messageCache.computeIfAbsent(
23-
key + resolvedLocale, k -> bundleManager.message(key, resolvedLocale));
20+
final String msg = messageCache.computeIfAbsent(key + resolvedLocale, k -> bundleManager.message(key, resolvedLocale));
2421
if (msg != null) {
2522
return msg;
2623
}

validator/src/main/java/io/avaje/validation/core/DValidator.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ final class DValidator implements Validator, ValidationContext {
4141
MessageInterpolator interpolator,
4242
LocaleResolver localeResolver) {
4343
this.localeResolver = localeResolver;
44-
45-
final var defaultResourceBundle =
46-
new DResourceBundleManager(bundleNames, bundles, localeResolver);
44+
final var defaultResourceBundle = new DResourceBundleManager(bundleNames, bundles, localeResolver);
4745
this.templateLookup = new DTemplateLookup(defaultResourceBundle);
48-
4946
this.interpolator = interpolator;
5047
this.builder = new CoreAdapterBuilder(this, factories, annotationFactories);
5148
}
@@ -72,23 +69,19 @@ private <T> ValidationType<T> type(Class<T> cls) {
7269

7370
@SuppressWarnings("unchecked")
7471
private <T> ValidationType<T> typeWithCache(Type type) {
75-
return (ValidationType<T>)
76-
typeCache.computeIfAbsent(type, _type -> new DValidationType<>(this, adapter(_type)));
72+
return (ValidationType<T>) typeCache.computeIfAbsent(type, _type -> new DValidationType<>(this, adapter(_type)));
7773
}
7874

7975
@Override
8076
public Message message(Map<String, Object> attributes) {
8177
final String keyOrTemplate = (String) attributes.get("message");
82-
8378
// if configured to support only 1 Locale then we can do the lookup and message translation once
84-
// and early
85-
// otherwise we defer as the final message is locale specific
79+
// and early otherwise we defer as the final message is locale specific
8680
return new DMessage(keyOrTemplate, attributes);
8781
}
8882

8983
@Override
9084
public Message message(String message, Map<String, Object> attributes) {
91-
9285
return new DMessage(message, attributes);
9386
}
9487

@@ -103,8 +96,7 @@ public <T> ValidationAdapter<T> adapter(Class<T> cls) {
10396
}
10497

10598
@Override
106-
public <T> ValidationAdapter<T> adapter(
107-
Class<? extends Annotation> cls, Map<String, Object> attributes) {
99+
public <T> ValidationAdapter<T> adapter(Class<? extends Annotation> cls, Map<String, Object> attributes) {
108100
return builder.annotationAdapter(cls, attributes);
109101
}
110102

@@ -124,12 +116,10 @@ ValidationRequest request(@Nullable Locale locale) {
124116
}
125117

126118
String interpolate(Message msg, Locale requestLocale) {
127-
128119
// resolve the locale to use to produce the message
129120
final Locale locale = localeResolver.resolve(requestLocale);
130121
// lookup in resource bundles using resolved locale and template
131122
final String template = templateLookup.lookup(msg.template(), locale);
132-
133123
return interpolator.interpolate(template, msg.attributes());
134124
}
135125

@@ -189,7 +179,6 @@ public Builder addResourceBundles(String... bundleName) {
189179

190180
@Override
191181
public Builder addResourceBundles(ResourceBundle... bundle) {
192-
193182
Collections.addAll(bundles, bundle);
194183
return this;
195184
}
@@ -202,7 +191,6 @@ public Builder setDefaultLocale(Locale defaultLocal) {
202191

203192
@Override
204193
public Builder addLocales(Locale... locals) {
205-
206194
Collections.addAll(otherLocals, locals);
207195
return this;
208196
}
@@ -226,12 +214,10 @@ public DValidator build() {
226214
ServiceLoader.load(MessageInterpolator.class)
227215
.findFirst()
228216
.orElseGet(BasicMessageInterpolator::new);
229-
return new DValidator(
230-
factories, afactories, bundleNames, bundles, interpolator, localeResolver);
217+
return new DValidator(factories, afactories, bundleNames, bundles, interpolator, localeResolver);
231218
}
232219

233-
private static <T> AnnotationFactory newAnnotationAdapterFactory(
234-
Type type, ValidationAdapter<T> adapter) {
220+
private static <T> AnnotationFactory newAnnotationAdapterFactory(Type type, ValidationAdapter<T> adapter) {
235221
requireNonNull(type);
236222
requireNonNull(adapter);
237223
return (targetType, context, attributes) -> simpleMatch(type, targetType) ? adapter : null;
@@ -249,12 +235,10 @@ private static AdapterFactory newAdapterFactory(Type type, AdapterBuilder builde
249235
return (targetType, ctx) -> simpleMatch(type, targetType) ? builder.build(ctx) : null;
250236
}
251237

252-
private static AnnotationFactory newAdapterFactory(
253-
Class<? extends Annotation> type, AnnotationAdapterBuilder builder) {
238+
private static AnnotationFactory newAdapterFactory(Class<? extends Annotation> type, AnnotationAdapterBuilder builder) {
254239
requireNonNull(type);
255240
requireNonNull(builder);
256-
return (targetType, ctx, attributes) ->
257-
simpleMatch(type, targetType) ? builder.build(ctx, attributes) : null;
241+
return (targetType, ctx, attributes) -> simpleMatch(type, targetType) ? builder.build(ctx, attributes) : null;
258242
}
259243
}
260244

validator/src/main/java/io/avaje/validation/core/Util.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static boolean typesMatch(Type pattern, Type candidate) {
4646
return Util.equals(pattern, candidate);
4747
}
4848

49-
static boolean isAnnotationPresent(
50-
Set<? extends Annotation> annotations, Class<? extends Annotation> annotationClass) {
49+
static boolean isAnnotationPresent(Set<? extends Annotation> annotations, Class<? extends Annotation> annotationClass) {
5150
if (annotations.isEmpty()) return false; // Save an iterator in the common case.
5251
for (final Annotation annotation : annotations) {
5352
if (annotation.annotationType() == annotationClass) return true;
@@ -189,9 +188,10 @@ private static Type resolve(
189188

190189
static Type resolveTypeVariable(Type context, Class<?> contextRawType, TypeVariable<?> unknown) {
191190
final Class<?> declaredByRaw = declaringClassOf(unknown);
192-
193191
// We can't reduce this further.
194-
if (declaredByRaw == null) return unknown;
192+
if (declaredByRaw == null) {
193+
return unknown;
194+
}
195195

196196
final Type declaredBy = genericSupertype(context, contextRawType, declaredByRaw);
197197
if (declaredBy instanceof ParameterizedType) {
@@ -281,10 +281,9 @@ public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments
281281
if (ownerType != null && rawType instanceof Class<?>) {
282282
final Class<?> enclosingClass = ((Class<?>) rawType).getEnclosingClass();
283283
if (enclosingClass == null) {
284-
throw new IllegalArgumentException(
285-
"unexpected owner type for " + rawType + ": " + ownerType);
284+
throw new IllegalArgumentException("unexpected owner type for " + rawType + ": " + ownerType);
286285

287-
} else if (enclosingClass != null) {
286+
} else if (enclosingClass != null) { // FIXME: Huh?
288287
throw new IllegalArgumentException("unexpected owner type for " + rawType + ": null");
289288
}
290289
}

validator/src/main/java/io/avaje/validation/core/adapters/BasicAdapters.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public boolean validate(Object value, ValidationRequest req, String propertyName
9999
return len > 0;
100100
}
101101
} else if (value.getClass().isArray()) {
102-
103102
final var len = Array.getLength(value);
104103
if (len > max || len < min) {
105104
req.addViolation(message, propertyName);

0 commit comments

Comments
 (0)