add:策略管理,单据管理

This commit is contained in:
2025-06-25 21:56:44 +08:00
parent cc3376f60d
commit 638b8a109b
17 changed files with 2271 additions and 1 deletions

View File

@@ -0,0 +1,90 @@
package org.nl.common.utils;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/*
* @author ZZQ
* @Date 2022/11/29 2:55 下午
* 三叉Map
*/
public class ForkMap<L,M,R> implements Serializable {
transient Map<Integer,Node> items=new HashMap<>();
transient Set<L> keySet = new HashSet<>();
public <M> M getM(L key){
Node<L,M,R> node = items.get(hash(key));
if (node==null){
return null;
}
return node.middle;
}
public <L> L getNode(M desc){
for (Node<L,M,R> value : items.values()) {
if (value.middle.equals(desc)){
return value.left;
}
}
return null;
}
public <R> R getR(L key){
Node<L,M,R> node = items.get(hash(key));
if (node==null){
return null;
}
return node.right;
}
public Set<L> getKeySet(){
return keySet;
}
public static <L,M,R> ForkMap pushAll(ForkMap... maps){
ForkMap<L,M,R> forkMap = new ForkMap();
for (ForkMap<L,M,R> map : maps) {
for (L key : map.getKeySet()) {
L key1 = key;
M m = map.getM(key1);
R r = map.getR(key1);
forkMap.put(key1, m, r);
}
}
return forkMap;
}
public static <V> ForkMap of(V...keys){
ForkMap<V,V,V> map = new ForkMap<V,V,V>();
for (int i = 0; i < keys.length/3; i++) {
map.put(keys[i*3+1],keys[i*3],keys[i*3+2]);
}
return map;
}
public ForkMap put(L key, M middle,R right) {
Node node = new Node(key, middle, right);
items.put(hash(key),node);
keySet.add(key);
return this;
}
static class Node<L,M,R>{
private L left;
private M middle;
private R right;
Node(L left, M middle, R right) {
this.left = left;
this.middle = middle;
this.right = right;
}
}
static final int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
}