Mercurial > hg > openmind
view src/main/java/cl/maps/penta/PentaMap.java @ 127:3e772f7f43e0 default tip
ismi-date with long month names in xml dump.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 11 May 2023 18:15:45 +0200 |
parents | 6e08ff123ae6 |
children |
line wrap: on
line source
package cl.maps.penta; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; public class PentaMap<V, A, B, C, D, E> implements IPentaMap<V, A, B, C, D, E>{ private Map<PentaKey<A, B, C, D, E>, V> map; private Map<A, List<PentaKey<A, B, C, D, E>>> mapAKey; private Map<B, List<PentaKey<A, B, C, D, E>>> mapBKey; private Map<C, List<PentaKey<A, B, C, D, E>>> mapCKey; private Map<D, List<PentaKey<A, B, C, D, E>>> mapDKey; private Map<E, PentaKey<A, B, C, D, E>> mapOwnKey; public PentaMap(){ this.map = new HashMap<PentaKey<A, B, C, D, E>, V>(); this.mapAKey = new HashMap<A, List<PentaKey<A, B, C, D, E>>>(); this.mapBKey = new HashMap<B, List<PentaKey<A, B, C, D, E>>>(); this.mapCKey = new HashMap<C, List<PentaKey<A, B, C, D, E>>>(); this.mapDKey = new HashMap<D, List<PentaKey<A, B, C, D, E>>>(); this.mapOwnKey = new HashMap<E, PentaKey<A, B, C, D, E>>(); } public PentaMap(PentaMap<V, A, B, C, D, E> m) { this.map = new HashMap<PentaKey<A, B, C, D, E>, V>(); this.mapAKey = new HashMap<A, List<PentaKey<A, B, C, D, E>>>(); this.mapBKey = new HashMap<B, List<PentaKey<A, B, C, D, E>>>(); this.mapCKey = new HashMap<C, List<PentaKey<A, B, C, D, E>>>(); this.mapDKey = new HashMap<D, List<PentaKey<A, B, C, D, E>>>(); this.mapOwnKey = new HashMap<E, PentaKey<A, B, C, D, E>>(); this.putAllForCreate(m); } private void putAllForCreate(PentaMap<? extends V, A, B, C, D, E> m) { for(Map.Entry<PentaKey<A, B, C, D, E>, ? extends V> e : m.entrySet()){ PentaKey<A, B, C, D, E> tKey = e.getKey(); this.map.put(tKey, e.getValue()); this.mapOwnKey.put(tKey.getOwnKey(), tKey); if(!mapAKey.containsKey(tKey.getAKey())){ mapAKey.put(tKey.getAKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapAKey.get(tKey.getAKey()).contains(tKey)){ mapAKey.get(tKey.getAKey()).add(tKey); } if(!mapBKey.containsKey(tKey.getBKey())){ mapBKey.put(tKey.getBKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapBKey.get(tKey.getBKey()).contains(tKey)){ mapBKey.get(tKey.getBKey()).add(tKey); } if(!mapCKey.containsKey(tKey.getCKey())){ mapCKey.put(tKey.getCKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapCKey.get(tKey.getCKey()).contains(tKey)){ mapCKey.get(tKey.getCKey()).add(tKey); } if(!mapDKey.containsKey(tKey.getDKey())){ mapDKey.put(tKey.getDKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapDKey.get(tKey.getDKey()).contains(tKey)){ mapDKey.get(tKey.getDKey()).add(tKey); } } } public List<V> getValuesByAKey(A srcKey){ List<V> list = new ArrayList<V>(); if(mapAKey.containsKey(srcKey)){ for(PentaKey<A, B, C, D, E> tKey : mapAKey.get(srcKey)){ list.add(map.get(tKey)); } } return list; } public List<V> getValuesByBKey(B tarKey){ List<V> list = new ArrayList<V>(); if(mapBKey.containsKey(tarKey)){ for(PentaKey<A, B, C, D, E> tKey : mapBKey.get(tarKey)){ list.add(map.get(tKey)); } } return list; } public List<V> getValuesByCKey(C cKey){ List<V> list = new ArrayList<V>(); if(mapCKey.containsKey(cKey)){ for(PentaKey<A, B, C, D, E> tKey : mapCKey.get(cKey)){ list.add(map.get(tKey)); } } return list; } public List<V> getValuesByDKey(D dKey){ List<V> list = new ArrayList<V>(); if(mapDKey.containsKey(dKey)){ for(PentaKey<A, B, C, D, E> tKey : mapDKey.get(dKey)){ list.add(map.get(tKey)); } } return list; } public V getValuesByOwnKey(E ownKey){ PentaKey<A, B, C, D, E> tKey = mapOwnKey.get(ownKey); if(tKey != null){ return this.map.get(tKey); } return null; } public Set<PentaKey<A, B, C, D, E>> keySet(){ return this.map.keySet(); } public Set<Map.Entry<PentaKey<A, B, C, D, E>, V>> entrySet() { return this.map.entrySet(); } @Override public int size() { return this.map.size(); } @Override public boolean isEmpty() { return this.map.isEmpty(); } @Override public boolean containsKey(PentaKey<A, B, C, D, E> key) { return this.map.containsKey(key); } @Override public boolean containsValue(Object value) { return this.map.containsValue(value); } @Override public V get(PentaKey<A, B, C, D, E> key) { return map.get(key); } @Override public V put(PentaKey<A, B, C, D, E> tKey, V value) { if(!mapAKey.containsKey(tKey.getAKey())){ mapAKey.put(tKey.getAKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapAKey.get(tKey.getAKey()).contains(tKey)){ mapAKey.get(tKey.getAKey()).add(tKey); } if(!mapBKey.containsKey(tKey.getBKey())){ mapBKey.put(tKey.getBKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapBKey.get(tKey.getBKey()).contains(tKey)){ mapBKey.get(tKey.getBKey()).add(tKey); } if(!mapCKey.containsKey(tKey.getCKey())){ mapCKey.put(tKey.getCKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapCKey.get(tKey.getCKey()).contains(tKey)){ mapCKey.get(tKey.getCKey()).add(tKey); } if(!mapDKey.containsKey(tKey.getDKey())){ mapDKey.put(tKey.getDKey(), new ArrayList<PentaKey<A, B, C, D, E>>()); } if(!mapDKey.get(tKey.getDKey()).contains(tKey)){ mapDKey.get(tKey.getDKey()).add(tKey); } this.mapOwnKey.put(tKey.getOwnKey(), tKey); return this.map.put(tKey, value); } @Override public V remove(PentaKey<A, B, C, D, E> key) { if(mapAKey.containsKey(key.getAKey())){ mapAKey.get(key.getAKey()).remove(key); } if(mapBKey.containsKey(key.getBKey())){ mapBKey.get(key.getBKey()).remove(key); } if(mapCKey.containsKey(key.getCKey())){ mapCKey.get(key.getCKey()).remove(key); } if(mapDKey.containsKey(key.getDKey())){ mapDKey.get(key.getDKey()).remove(key); } this.mapOwnKey.remove(key.getOwnKey()); return this.map.remove(key); } @Override public void clear() { this.map.clear(); this.mapAKey.clear(); this.mapBKey.clear(); this.mapCKey.clear(); this.mapDKey.clear(); this.mapOwnKey.clear(); } @Override public Collection<V> values() { return this.map.values(); } }