Skip to content

Commit e34fd8b

Browse files
committed
[fit] solve review comments
1 parent 9b73d43 commit e34fd8b

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

framework/fit/java/fit-builtin/services/fit-http-classic/definition/src/main/java/modelengine/fit/http/support/DefaultCookieCollection.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import modelengine.fit.http.header.ConfigurableCookieCollection;
1414
import modelengine.fit.http.header.CookieCollection;
1515
import modelengine.fit.http.util.HttpUtils;
16+
import modelengine.fitframework.util.CollectionUtils;
1617
import modelengine.fitframework.util.StringUtils;
1718

1819
import java.util.ArrayList;
@@ -35,26 +36,26 @@ public class DefaultCookieCollection implements ConfigurableCookieCollection {
3536

3637
@Override
3738
public Optional<Cookie> get(String name) {
38-
List<Cookie> cookies = store.get(name);
39-
if (cookies == null || cookies.isEmpty()) {
39+
List<Cookie> cookies = this.store.get(name);
40+
if (CollectionUtils.isEmpty(cookies)) {
4041
return Optional.empty();
4142
}
4243
return Optional.of(cookies.get(0));
4344
}
4445

4546
@Override
4647
public List<Cookie> all(String name) {
47-
return store.getOrDefault(name, Collections.emptyList());
48+
return this.store.getOrDefault(name, Collections.emptyList());
4849
}
4950

5051
@Override
5152
public List<Cookie> all() {
52-
return store.values().stream().flatMap(List::stream).collect(Collectors.toList());
53+
return this.store.values().stream().flatMap(List::stream).collect(Collectors.toList());
5354
}
5455

5556
@Override
5657
public int size() {
57-
return store.values().stream().mapToInt(List::size).sum();
58+
return this.store.values().stream().mapToInt(List::size).sum();
5859
}
5960

6061
@Override
@@ -63,10 +64,10 @@ public void add(Cookie cookie) {
6364
return;
6465
}
6566
if (HttpUtils.isInvalidCookiePair(cookie.name(), cookie.value())) {
66-
throw new IllegalArgumentException("Invalid cookie: name or value is not allowed");
67+
throw new IllegalArgumentException("Invalid cookie: name or value is not allowed.");
6768
}
68-
store.computeIfAbsent(cookie.name(), k -> new ArrayList<>());
69-
List<Cookie> list = store.get(cookie.name());
69+
this.store.computeIfAbsent(cookie.name(), k -> new ArrayList<>());
70+
List<Cookie> list = this.store.get(cookie.name());
7071
list.removeIf(c -> Objects.equals(c.path(), cookie.path()) && Objects.equals(c.domain(), cookie.domain()));
7172
list.add(cookie);
7273
}

framework/fit/java/fit-builtin/services/fit-http-classic/definition/src/main/java/modelengine/fit/http/util/HttpUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static void parseCookieAttributes(String[] parts, Cookie.Builder builder
236236
* @return 如果 name 和 value 都合法返回 {@code true},否则返回 {@code false}。
237237
*/
238238
public static boolean isInvalidCookiePair(String name, String value) {
239-
if (name == null || name.isEmpty() || !TOKEN_PATTERN.matcher(name).matches()) {
239+
if (StringUtils.isEmpty(name) || !TOKEN_PATTERN.matcher(name).matches()) {
240240
return true;
241241
}
242242
if (value == null) {

0 commit comments

Comments
 (0)