Skip to content

Commit

Permalink
added npe protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Orbiter committed Sep 1, 2023
1 parent 8285fe7 commit 0089f23
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/net/yacy/kelondro/util/SetTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ private static <A, B> SortedMap<A, B> joinConstructiveByTest(final SortedMap<A,
@SuppressWarnings("unchecked")
private static <A, B> SortedMap<A, B> joinConstructiveByEnumeration(final SortedMap<A, B> map1, final SortedMap<A, B> map2, final boolean concatStrings) {
// implement pairwise enumeration
final Comparator<? super A> comp = map1.comparator();
final Comparator<? super A> comp = map1.comparator() == null ? (Comparator<? super A>) Comparator.naturalOrder() : map1.comparator();
final Iterator<Map.Entry<A, B>> mi1 = map1.entrySet().iterator();
final Iterator<Map.Entry<A, B>> mi2 = map2.entrySet().iterator();
final SortedMap<A, B> result = new TreeMap<A, B>(map1.comparator());
final SortedMap<A, B> result = new TreeMap<A, B>(comp);
int c;
if ((mi1.hasNext()) && (mi2.hasNext())) {
Map.Entry<A, B> mentry1 = mi1.next();
Expand Down Expand Up @@ -263,6 +263,8 @@ private static <A> SortedSet<A> joinConstructiveByEnumeration(final SortedSet<A>
* @return true if the small set is completely included in the large set
*/
public static <A> boolean totalInclusion(final Iterator<A> small, final Set<A> large) {
if (small == null) return true;
if (large == null) return false;
while (small.hasNext()) {
if (!large.contains(small.next())) return false;
}
Expand All @@ -276,6 +278,8 @@ public static <A> boolean totalInclusion(final Iterator<A> small, final Set<A> l
* @return true if the small set is completely included in the large set
*/
public static boolean totalInclusion(final HandleSet small, final HandleSet large) {
if (small == null) return true;
if (large == null) return false;
for (byte[] handle: small) {
if (!large.has(handle)) return false;
}
Expand Down

0 comments on commit 0089f23

Please sign in to comment.