NoSuchElementException

This commit is contained in:
Alexey Kudravtsev
2012-09-14 16:19:55 +04:00
parent 10c6ec2b84
commit 9458992e79
2 changed files with 35 additions and 3 deletions
@@ -3834,11 +3834,11 @@ public class AbstractTreeUi {
}
}
Set<Object> toSelect = new THashSet<Object>();
clearSelection();
ContainerUtil.addAll(toSelect, elements);
Set<Object> toSelect = new THashSet<Object>();
ContainerUtil.addAllNotNull(toSelect, elements);
if (addToSelection) {
toSelect.addAll(currentElements);
ContainerUtil.addAllNotNull(toSelect, currentElements);
}
if (checkIfInStructure) {
@@ -467,6 +467,25 @@ public class ContainerUtil extends ContainerUtilRt {
}
}
/**
* Adds all not-null elements from the {@code elements}, ignoring nulls
*/
public static <T> void addAllNotNull(@NotNull Collection<T> collection, @NotNull Iterable<? extends T> elements) {
addAll(collection, elements.iterator());
}
/**
* Adds all not-null elements from the {@code elements}, ignoring nulls
*/
public static <T> void addAllNotNull(@NotNull Collection<T> collection, @NotNull Iterator<? extends T> elements) {
while (elements.hasNext()) {
T o = elements.next();
if (o != null) {
collection.add(o);
}
}
}
@NotNull
public static <T> List<T> collect(@NotNull Iterator<T> iterator) {
if (!iterator.hasNext()) return Collections.emptyList();
@@ -859,6 +878,19 @@ public class ContainerUtil extends ContainerUtilRt {
return collection;
}
/**
* Adds all not-null elements from the {@code elements}, ignoring nulls
*/
public static <T, A extends T, C extends Collection<T>> C addAllNotNull(@NotNull C collection, @NotNull A... elements) {
//noinspection ManualArrayToCollectionCopy
for (T element : elements) {
if (element != null) {
collection.add(element);
}
}
return collection;
}
public static <T, U extends T> U findInstance(@NotNull Iterable<T> iterable, @NotNull Class<U> aClass) {
return findInstance(iterable.iterator(), aClass);
}