Skip to content

Commit c3cee1b

Browse files
thcedclaude
andcommitted
style: Add curly braces to brace-less control-flow one-liners
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 926c1a5 commit c3cee1b

5 files changed

Lines changed: 93 additions & 39 deletions

File tree

src/main/java/com/retailsvc/http/internal/Router.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ public Router(List<Operation> operations) {
3434

3535
public Optional<Match> match(HttpMethod method, String path) {
3636
Operation hit = exact.get(method).get(path);
37-
if (hit != null) return Optional.of(new Match(hit, Map.of()));
37+
if (hit != null) {
38+
return Optional.of(new Match(hit, Map.of()));
39+
}
3840
for (Operation op : templated.get(method)) {
3941
Optional<Map<String, String>> params = op.path().match(path);
40-
if (params.isPresent()) return Optional.of(new Match(op, params.get()));
42+
if (params.isPresent()) {
43+
return Optional.of(new Match(op, params.get()));
44+
}
4145
}
4246
return Optional.empty();
4347
}

src/main/java/com/retailsvc/http/spec/PathTemplate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public static PathTemplate compile(String template) {
3030

3131
public Optional<Map<String, String>> match(String path) {
3232
Matcher m = compiled.matcher(path);
33-
if (!m.matches()) return Optional.empty();
33+
if (!m.matches()) {
34+
return Optional.empty();
35+
}
3436
Map<String, String> out = new LinkedHashMap<>();
3537
for (int i = 0; i < parameterNames.size(); i++) {
3638
out.put(parameterNames.get(i), m.group(i + 1));

src/main/java/com/retailsvc/http/spec/Spec.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ public String basePath() {
4343
public Schema resolveSchema(String ref) {
4444
String name = stripPrefix(ref, "#/components/schemas/");
4545
Schema s = componentSchemas.get(name);
46-
if (s == null) throw new IllegalArgumentException("unknown schema ref: " + ref);
46+
if (s == null) {
47+
throw new IllegalArgumentException("unknown schema ref: " + ref);
48+
}
4749
return s;
4850
}
4951

5052
public Parameter resolveParameter(String ref) {
5153
String name = stripPrefix(ref, "#/components/parameters/");
5254
Parameter p = componentParameters.get(name);
53-
if (p == null) throw new IllegalArgumentException("unknown parameter ref: " + ref);
55+
if (p == null) {
56+
throw new IllegalArgumentException("unknown parameter ref: " + ref);
57+
}
5458
return p;
5559
}
5660

@@ -66,7 +70,9 @@ private static Info parseInfo(Map<String, Object> raw) {
6670
}
6771

6872
private static List<Server> parseServers(List<Map<String, Object>> raw) {
69-
if (raw == null || raw.isEmpty()) return List.of();
73+
if (raw == null || raw.isEmpty()) {
74+
return List.of();
75+
}
7076
return raw.stream().map(m -> new Server((String) m.get("url"))).toList();
7177
}
7278

@@ -150,7 +156,9 @@ private static Parameter resolveParameterOrParse(
150156
if (ref != null) {
151157
String name = stripPrefix(ref, "#/components/parameters/");
152158
Parameter p = componentParameters.get(name);
153-
if (p == null) throw new IllegalArgumentException("unknown parameter ref: " + ref);
159+
if (p == null) {
160+
throw new IllegalArgumentException("unknown parameter ref: " + ref);
161+
}
154162
return p;
155163
}
156164
return parseParameter(raw);

src/main/java/com/retailsvc/http/spec/schema/SchemaParser.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ public static Schema parse(Map<String, Object> raw) {
1616
return new RefSchema((String) raw.get("$ref"));
1717
}
1818

19-
if (raw.containsKey("oneOf")) return new OneOfSchema(parseList(raw, "oneOf"));
20-
if (raw.containsKey("anyOf")) return new AnyOfSchema(parseList(raw, "anyOf"));
21-
if (raw.containsKey("allOf")) return new AllOfSchema(parseList(raw, "allOf"));
22-
if (raw.containsKey("not")) return new NotSchema(parse((Map<String, Object>) raw.get("not")));
23-
if (raw.containsKey("const")) return new ConstSchema(raw.get("const"));
19+
if (raw.containsKey("oneOf")) {
20+
return new OneOfSchema(parseList(raw, "oneOf"));
21+
}
22+
if (raw.containsKey("anyOf")) {
23+
return new AnyOfSchema(parseList(raw, "anyOf"));
24+
}
25+
if (raw.containsKey("allOf")) {
26+
return new AllOfSchema(parseList(raw, "allOf"));
27+
}
28+
if (raw.containsKey("not")) {
29+
return new NotSchema(parse((Map<String, Object>) raw.get("not")));
30+
}
31+
if (raw.containsKey("const")) {
32+
return new ConstSchema(raw.get("const"));
33+
}
2434
if (raw.containsKey("enum") && !raw.containsKey("type")) {
2535
return new EnumSchema(List.copyOf((List<Object>) raw.get("enum")));
2636
}
@@ -136,7 +146,9 @@ private static ArraySchema parseArray(Map<String, Object> raw, Set<TypeName> typ
136146
private static List<Schema> parseList(Map<String, Object> raw, String key) {
137147
List<Map<String, Object>> raws = (List<Map<String, Object>>) raw.get(key);
138148
List<Schema> out = new ArrayList<>(raws.size());
139-
for (Map<String, Object> r : raws) out.add(parse(r));
149+
for (Map<String, Object> r : raws) {
150+
out.add(parse(r));
151+
}
140152
return List.copyOf(out);
141153
}
142154

src/main/java/com/retailsvc/http/validate/DefaultValidator.java

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public DefaultValidator(Function<String, Schema> refResolver) {
3939

4040
@Override
4141
public void validate(Object value, Schema schema, String pointer) {
42-
if (value == null && schema.types().contains(TypeName.NULL)) return;
42+
if (value == null && schema.types().contains(TypeName.NULL)) {
43+
return;
44+
}
4345

4446
switch (schema) {
4547
case RefSchema r -> validate(value, refResolver.apply(r.pointer()), pointer);
@@ -68,15 +70,21 @@ private void validateBoolean(Object value, String pointer) {
6870
private void validateString(Object value, StringSchema s, String pointer) {
6971
require(value instanceof String, pointer, "type", "expected string");
7072
String str = (String) value;
71-
if (s.minLength() != null && str.length() < s.minLength())
73+
if (s.minLength() != null && str.length() < s.minLength()) {
7274
fail(pointer, "minLength", "string shorter than " + s.minLength(), str);
73-
if (s.maxLength() != null && str.length() > s.maxLength())
75+
}
76+
if (s.maxLength() != null && str.length() > s.maxLength()) {
7477
fail(pointer, "maxLength", "string longer than " + s.maxLength(), str);
75-
if (s.pattern() != null && !Pattern.compile(s.pattern()).matcher(str).matches())
78+
}
79+
if (s.pattern() != null && !Pattern.compile(s.pattern()).matcher(str).matches()) {
7680
fail(pointer, "pattern", "does not match pattern " + s.pattern(), str);
77-
if (s.enumValues() != null && !s.enumValues().contains(str))
81+
}
82+
if (s.enumValues() != null && !s.enumValues().contains(str)) {
7883
fail(pointer, "enum", "value not in enum", str);
79-
if (s.format() != null) validateStringFormat(str, s.format(), pointer);
84+
}
85+
if (s.format() != null) {
86+
validateStringFormat(str, s.format(), pointer);
87+
}
8088
}
8189

8290
private void validateStringFormat(String str, String format, String pointer) {
@@ -108,8 +116,9 @@ private void validateStringFormat(String str, String format, String pointer) {
108116

109117
private void validateInteger(Object value, IntegerSchema s, String pointer) {
110118
long n;
111-
if (value instanceof Number num) n = num.longValue();
112-
else if (value instanceof String str) {
119+
if (value instanceof Number num) {
120+
n = num.longValue();
121+
} else if (value instanceof String str) {
113122
try {
114123
n = Long.parseLong(str);
115124
} catch (NumberFormatException e) {
@@ -121,22 +130,28 @@ else if (value instanceof String str) {
121130
return;
122131
}
123132

124-
if (s.minimum() != null && n < s.minimum())
133+
if (s.minimum() != null && n < s.minimum()) {
125134
fail(pointer, "minimum", "integer below minimum " + s.minimum(), n);
126-
if (s.maximum() != null && n > s.maximum())
135+
}
136+
if (s.maximum() != null && n > s.maximum()) {
127137
fail(pointer, "maximum", "integer above maximum " + s.maximum(), n);
128-
if (s.exclusiveMinimum() != null && n <= s.exclusiveMinimum())
138+
}
139+
if (s.exclusiveMinimum() != null && n <= s.exclusiveMinimum()) {
129140
fail(pointer, "exclusiveMinimum", "integer not greater than " + s.exclusiveMinimum(), n);
130-
if (s.exclusiveMaximum() != null && n >= s.exclusiveMaximum())
141+
}
142+
if (s.exclusiveMaximum() != null && n >= s.exclusiveMaximum()) {
131143
fail(pointer, "exclusiveMaximum", "integer not less than " + s.exclusiveMaximum(), n);
132-
if (s.multipleOf() != null && n % s.multipleOf() != 0)
144+
}
145+
if (s.multipleOf() != null && n % s.multipleOf() != 0) {
133146
fail(pointer, "multipleOf", "not a multiple of " + s.multipleOf(), n);
147+
}
134148
}
135149

136150
private void validateNumber(Object value, NumberSchema s, String pointer) {
137151
double n;
138-
if (value instanceof Number num) n = num.doubleValue();
139-
else if (value instanceof String str) {
152+
if (value instanceof Number num) {
153+
n = num.doubleValue();
154+
} else if (value instanceof String str) {
140155
try {
141156
n = Double.parseDouble(str);
142157
} catch (NumberFormatException e) {
@@ -148,16 +163,21 @@ else if (value instanceof String str) {
148163
return;
149164
}
150165

151-
if (s.minimum() != null && n < s.minimum().doubleValue())
166+
if (s.minimum() != null && n < s.minimum().doubleValue()) {
152167
fail(pointer, "minimum", "number below minimum " + s.minimum(), n);
153-
if (s.maximum() != null && n > s.maximum().doubleValue())
168+
}
169+
if (s.maximum() != null && n > s.maximum().doubleValue()) {
154170
fail(pointer, "maximum", "number above maximum " + s.maximum(), n);
155-
if (s.exclusiveMinimum() != null && n <= s.exclusiveMinimum().doubleValue())
171+
}
172+
if (s.exclusiveMinimum() != null && n <= s.exclusiveMinimum().doubleValue()) {
156173
fail(pointer, "exclusiveMinimum", "number not greater than " + s.exclusiveMinimum(), n);
157-
if (s.exclusiveMaximum() != null && n >= s.exclusiveMaximum().doubleValue())
174+
}
175+
if (s.exclusiveMaximum() != null && n >= s.exclusiveMaximum().doubleValue()) {
158176
fail(pointer, "exclusiveMaximum", "number not less than " + s.exclusiveMaximum(), n);
159-
if (s.multipleOf() != null && (n / s.multipleOf().doubleValue()) % 1 != 0)
177+
}
178+
if (s.multipleOf() != null && (n / s.multipleOf().doubleValue()) % 1 != 0) {
160179
fail(pointer, "multipleOf", "not a multiple of " + s.multipleOf(), n);
180+
}
161181
}
162182

163183
@SuppressWarnings("unchecked")
@@ -173,10 +193,12 @@ private void validateObject(Object value, ObjectSchema s, String pointer) {
173193
"required property missing");
174194
}
175195

176-
if (s.minProperties() != null && map.size() < s.minProperties())
196+
if (s.minProperties() != null && map.size() < s.minProperties()) {
177197
fail(pointer, "minProperties", "fewer than " + s.minProperties() + " properties", map.size());
178-
if (s.maxProperties() != null && map.size() > s.maxProperties())
198+
}
199+
if (s.maxProperties() != null && map.size() > s.maxProperties()) {
179200
fail(pointer, "maxProperties", "more than " + s.maxProperties() + " properties", map.size());
201+
}
180202

181203
for (var entry : map.entrySet()) {
182204
String childPointer = pointer + "/" + entry.getKey();
@@ -203,17 +225,23 @@ private void validateArray(Object value, ArraySchema s, String pointer) {
203225
require(value instanceof Iterable, pointer, "type", "expected array");
204226
Iterable<?> it = (Iterable<?>) value;
205227
List<Object> elements = new ArrayList<>();
206-
for (Object o : it) elements.add(o);
228+
for (Object o : it) {
229+
elements.add(o);
230+
}
207231

208-
if (s.minItems() != null && elements.size() < s.minItems())
232+
if (s.minItems() != null && elements.size() < s.minItems()) {
209233
fail(pointer, "minItems", "fewer than " + s.minItems() + " items", elements.size());
210-
if (s.maxItems() != null && elements.size() > s.maxItems())
234+
}
235+
if (s.maxItems() != null && elements.size() > s.maxItems()) {
211236
fail(pointer, "maxItems", "more than " + s.maxItems() + " items", elements.size());
237+
}
212238

213239
if (s.uniqueItems()) {
214240
Set<Object> seen = new HashSet<>();
215241
for (Object e : elements) {
216-
if (!seen.add(e)) fail(pointer, "uniqueItems", "duplicate item", e);
242+
if (!seen.add(e)) {
243+
fail(pointer, "uniqueItems", "duplicate item", e);
244+
}
217245
}
218246
}
219247

0 commit comments

Comments
 (0)