-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance BiList, BiMap, BiArrayList, BiHashMap
Add TriList, TriMap, TriArrayList, TriHashMap Add QuadConsumer Default Features uses now BiList instead of List<Pair>
- Loading branch information
1 parent
89f5b01
commit c19aa0e
Showing
18 changed files
with
297 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/mmodding/mmodding_lib/library/utils/QuadConsumer.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,6 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
public interface QuadConsumer<K, V, S, T> { | ||
|
||
void accept(K k, V v, S s, T t); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/com/mmodding/mmodding_lib/library/utils/TriArrayList.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,79 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import org.apache.commons.lang3.tuple.ImmutableTriple; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
import org.apache.logging.log4j.util.TriConsumer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.function.Consumer; | ||
|
||
public class TriArrayList<E1, E2, E3> extends ArrayList<Triple<E1, E2, E3>> implements TriList<E1, E2, E3> { | ||
|
||
public TriArrayList(int initialCapacity) { | ||
super(initialCapacity); | ||
} | ||
|
||
public TriArrayList() { | ||
super(); | ||
} | ||
|
||
public TriArrayList(@NotNull TriList<E1, E2, E3> c) { | ||
super(c); | ||
} | ||
|
||
@Override | ||
public boolean contains(E1 first, E2 second, E3 third) { | ||
return this.contains(new ImmutableTriple<>(first, second, third)); | ||
} | ||
|
||
@Override | ||
public E1 getFirst(int index) { | ||
return this.get(index).getLeft(); | ||
} | ||
|
||
@Override | ||
public E2 getSecond(int index) { | ||
return this.get(index).getMiddle(); | ||
} | ||
|
||
@Override | ||
public E3 getThird(int index) { | ||
return this.get(index).getRight(); | ||
} | ||
|
||
@Override | ||
public boolean add(E1 first, E2 second, E3 third) { | ||
return this.add(new ImmutableTriple<>(first, second, third)); | ||
} | ||
|
||
@Override | ||
public boolean remove(E1 first, E2 second, E3 third) { | ||
return this.remove(new ImmutableTriple<>(first, second, third)); | ||
} | ||
|
||
@Override | ||
public Triple<E1, E2, E3> set(int index, E1 first, E2 second, E3 third) { | ||
return this.set(index, new ImmutableTriple<>(first, second, third)); | ||
} | ||
|
||
@Override | ||
public void forEachFirst(Consumer<? super E1> action) { | ||
this.forEach(value -> action.accept(value.getLeft())); | ||
} | ||
|
||
@Override | ||
public void forEachSecond(Consumer<? super E2> action) { | ||
this.forEach(value -> action.accept(value.getMiddle())); | ||
} | ||
|
||
@Override | ||
public void forEachThird(Consumer<? super E3> action) { | ||
this.forEach(value -> action.accept(value.getRight())); | ||
} | ||
|
||
@Override | ||
public void forEach(TriConsumer<? super E1, ? super E2, ? super E3> action) { | ||
this.forEach(value -> action.accept(value.getLeft(), value.getMiddle(), value.getRight())); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/com/mmodding/mmodding_lib/library/utils/TriHashMap.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,64 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import org.apache.commons.lang3.tuple.ImmutableTriple; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.BiConsumer; | ||
|
||
public class TriHashMap<K, V1, V2, V3> extends HashMap<K, Triple<V1, V2, V3>> implements TriMap<K, V1, V2, V3> { | ||
|
||
public TriHashMap(int initialCapacity, float loadFactor) { | ||
super(initialCapacity, loadFactor); | ||
} | ||
|
||
public TriHashMap(int initialCapacity) { | ||
super(initialCapacity); | ||
} | ||
|
||
public TriHashMap() { | ||
super(); | ||
} | ||
|
||
public TriHashMap(TriMap<? extends K, V1, V2, V3> m) { | ||
super(m); | ||
} | ||
|
||
|
||
@Override | ||
public boolean containsValue(V1 firstValue, V2 secondValue, V3 thirdValue) { | ||
return this.containsValue(new ImmutableTriple<>(firstValue, secondValue, thirdValue)); | ||
} | ||
|
||
public V1 getFirstValue(K key) { | ||
return this.getOrDefault(key, TriMap.emptyValue()).getLeft(); | ||
} | ||
|
||
public V2 getSecondValue(K key) { | ||
return this.getOrDefault(key, TriMap.emptyValue()).getMiddle(); | ||
} | ||
|
||
public V3 getThirdValue(K key) { | ||
return this.getOrDefault(key, TriMap.emptyValue()).getRight(); | ||
} | ||
|
||
public Triple<V1, V2, V3> put(K key, V1 firstValue, V2 secondValue, V3 thirdValue) { | ||
return this.put(key, new ImmutableTriple<>(firstValue, secondValue, thirdValue)); | ||
} | ||
|
||
public void forEachFirst(BiConsumer<? super K, ? super V1> action) { | ||
this.forEach((key, value) -> action.accept(key, value.getLeft())); | ||
} | ||
|
||
public void forEachSecond(BiConsumer<? super K, ? super V2> action) { | ||
this.forEach((key, value) -> action.accept(key, value.getMiddle())); | ||
} | ||
|
||
public void forEachThird(BiConsumer<? super K, ? super V3> action) { | ||
this.forEach((key, value) -> action.accept(key, value.getRight())); | ||
} | ||
|
||
public void forEach(QuadConsumer<? super K, ? super V1, ? super V2, ? super V3> action) { | ||
this.forEach((key, value) -> action.accept(key, value.getLeft(), value.getMiddle(), value.getRight())); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/mmodding/mmodding_lib/library/utils/TriList.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,43 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import org.apache.commons.lang3.tuple.ImmutableTriple; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
import org.apache.logging.log4j.util.TriConsumer; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public interface TriList<E1, E2, E3> extends List<Triple<E1, E2, E3>> { | ||
|
||
static <E> boolean contains(TriList<E, E, E> triList, E first, E second, E third) { | ||
return (triList.contains(first, second, third) || triList.contains(first, third, second)) | ||
|| (triList.contains(second, first, third) || triList.contains(second, third, first)) | ||
|| (triList.contains(third, first, second) || triList.contains(third, second, first)); | ||
} | ||
|
||
static <E1, E2, E3> Triple<E1, E2, E3> emptyValue() { | ||
return new ImmutableTriple<>(null, null, null); | ||
} | ||
|
||
boolean contains(E1 first, E2 second, E3 third); | ||
|
||
E1 getFirst(int index); | ||
|
||
E2 getSecond(int index); | ||
|
||
E3 getThird(int index); | ||
|
||
boolean add(E1 first, E2 second, E3 third); | ||
|
||
boolean remove(E1 first, E2 second, E3 third); | ||
|
||
Triple<E1, E2, E3> set(int index, E1 first, E2 second, E3 third); | ||
|
||
void forEachFirst(Consumer<? super E1> action); | ||
|
||
void forEachSecond(Consumer<? super E2> action); | ||
|
||
void forEachThird(Consumer<? super E3> action); | ||
|
||
void forEach(TriConsumer<? super E1, ? super E2, ? super E3> action); | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/mmodding/mmodding_lib/library/utils/TriMap.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,38 @@ | ||
package com.mmodding.mmodding_lib.library.utils; | ||
|
||
import org.apache.commons.lang3.tuple.ImmutableTriple; | ||
import org.apache.commons.lang3.tuple.Triple; | ||
|
||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
|
||
public interface TriMap<K, V1, V2, V3> extends Map<K, Triple<V1, V2, V3>> { | ||
|
||
static <K, V> boolean contains(TriMap<K, V, V, V> triMap, V firstValue, V secondValue, V thirdValue) { | ||
return (triMap.containsValue(firstValue, secondValue, thirdValue) || triMap.containsValue(firstValue, thirdValue, secondValue)) | ||
|| (triMap.containsValue(secondValue, firstValue, thirdValue) || triMap.containsValue(secondValue, thirdValue, firstValue)) | ||
|| (triMap.containsValue(thirdValue, firstValue, secondValue) || triMap.containsValue(thirdValue, secondValue, firstValue)); | ||
} | ||
|
||
static <V1, V2, V3> Triple<V1, V2, V3> emptyValue() { | ||
return new ImmutableTriple<>(null, null, null); | ||
} | ||
|
||
boolean containsValue(V1 firstValue, V2 secondValue, V3 thirdValue); | ||
|
||
V1 getFirstValue(K key); | ||
|
||
V2 getSecondValue(K key); | ||
|
||
V3 getThirdValue(K key); | ||
|
||
Triple<V1, V2, V3> put(K key, V1 firstValue, V2 secondValue, V3 thirdValue); | ||
|
||
void forEachFirst(BiConsumer<? super K, ? super V1> action); | ||
|
||
void forEachSecond(BiConsumer<? super K, ? super V2> action); | ||
|
||
void forEachThird(BiConsumer<? super K, ? super V3> action); | ||
|
||
void forEach(QuadConsumer<? super K, ? super V1, ? super V2, ? super V3> action); | ||
} |
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
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
Oops, something went wrong.