Skip to content

Commit 5f0eb52

Browse files
authored
Fixed Idea warnings
1 parent f9513d2 commit 5f0eb52

File tree

4 files changed

+15
-43
lines changed

4 files changed

+15
-43
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,11 +2005,7 @@ public byte[] blob() {
20052005
}
20062006

20072007
public String text() {
2008-
try {
2009-
return stream.toString(StandardCharsets.UTF_8.name());
2010-
} catch (java.io.UnsupportedEncodingException ex) {
2011-
throw new UnsupportedOperationException(ex);
2012-
}
2008+
return stream.toString(StandardCharsets.UTF_8);
20132009
}
20142010

20152011
public Object json() {
@@ -3330,7 +3326,7 @@ public Builder add(final String key, final Builder builder) {
33303326
}
33313327

33323328
public Builder add(final Map<String, Object> map) {
3333-
deepCopyMap(map).forEach(data::put);
3329+
data.putAll(deepCopyMap(map));
33343330
return this;
33353331
}
33363332

@@ -3361,7 +3357,7 @@ public static Builder fromXml(final String xml) {
33613357

33623358
public static Builder fromMap(final Map<String, Object> map) {
33633359
final Builder builder = new Builder();
3364-
deepCopyMap(map).forEach(builder.data::put);
3360+
builder.data.putAll(deepCopyMap(map));
33653361
return builder;
33663362
}
33673363

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private static final class MyIterable<T> implements Iterable<T> {
254254
}
255255

256256
public Iterator<T> iterator() {
257-
return new Iterator<T>() {
257+
return new Iterator<>() {
258258
@Override
259259
public boolean hasNext() {
260260
return true;
@@ -1726,7 +1726,7 @@ public static <T> List<List<T>> unzip(final List<T>... lists) {
17261726
public static <K, V> List<Map.Entry<K, V>> object(final List<K> keys, final List<V> values) {
17271727
return map(
17281728
keys,
1729-
new Function<K, Map.Entry<K, V>>() {
1729+
new Function<>() {
17301730
private int index;
17311731

17321732
@Override
@@ -2065,7 +2065,7 @@ public static <T, F> Function<F, T> bind(final Function<F, T> function) {
20652065
* Documented, #memoize
20662066
*/
20672067
public static <T, F> Function<F, T> memoize(final Function<F, T> function) {
2068-
return new MemoizeFunction<F, T>() {
2068+
return new MemoizeFunction<>() {
20692069
@Override
20702070
public T calc(F arg) {
20712071
return function.apply(arg);
@@ -2170,7 +2170,7 @@ public T get() {
21702170
*/
21712171
public static <T> Supplier<T> debounce(
21722172
final Supplier<T> function, final int delayMilliseconds) {
2173-
return new Supplier<T>() {
2173+
return new Supplier<>() {
21742174
private java.util.concurrent.ScheduledFuture<T> timeout;
21752175

21762176
@Override
@@ -2262,7 +2262,7 @@ public E get() {
22622262
* Documented, #once
22632263
*/
22642264
public static <T> Supplier<T> once(final Supplier<T> function) {
2265-
return new Supplier<T>() {
2265+
return new Supplier<>() {
22662266
private volatile boolean executed;
22672267
private T result;
22682268

@@ -2337,13 +2337,9 @@ public static List<String> methods(final Object object) {
23372337
@SuppressWarnings("unchecked")
23382338
public static <K, V> Map<K, V> extend(final Map<K, V> destination, final Map<K, V>... sources) {
23392339
final Map<K, V> result = newLinkedHashMap();
2340-
for (final Map.Entry<K, V> entry : destination.entrySet()) {
2341-
result.put(entry.getKey(), entry.getValue());
2342-
}
2340+
result.putAll(destination);
23432341
for (final Map<K, V> source : sources) {
2344-
for (final Map.Entry<K, V> entry : source.entrySet()) {
2345-
result.put(entry.getKey(), entry.getValue());
2346-
}
2342+
result.putAll(source);
23472343
}
23482344
return result;
23492345
}
@@ -2447,12 +2443,8 @@ public static <K, V> List<Map.Entry<K, V>> omit(
24472443
*/
24482444
public static <K, V> Map<K, V> defaults(final Map<K, V> object, final Map<K, V> defaults) {
24492445
final Map<K, V> result = newLinkedHashMap();
2450-
for (final Map.Entry<K, V> entry : defaults.entrySet()) {
2451-
result.put(entry.getKey(), entry.getValue());
2452-
}
2453-
for (final Map.Entry<K, V> entry : object.entrySet()) {
2454-
result.put(entry.getKey(), entry.getValue());
2455-
}
2446+
result.putAll(defaults);
2447+
result.putAll(object);
24562448
return result;
24572449
}
24582450

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ public XmlStringBuilder append(final String string) {
142142
}
143143

144144
public XmlStringBuilder fillSpaces() {
145-
for (int index = 0; index < ident; index += 1) {
146-
builder.append(identStep == Step.TABS ? '\t' : ' ');
147-
}
145+
builder.append(
146+
String.valueOf(identStep == Step.TABS ? '\t' : ' ').repeat(Math.max(0, ident)));
148147
return this;
149148
}
150149

@@ -1053,9 +1052,7 @@ private static void escape(String s, StringBuilder sb) {
10531052
|| ch >= '\u2000' && ch <= '\u20FF') {
10541053
String ss = Integer.toHexString(ch);
10551054
sb.append("&#x");
1056-
for (int k = 0; k < 4 - ss.length(); k++) {
1057-
sb.append('0');
1058-
}
1055+
sb.append("0".repeat(4 - ss.length()));
10591056
sb.append(ss.toUpperCase()).append(";");
10601057
} else {
10611058
sb.append(ch);

src/test/java/com/github/underscore/LodashTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -685,19 +685,6 @@ void fetchGetXml() {
685685
assertEquals("Tove", U.get(result.xmlMap(), "note.to"));
686686
}
687687

688-
@Test
689-
void fetchResponseError() {
690-
java.io.ByteArrayOutputStream stream =
691-
new java.io.ByteArrayOutputStream() {
692-
public String toString(String encoding)
693-
throws java.io.UnsupportedEncodingException {
694-
throw new java.io.UnsupportedEncodingException();
695-
}
696-
};
697-
U.FetchResponse fetchResponse = new U.FetchResponse(true, 100, null, stream);
698-
assertThrows(UnsupportedOperationException.class, () -> fetchResponse.text());
699-
}
700-
701688
@Test
702689
void fetchResponseBlob() {
703690
java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();

0 commit comments

Comments
 (0)