删除意义不大的集合工具。
parent
fba176864c
commit
8d9ccdb08e
|
@ -1,15 +0,0 @@
|
|||
package xyz.zhouxy.plusone.commons.collection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ListTools {
|
||||
|
||||
public static <T> void transformValue(List<T> list, int index, Function<T, ? extends T> func) {
|
||||
list.set(index, func.apply(list.get(index)));
|
||||
}
|
||||
|
||||
private ListTools() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package xyz.zhouxy.plusone.commons.collection;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MapTools {
|
||||
|
||||
public static <K, V> void transformValue(Map<K, V> map, K key, Function<V, ? extends V> func) {
|
||||
if (map.containsKey(key)) {
|
||||
map.put(key, func.apply(map.get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
private MapTools() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package xyz.zhouxy.plusone.commons.collection;
|
||||
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
public class TableTools {
|
||||
|
||||
public static <R, C, V> Table<R, C, V> synchronizedTable(Table<R, C, V> t) {
|
||||
if (t instanceof SynchronizedTable) {
|
||||
return t;
|
||||
}
|
||||
return SynchronizedTable.of(t);
|
||||
}
|
||||
|
||||
private TableTools() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
}
|
|
@ -17,23 +17,14 @@
|
|||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.collection.CollectionTools;
|
||||
import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
|
||||
|
||||
@Beta
|
||||
public class ArrayTools {
|
||||
|
||||
|
@ -186,61 +177,6 @@ public class ArrayTools {
|
|||
return result;
|
||||
}
|
||||
|
||||
// array -> map
|
||||
|
||||
public static <K, V> HashMap<K, V> toHashMap(
|
||||
V[] c,
|
||||
Function<? super V, K> keyGenerator,
|
||||
int initialCapacity) {
|
||||
HashMap<K, V> map = new HashMap<>(initialCapacity);
|
||||
fillIntoEmptyMap(map, c, keyGenerator);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K, V> HashMap<K, V> toHashMap(
|
||||
V[] c,
|
||||
Function<? super V, K> keyGenerator) {
|
||||
return toHashMap(c, keyGenerator, c.length);
|
||||
}
|
||||
|
||||
public static <K, V> SafeConcurrentHashMap<K, V> toConcurrentHashMap(
|
||||
V[] c,
|
||||
Function<? super V, K> keyGenerator,
|
||||
int initialCapacity) {
|
||||
SafeConcurrentHashMap<K, V> map = new SafeConcurrentHashMap<>(initialCapacity);
|
||||
fillIntoEmptyMap(map, c, keyGenerator);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K, V> SafeConcurrentHashMap<K, V> toConcurrentHashMap(
|
||||
V[] c,
|
||||
Function<? super V, K> keyGenerator) {
|
||||
return toConcurrentHashMap(c, keyGenerator, c.length);
|
||||
}
|
||||
|
||||
public static <K extends Comparable<? super K>, V> TreeMap<K, V> toTreeMap(
|
||||
V[] c,
|
||||
Function<? super V, K> keyGenerator) {
|
||||
TreeMap<K, V> map = new TreeMap<>();
|
||||
fillIntoEmptyMap(map, c, keyGenerator);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K, V> TreeMap<K, V> toTreeMap(
|
||||
V[] c,
|
||||
Function<? super V, K> keyGenerator,
|
||||
Comparator<? super K> keyComparator) {
|
||||
TreeMap<K, V> map = new TreeMap<>(keyComparator);
|
||||
fillIntoEmptyMap(map, c, keyGenerator);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K, V> void fillIntoEmptyMap(
|
||||
Map<K, ? super V> map, V[] c,
|
||||
Function<? super V, K> keyGenerator) {
|
||||
CollectionTools.fillIntoEmptyMap(map, Arrays.asList(c), keyGenerator);
|
||||
}
|
||||
|
||||
private ArrayTools() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue