Commit c91f5209 authored by Alexey Kudravtsev's avatar Alexey Kudravtsev
Browse files

cleanup

parent 5ca97325
Showing with 46 additions and 54 deletions
+46 -54
......@@ -46,47 +46,47 @@ public class ModuleRootModificationUtil {
public static void addModuleLibrary(@NotNull Module module,
@Nullable String libName,
@NotNull List<String> classesRoots,
@NotNull List<String> sourceRoots) {
addModuleLibrary(module, libName, classesRoots, sourceRoots, DependencyScope.COMPILE);
@NotNull List<String> classesRootUrls,
@NotNull List<String> sourceRootUrls) {
addModuleLibrary(module, libName, classesRootUrls, sourceRootUrls, DependencyScope.COMPILE);
}
public static void addModuleLibrary(@NotNull Module module,
@Nullable String libName,
@NotNull List<String> classesRoots,
@NotNull List<String> sourceRoots,
@NotNull List<String> classesRootUrls,
@NotNull List<String> sourceRootUrls,
@NotNull DependencyScope scope) {
addModuleLibrary(module, libName, classesRoots, sourceRoots, Collections.emptyList(), scope);
addModuleLibrary(module, libName, classesRootUrls, sourceRootUrls, Collections.emptyList(), scope);
}
public static void addModuleLibrary(@NotNull Module module,
@Nullable String libName,
@NotNull List<String> classesRoots,
@NotNull List<String> sourceRoots,
@NotNull List<String> excludedRoots,
@NotNull List<String> classesRootUrls,
@NotNull List<String> sourceRootUrls,
@NotNull List<String> excludedRootUrls,
@NotNull DependencyScope scope) {
addModuleLibrary(module, libName, classesRoots, sourceRoots, excludedRoots, scope, false);
addModuleLibrary(module, libName, classesRootUrls, sourceRootUrls, excludedRootUrls, scope, false);
}
public static void addModuleLibrary(@NotNull Module module,
@Nullable String libName,
@NotNull List<String> classesRoots,
@NotNull List<String> sourceRoots,
@NotNull List<String> excludedRoots,
@NotNull List<String> classesRootUrls,
@NotNull List<String> sourceRootUrls,
@NotNull List<String> excludedRootUrls,
@NotNull DependencyScope scope,
boolean exported) {
updateModel(module, model -> {
LibraryEx library = (LibraryEx)model.getModuleLibraryTable().createLibrary(libName);
LibraryEx.ModifiableModelEx libraryModel = library.getModifiableModel();
for (String root : classesRoots) {
libraryModel.addRoot(root, OrderRootType.CLASSES);
for (String rootUrl : classesRootUrls) {
libraryModel.addRoot(rootUrl, OrderRootType.CLASSES);
}
for (String root : sourceRoots) {
libraryModel.addRoot(root, OrderRootType.SOURCES);
for (String rootUrl : sourceRootUrls) {
libraryModel.addRoot(rootUrl, OrderRootType.SOURCES);
}
for (String excluded : excludedRoots) {
libraryModel.addExcludedRoot(excluded);
for (String excludedUrl : excludedRootUrls) {
libraryModel.addExcludedRoot(excludedUrl);
}
LibraryOrderEntry entry = model.findLibraryOrderEntry(library);
......
......@@ -13,7 +13,6 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Stripped-down version of {@code com.intellij.util.containers.ContainerUtil}.
......@@ -25,13 +24,13 @@ public class ContainerUtilRt {
@NotNull
@Contract(value = " -> new", pure = true)
public static <K, V> HashMap<K, V> newHashMap() {
return new java.util.HashMap<K, V>();
return new HashMap<K, V>();
}
@NotNull
@Contract(value = "_ -> new", pure = true)
public static <K, V> HashMap<K, V> newHashMap(@NotNull Map<? extends K, ? extends V> map) {
return new java.util.HashMap<K, V>(map);
return new HashMap<K, V>(map);
}
@NotNull
......@@ -41,7 +40,7 @@ public class ContainerUtilRt {
throw new IllegalArgumentException(keys + " should have same length as " + values);
}
Map<K, V> map = newHashMap(keys.size());
Map<K, V> map = new HashMap<K, V>(keys.size());
for (int i = 0; i < keys.size(); ++i) {
map.put(keys.get(i), values.get(i));
}
......@@ -51,7 +50,7 @@ public class ContainerUtilRt {
@NotNull
@Contract(value = "_,_ -> new", pure = true)
public static <K, V> Map<K, V> newHashMap(@NotNull Pair<? extends K, ? extends V> first, @NotNull Pair<? extends K, ? extends V>... entries) {
Map<K, V> map = newHashMap(entries.length + 1);
Map<K, V> map = new HashMap<K, V>(entries.length + 1);
map.put(first.getFirst(), first.getSecond());
for (Pair<? extends K, ? extends V> entry : entries) {
map.put(entry.getFirst(), entry.getSecond());
......@@ -62,7 +61,7 @@ public class ContainerUtilRt {
@NotNull
@Contract(value = "_ -> new", pure = true)
public static <K, V> Map<K, V> newHashMap(int initialCapacity) {
return new java.util.HashMap<K, V>(initialCapacity);
return new HashMap<K, V>(initialCapacity);
}
@NotNull
......@@ -168,19 +167,19 @@ public class ContainerUtilRt {
@NotNull
@Contract(value = " -> new", pure = true)
public static <T> HashSet<T> newHashSet() {
return new java.util.HashSet<T>();
return new HashSet<T>();
}
@NotNull
@Contract(value = "_ -> new", pure = true)
public static <T> HashSet<T> newHashSet(int initialCapacity) {
return new java.util.HashSet<T>(initialCapacity);
return new HashSet<T>(initialCapacity);
}
@NotNull
@Contract(value = "_ -> new", pure = true)
public static <T> HashSet<T> newHashSet(@NotNull T... elements) {
return new java.util.HashSet<T>(Arrays.asList(elements));
return new HashSet<T>(Arrays.asList(elements));
}
@NotNull
......@@ -188,14 +187,14 @@ public class ContainerUtilRt {
public static <T> HashSet<T> newHashSet(@NotNull Iterable<? extends T> elements) {
if (elements instanceof Collection) {
@SuppressWarnings("unchecked") Collection<? extends T> collection = (Collection<? extends T>)elements;
return new java.util.HashSet<T>(collection);
return new HashSet<T>(collection);
}
return newHashSet(elements.iterator());
}
@NotNull
public static <T> HashSet<T> newHashSet(@NotNull Iterator<? extends T> iterator) {
HashSet<T> set = newHashSet();
HashSet<T> set = new HashSet<T>();
while (iterator.hasNext()) set.add(iterator.next());
return set;
}
......@@ -339,13 +338,6 @@ public class ContainerUtilRt {
return (List<T>)EmptyList.INSTANCE;
}
@NotNull
@Contract(value = " -> new", pure = true)
public static <T> CopyOnWriteArrayList<T> createEmptyCOWList() {
// does not create garbage new Object[0]
return new CopyOnWriteArrayList<T>(ContainerUtilRt.<T>emptyList());
}
/**
* @see #addIfNotNull(Collection, Object)
*/
......
......@@ -30,13 +30,13 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <K, V> HashMap<K, V> newHashMap() {
return ContainerUtilRt.newHashMap();
return new HashMap<K, V>();
}
@NotNull
@Contract(pure=true)
public static <K, V> HashMap<K, V> newHashMap(@NotNull Map<? extends K, ? extends V> map) {
return ContainerUtilRt.newHashMap(map);
return new HashMap<K, V>(map);
}
@NotNull
......@@ -279,13 +279,13 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> HashSet<T> newHashSet() {
return ContainerUtilRt.newHashSet();
return new HashSet<T>();
}
@NotNull
@Contract(pure=true)
public static <T> HashSet<T> newHashSet(int initialCapacity) {
return ContainerUtilRt.newHashSet(initialCapacity);
return new HashSet<T>(initialCapacity);
}
@NotNull
......@@ -587,10 +587,10 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <K, V> Map<K, V> intersection(@NotNull Map<? extends K, ? extends V> map1, @NotNull Map<? extends K, ? extends V> map2) {
final Map<K, V> res = newHashMap();
final Set<K> keys = newHashSet();
final Set<K> keys = new HashSet<K>();
keys.addAll(map1.keySet());
keys.addAll(map2.keySet());
final Map<K, V> res = new HashMap<K, V>();
for (K k : keys) {
V v1 = map1.get(k);
V v2 = map2.get(k);
......@@ -604,10 +604,10 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <K, V> Map<K,Couple<V>> diff(@NotNull Map<? extends K, ? extends V> map1, @NotNull Map<? extends K, ? extends V> map2) {
final Map<K, Couple<V>> res = newHashMap();
final Set<K> keys = newHashSet();
final Set<K> keys = new HashSet<K>();
keys.addAll(map1.keySet());
keys.addAll(map2.keySet());
final Map<K, Couple<V>> res = new HashMap<K, Couple<V>>();
for (K k : keys) {
V v1 = map1.get(k);
V v2 = map2.get(k);
......@@ -724,7 +724,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
public static <T> Set<T> collectSet(@NotNull Iterator<? extends T> iterator) {
if (!iterator.hasNext()) return Collections.emptySet();
Set<T> hashSet = newHashSet();
Set<T> hashSet = new HashSet<T>();
addAll(hashSet, iterator);
return hashSet;
}
......@@ -732,7 +732,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure = true)
public static <K, V> Map<K, V> newMapFromKeys(@NotNull Iterator<? extends K> keys, @NotNull Convertor<? super K, ? extends V> valueConvertor) {
Map<K, V> map = newHashMap();
Map<K, V> map = new HashMap<K, V>();
while (keys.hasNext()) {
K key = keys.next();
map.put(key, valueConvertor.convert(key));
......@@ -743,7 +743,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure = true)
public static <K, V> Map<K, V> newMapFromValues(@NotNull Iterator<? extends V> values, @NotNull Convertor<? super V, ? extends K> keyConvertor) {
Map<K, V> map = newHashMap();
Map<K, V> map = new HashMap<K, V>();
fillMapWithValues(map, values, keyConvertor);
return map;
}
......@@ -1000,7 +1000,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure = true)
public static <K, V> Map<K, V> filter(@NotNull Map<? extends K, ? extends V> map, @NotNull Condition<? super K> keyFilter) {
Map<K, V> result = newHashMap();
Map<K, V> result = new HashMap<K, V>();
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
if (keyFilter.value(entry.getKey())) {
result.put(entry.getKey(), entry.getValue());
......@@ -1084,7 +1084,7 @@ public class ContainerUtil extends ContainerUtilRt {
}
public static <T> void removeDuplicates(@NotNull Collection<T> collection) {
Set<T> collected = newHashSet();
Set<T> collected = new HashSet<T>();
for (Iterator<T> iterator = collection.iterator(); iterator.hasNext();) {
T t = iterator.next();
if (!collected.contains(t)) {
......@@ -1099,7 +1099,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static Map<String, String> stringMap(@NotNull final String... keyValues) {
final Map<String, String> result = newHashMap();
final Map<String, String> result = new HashMap<String, String>();
for (int i = 0; i < keyValues.length - 1; i+=2) {
result.put(keyValues[i], keyValues[i+1]);
}
......@@ -1712,7 +1712,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> Collection<T> subtract(@NotNull Collection<? extends T> from, @NotNull Collection<? extends T> what) {
final Set<T> set = newHashSet(from);
final Set<T> set = ContainerUtilRt.newHashSet(from);
set.removeAll(what);
return set.isEmpty() ? ContainerUtil.<T>emptyList() : set;
}
......@@ -2019,7 +2019,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> Set<T> set(@NotNull T ... items) {
return newHashSet(items);
return ContainerUtilRt.newHashSet(items);
}
public static <K, V> void putIfAbsent(final K key, @Nullable V value, @NotNull final Map<? super K, ? super V> result) {
......@@ -2421,7 +2421,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <A,B> Map<B,A> reverseMap(@NotNull Map<A,B> map) {
final Map<B,A> result = newHashMap();
final Map<B,A> result = new HashMap<B, A>();
for (Map.Entry<A, B> entry : map.entrySet()) {
result.put(entry.getValue(), entry.getKey());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment