Skip to content

Commit

Permalink
Add ListUtils And MapUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Nov 17, 2023
1 parent 06d432f commit 553707f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mmodding.mmodding_lib.library.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class ListUtils {

public static <E> List<E> builder(Consumer<List<E>> consumer) {
List<E> list = new ArrayList<>();
consumer.accept(list);
return list;
}

public static <E1, E2> BiList<E1, E2> biBuilder(Consumer<BiList<E1, E2>> consumer) {
BiList<E1, E2> biList = new BiArrayList<>();
consumer.accept(biList);
return biList;
}

public static <E1, E2, E3> TriList<E1, E2, E3> triBuilder(Consumer<TriList<E1, E2, E3>> consumer) {
TriList<E1, E2, E3> triList = new TriArrayList<>();
consumer.accept(triList);
return triList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mmodding.mmodding_lib.library.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class MapUtils {

public static <K, V> Map<K, V> builder(Consumer<Map<K, V>> consumer) {
Map<K, V> map = new HashMap<>();
consumer.accept(map);
return map;
}

public static <K, V1, V2> BiMap<K, V1, V2> biBuilder(Consumer<BiMap<K, V1, V2>> consumer) {
BiMap<K, V1, V2> biMap = new BiHashMap<>();
consumer.accept(biMap);
return biMap;
}

public static <K, V1, V2, V3> TriMap<K, V1, V2, V3> triBuilder(Consumer<TriMap<K, V1, V2, V3>> consumer) {
TriMap<K, V1, V2, V3> triMap = new TriHashMap<>();
consumer.accept(triMap);
return triMap;
}
}

0 comments on commit 553707f

Please sign in to comment.