notnull, cleanup

This commit is contained in:
Alexey Kudravtsev
2018-11-09 17:16:07 +03:00
parent d09552ce88
commit 3d0c65bd23
4 changed files with 27 additions and 31 deletions
@@ -63,7 +63,8 @@ public class JavaSharedImplUtil {
List<PsiAnnotation[]> annotations = ContainerUtil.newSmartList();
List<PsiAnnotation> current = null;
boolean found = (stopAt == null), stop = false;
boolean found = stopAt == null;
boolean stop = false;
for (PsiElement child = anchor.getNextSibling(); child != null; child = child.getNextSibling()) {
if (child instanceof PsiComment || child instanceof PsiWhiteSpace) continue;
@@ -75,7 +76,7 @@ public class JavaSharedImplUtil {
}
if (PsiUtil.isJavaToken(child, JavaTokenType.LBRACKET)) {
annotations.add(ContainerUtil.toArray(current, PsiAnnotation.ARRAY_FACTORY));
annotations.add(current == null ? PsiAnnotation.EMPTY_ARRAY : ContainerUtil.toArray(current, PsiAnnotation.ARRAY_FACTORY));
current = null;
if (stop) return annotations;
}
@@ -27,6 +27,7 @@ public class JsonPointerUtil {
return "#".equals(ref) || "#/".equals(ref) || StringUtil.isEmpty(ref);
}
@NotNull
public static List<String> split(@NotNull String pointer) {
return StringUtil.split(pointer, "/", true, false);
}
@@ -135,7 +135,7 @@ public class ContainerUtilRt {
@NotNull
@Contract(value = "_ -> new", pure = true)
public static <T> ArrayList<T> newArrayList(@NotNull T... elements) {
ArrayList<T> list = newArrayListWithCapacity(elements.length);
ArrayList<T> list = new ArrayList<T>(elements.length);
Collections.addAll(list, elements);
return list;
}
@@ -144,10 +144,11 @@ public class ContainerUtilRt {
@Contract(value = "_ -> new", pure = true)
public static <T> ArrayList<T> newArrayList(@NotNull Iterable<? extends T> elements) {
if (elements instanceof Collection) {
@SuppressWarnings("unchecked") Collection<? extends T> collection = (Collection<? extends T>)elements;
@SuppressWarnings("unchecked")
Collection<? extends T> collection = (Collection<? extends T>)elements;
return new ArrayList<T>(collection);
}
return copy(ContainerUtilRt.<T>newArrayList(), elements);
return copy(new ArrayList<T>(), elements);
}
@NotNull
@@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass"})
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
public class ContainerUtil extends ContainerUtilRt {
private static final int INSERTION_SORT_THRESHOLD = 10;
@@ -146,7 +146,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> ArrayList<T> newArrayList() {
return ContainerUtilRt.newArrayList();
return new ArrayList<T>();
}
@NotNull
@@ -164,7 +164,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> ArrayList<T> newArrayListWithCapacity(int size) {
return ContainerUtilRt.newArrayListWithCapacity(size);
return new ArrayList<T>(size);
}
@NotNull
@@ -197,12 +197,10 @@ public class ContainerUtil extends ContainerUtilRt {
if (size == 0) {
return emptyList();
}
else if (size == 1) {
if (size == 1) {
return Collections.singletonList(originalList.get(0));
}
else {
return Collections.unmodifiableList(newArrayList(originalList));
}
return Collections.unmodifiableList(new ArrayList<T>(originalList));
}
@NotNull
@@ -215,9 +213,7 @@ public class ContainerUtil extends ContainerUtilRt {
if (size == 1) {
return Collections.singletonList(original.iterator().next());
}
else {
return Collections.unmodifiableCollection(original);
}
return Collections.unmodifiableCollection(original);
}
@NotNull
@@ -230,9 +226,7 @@ public class ContainerUtil extends ContainerUtilRt {
if (size == 1) {
return Collections.singletonList(original.iterator().next());
}
else {
return Collections.unmodifiableList(original);
}
return Collections.unmodifiableList(original);
}
@NotNull
@@ -245,9 +239,7 @@ public class ContainerUtil extends ContainerUtilRt {
if (size == 1) {
return Collections.singleton(original.iterator().next());
}
else {
return Collections.unmodifiableSet(original);
}
return Collections.unmodifiableSet(original);
}
@NotNull
@@ -475,7 +467,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> Set<T> union(@NotNull Set<? extends T> set, @NotNull Set<? extends T> set2) {
return union((Collection<T>)set, set2);
return union((Collection<? extends T>)set, set2);
}
@NotNull
@@ -537,7 +529,8 @@ public class ContainerUtil extends ContainerUtilRt {
}
if (!result.isEmpty() && result.keySet().iterator().next() instanceof Comparable) {
return new KeyOrderedMultiMap<K, V>(result);
//noinspection unchecked
return new KeyOrderedMultiMap(result);
}
return result;
}
@@ -1416,7 +1409,7 @@ public class ContainerUtil extends ContainerUtilRt {
};
}
@SuppressWarnings({"unchecked"})
@SuppressWarnings("unchecked")
@NotNull
@Contract(pure=true)
public static <T> Iterable<T> concat(@NotNull final Iterable<? extends T>... iterables) {
@@ -1725,8 +1718,9 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> T[] toArray(@Nullable Collection<T> c, @NotNull ArrayFactory<? extends T> factory) {
return c != null ? c.toArray(factory.create(c.size())) : factory.create(0);
public static <T> T[] toArray(@NotNull Collection<T> c, @NotNull ArrayFactory<? extends T> factory) {
T[] a = factory.create(c.size());
return c.toArray(a);
}
@NotNull
@@ -1837,7 +1831,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> List<T> sorted(@NotNull Collection<? extends T> list, @NotNull Comparator<? super T> comparator) {
return sorted((Iterable<T>)list, comparator);
return sorted((Iterable<? extends T>)list, comparator);
}
@NotNull
@@ -2758,6 +2752,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
@Contract(pure=true)
public static <T> Collection<T> toCollection(@NotNull Iterable<? extends T> iterable) {
//noinspection unchecked
return iterable instanceof Collection ? (Collection<T>)iterable : newArrayList(iterable);
}
@@ -2853,8 +2848,7 @@ public class ContainerUtil extends ContainerUtilRt {
return sb.toString();
}
public static class KeyOrderedMultiMap<K, V> extends MultiMap<K, V> {
public static class KeyOrderedMultiMap<K extends Comparable<K>, V> extends MultiMap<K, V> {
public KeyOrderedMultiMap() {
}
@@ -2876,8 +2870,7 @@ public class ContainerUtil extends ContainerUtilRt {
@NotNull
public NavigableSet<K> navigableKeySet() {
//noinspection unchecked
return ((TreeMap)myMap).navigableKeySet();
return ((TreeMap<K, Collection<V>>)myMap).navigableKeySet();
}
}