Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/main/java/org/auioc/mcmod/arnicalib/base/collection/ListUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.auioc.mcmod.arnicalib.base.collection; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import org.apache.commons.lang3.Validate; | ||
|
||
public class ListUtils { | ||
|
||
public static <T> T getLast(List<T> list) { | ||
Validate.notEmpty(list); | ||
return list.get(list.size() - 1); | ||
} | ||
|
||
public static <T> int indexOf(List<T> list, Predicate<T> predicate) { | ||
for (int i = 0, l = list.size(); i < l; ++i) { | ||
if (predicate.test(list.get(i))) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public static <T> int lastIndexOf(List<T> list, Predicate<T> predicate) { | ||
for (int i = list.size() - 1; i >= 0; --i) { | ||
if (predicate.test(list.get(i))) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
} |