Skip to content

Commit e882faf

Browse files
committed
Fixed sonarcloud warnings.
1 parent 5579d1d commit e882faf

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

src/main/java/com/github/underscore/MemoizeFunction.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ public abstract class MemoizeFunction<F, T> implements Function<F, T> {
99
public abstract T calc(final F n);
1010

1111
public T apply(final F key) {
12-
if (!cache.containsKey(key)) {
13-
cache.put(key, calc(key));
14-
}
15-
return cache.get(key);
12+
final T value = calc(key);
13+
cache.putIfAbsent(key, value);
14+
return value;
1615
}
1716
}

src/main/java/com/github/underscore/Optional.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.function.Supplier;
77

88
public final class Optional<T> {
9-
private static final Optional<?> EMPTY = new Optional();
9+
private static final Optional<?> EMPTY = new Optional<>();
1010
private final T arg;
1111
private final boolean absent;
1212

@@ -99,7 +99,7 @@ public boolean equals(final Object o) {
9999
return false;
100100
}
101101

102-
final Optional optional = (Optional) o;
102+
final Optional<?> optional = (Optional) o;
103103

104104
return absent == optional.absent && Objects.equals(arg, optional.arg);
105105
}

src/main/java/com/github/underscore/U.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,8 +2892,7 @@ public Chain<T> tap(final Consumer<T> func) {
28922892
}
28932893

28942894
public Chain<T> forEach(final Consumer<T> func) {
2895-
U.each(list, func);
2896-
return new Chain<>(list);
2895+
return tap(func);
28972896
}
28982897

28992898
public Chain<T> forEachRight(final Consumer<T> func) {
@@ -3180,9 +3179,7 @@ public String join() {
31803179
@SuppressWarnings("unchecked")
31813180
public static <T> List<T> push(final List<T> list, final T ... values) {
31823181
final List<T> result = newArrayList(list);
3183-
for (T value : values) {
3184-
result.add(value);
3185-
}
3182+
Collections.addAll(result, values);
31863183
return result;
31873184
}
31883185

src/main/java/com/github/underscore/lodash/Json.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
public final class Json {
3232
private static final String NULL = "null";
33+
private static final String DIGIT = "digit";
3334

3435
public static class JsonStringBuilder {
3536
public enum Step {
@@ -689,7 +690,7 @@ private Number readNumber() {
689690
readChar('-');
690691
int firstDigit = current;
691692
if (!readDigit()) {
692-
throw expected("digit");
693+
throw expected(DIGIT);
693694
}
694695
if (firstDigit != '0') {
695696
while (readDigit()) {
@@ -722,7 +723,7 @@ private boolean readFraction() {
722723
return false;
723724
}
724725
if (!readDigit()) {
725-
throw expected("digit");
726+
throw expected(DIGIT);
726727
}
727728
while (readDigit()) {
728729
}
@@ -737,7 +738,7 @@ private boolean readExponent() {
737738
readChar('-');
738739
}
739740
if (!readDigit()) {
740-
throw expected("digit");
741+
throw expected(DIGIT);
741742
}
742743
while (readDigit()) {
743744
}

0 commit comments

Comments
 (0)