|
2 | 2 |
|
3 | 3 | import dev.mv.utilsx.check.Match; |
4 | 4 | import dev.mv.utilsx.check.MatchReturn; |
| 5 | +import dev.mv.utilsx.collection.Vec; |
5 | 6 | import dev.mv.utilsx.generic.Option; |
6 | 7 | import dev.mv.utilsx.misc.ClassFinder; |
7 | 8 | import dev.mv.utilsx.nullHandler.NullHandler; |
@@ -225,6 +226,20 @@ public static <T> List<T> merge(List<T>... lists) { |
225 | 226 | return mergedList; |
226 | 227 | } |
227 | 228 |
|
| 229 | + /** |
| 230 | + * Merge multiple vecs into one vec, returns the merged vec as an {@link Vec}. |
| 231 | + * |
| 232 | + * @param vecs The vecs to be merged. |
| 233 | + * @return {@link Vec} instance with all the merged vecs. |
| 234 | + */ |
| 235 | + public static <T> Vec<T> merge(Vec<T>... vecs) { |
| 236 | + Vec<T> mergedVec = new Vec<>(); |
| 237 | + for (Vec<T> vec : vecs) { |
| 238 | + mergedVec.append(vec); |
| 239 | + } |
| 240 | + return mergedVec; |
| 241 | + } |
| 242 | + |
228 | 243 | /** |
229 | 244 | * Creates a null check instance on the object, allowing you to execute certain |
230 | 245 | * code only if the object is null and other code only if it is not null. |
@@ -391,9 +406,9 @@ public static <T> T[] repeat(T t, int times) { |
391 | 406 | * Get all the classes in the current JVM classPath with a filter on the full name of the class. |
392 | 407 | * |
393 | 408 | * @param filter the filter, true to add the class, false to not add. |
394 | | - * @return a {@link List} with all the classes as {@link Class<?>} objects. |
| 409 | + * @return a {@link Vec} with all the classes as {@link Class<?>} objects. |
395 | 410 | */ |
396 | | - public static List<Class<?>> getAllClasses(Predicate<String> filter) { |
| 411 | + public static Vec<Class<?>> getAllClasses(Predicate<String> filter) { |
397 | 412 | try { |
398 | 413 | ClassLoader loader = ClassLoader.getSystemClassLoader(); |
399 | 414 | return ClassFinder.findAllClasses().filter(filter).filterMap(name -> { |
@@ -488,6 +503,16 @@ public static <T> T random(List<T> list) { |
488 | 503 | return list.get(random.nextInt(list.size())); |
489 | 504 | } |
490 | 505 |
|
| 506 | + /** |
| 507 | + * Returns a random element from the given vec. |
| 508 | + * |
| 509 | + * @param vec The vec to get a random element from. |
| 510 | + * @return A random element from the vec. |
| 511 | + */ |
| 512 | + public static <T> T random(Vec<T> vec) { |
| 513 | + return vec.get(random.nextInt(vec.len())); |
| 514 | + } |
| 515 | + |
491 | 516 | /** |
492 | 517 | * Returns a random element from the given array. |
493 | 518 | * |
|
0 commit comments