-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use `computeIfAbsent()`, with constant function variables --------- Co-authored-by: Jonathan Hedley <jonathan@hedley.net>
- Loading branch information
1 parent
00f8318
commit bf40e9c
Showing
5 changed files
with
59 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jsoup.internal; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.IdentityHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* An internal class containing functions for use with {@link Map#computeIfAbsent(Object, Function)}. | ||
*/ | ||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
public final class Functions { | ||
private static final Function ListFunction = key -> new ArrayList<>(); | ||
private static final Function SetFunction = key -> new HashSet<>(); | ||
private static final Function MapFunction = key -> new HashMap<>(); | ||
private static final Function IdentityMapFunction = key -> new IdentityHashMap<>(); | ||
|
||
private Functions() { | ||
} | ||
|
||
public static <T, U> Function<T, List<U>> listFunction() { | ||
return (Function<T, List<U>>) ListFunction; | ||
} | ||
|
||
public static <T, U> Function<T, Set<U>> setFunction() { | ||
return (Function<T, Set<U>>) SetFunction; | ||
} | ||
|
||
public static <T, K, V> Function<T, Map<K, V>> mapFunction() { | ||
return (Function<T, Map<K, V>>) MapFunction; | ||
} | ||
|
||
public static <T, K, V> Function<T, IdentityHashMap<K, V>> identityMapFunction() { | ||
return (Function<T, IdentityHashMap<K, V>>) IdentityMapFunction; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters