Skip to content

Commit

Permalink
Add If missing in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed Jul 6, 2022
1 parent b129cc4 commit 08d089b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/Amulet/extensions/java/util/List/XList.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public static <E> E getRandom(@This List<E> self)
return self.getRandom(Random.r());
}

public static <E> void addIfMissing(@This List<E> self, E e)
{
if(!self.contains(e)) {
self.add(e);
}
}

public static <E> @Self List<E> where(@This List<E> self, Predicate<E> pred) {
return self.stream().where(pred).toList();
}
Expand Down

0 comments on commit 08d089b

Please sign in to comment.