6123 |
09 Feb 21 |
nicklas |
1 |
package net.sf.basedb.varsearch.util; |
6123 |
09 Feb 21 |
nicklas |
2 |
|
6123 |
09 Feb 21 |
nicklas |
3 |
import java.util.Collection; |
6123 |
09 Feb 21 |
nicklas |
4 |
import java.util.TreeSet; |
6123 |
09 Feb 21 |
nicklas |
5 |
|
6123 |
09 Feb 21 |
nicklas |
6 |
|
6123 |
09 Feb 21 |
nicklas |
7 |
/** |
6123 |
09 Feb 21 |
nicklas |
Variant of a TreeSet that simply ignore null values instead of |
6123 |
09 Feb 21 |
nicklas |
throwing an exception. |
6123 |
09 Feb 21 |
nicklas |
@author nicklas |
6123 |
09 Feb 21 |
nicklas |
11 |
*/ |
6123 |
09 Feb 21 |
nicklas |
12 |
public class NullSafeTreeSet<E> |
6123 |
09 Feb 21 |
nicklas |
13 |
extends TreeSet<E> |
6123 |
09 Feb 21 |
nicklas |
14 |
{ |
6123 |
09 Feb 21 |
nicklas |
15 |
|
6123 |
09 Feb 21 |
nicklas |
16 |
private static final long serialVersionUID = 3606992818619812054L; |
6123 |
09 Feb 21 |
nicklas |
17 |
|
6123 |
09 Feb 21 |
nicklas |
18 |
@Override |
6123 |
09 Feb 21 |
nicklas |
19 |
public boolean add(E e) |
6123 |
09 Feb 21 |
nicklas |
20 |
{ |
6123 |
09 Feb 21 |
nicklas |
21 |
return e == null ? false : super.add(e); |
6123 |
09 Feb 21 |
nicklas |
22 |
} |
6123 |
09 Feb 21 |
nicklas |
23 |
|
6123 |
09 Feb 21 |
nicklas |
24 |
@Override |
6123 |
09 Feb 21 |
nicklas |
25 |
public boolean addAll(Collection<? extends E> c) |
6123 |
09 Feb 21 |
nicklas |
26 |
{ |
6123 |
09 Feb 21 |
nicklas |
27 |
if (c == null || c.isEmpty()) return false; |
6123 |
09 Feb 21 |
nicklas |
28 |
boolean modified = false; |
6123 |
09 Feb 21 |
nicklas |
29 |
for (E e : c) |
6123 |
09 Feb 21 |
nicklas |
30 |
{ |
6123 |
09 Feb 21 |
nicklas |
31 |
if (add(e)) modified = true; |
6123 |
09 Feb 21 |
nicklas |
32 |
} |
6123 |
09 Feb 21 |
nicklas |
33 |
return modified; |
6123 |
09 Feb 21 |
nicklas |
34 |
} |
6123 |
09 Feb 21 |
nicklas |
35 |
|
6123 |
09 Feb 21 |
nicklas |
36 |
} |