mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-25 14:24:23 +00:00
feat: more data storage and side separation
This commit is contained in:
1 parent
90f768ed21
commit
ae0d3869cb
24 files changed
+502
-244
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package me.towdium.jecalculation.utils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
@@ -15,6 +16,7 @@ import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
@@ -239,4 +241,57 @@ public class Utilities {
|
||||
return (List<T>) data.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Immutable non-duplicated list builder
|
||||
*/
|
||||
public static class INDListBuilder<T> {
|
||||
public ImmutableList.Builder<T> builder = ImmutableList.builder();
|
||||
public HashSet<T> set = new HashSet<>();
|
||||
|
||||
public void add(T obj) {
|
||||
if (set.add(obj)) builder.add(obj);
|
||||
}
|
||||
|
||||
public ImmutableList<T> build() {
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class OrderedHashMap<K, V> {
|
||||
public HashMap<K, Integer> index = new HashMap<>();
|
||||
public List<Pair<K, V>> value = new ArrayList<>();
|
||||
|
||||
public void put(K key, V value) {
|
||||
if (index.containsKey(key)) this.value.set(index.get(key), new Pair<>(key, value));
|
||||
else {
|
||||
index.put(key, this.value.size());
|
||||
this.value.add(new Pair<>(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<V> get(int index) {
|
||||
Pair<K, V> p = value.get(index);
|
||||
return Optional.ofNullable(p == null ? null : p.two);
|
||||
}
|
||||
|
||||
public Optional<V> get(K key) {
|
||||
Integer i = index.get(key);
|
||||
return Optional.ofNullable(i == null ? null : value.get(i).two);
|
||||
}
|
||||
|
||||
public int getIndex(K key) {
|
||||
Integer ret = index.get(key);
|
||||
return ret == null ? -1 : ret;
|
||||
}
|
||||
|
||||
public Optional<K> getKey(int index) {
|
||||
Pair<K, V> ret = value.get(index);
|
||||
return Optional.ofNullable(ret == null ? null : ret.one);
|
||||
}
|
||||
|
||||
public void forEach(BiConsumer<K, V> func) {
|
||||
value.forEach(p -> func.accept(p.one, p.two));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user