Mercurial > hg > openmind
view src/main/java/cl/maps/quad/QuadMap.java @ 85:1aff84e5048d
configuration option for queryBrowserUrl.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 20 Oct 2017 12:48:31 +0200 |
parents | 6e08ff123ae6 |
children |
line wrap: on
line source
package cl.maps.quad; 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 QuadMap<V, A, B, C, D> implements IQuadMap<V, A, B, C, D>{ private Map<QuadKey<A, B, C, D>, V> map; private Map<A, List<QuadKey<A, B, C, D>>> mapAKey; private Map<B, List<QuadKey<A, B, C, D>>> mapBKey; private Map<C, List<QuadKey<A, B, C, D>>> mapCKey; private Map<D, QuadKey<A, B, C, D>> mapOwnKey; public QuadMap(){ this.map = new HashMap<QuadKey<A, B, C, D>, V>(); this.mapAKey = new HashMap<A, List<QuadKey<A, B, C, D>>>(); this.mapBKey = new HashMap<B, List<QuadKey<A, B, C, D>>>(); this.mapCKey = new HashMap<C, List<QuadKey<A, B, C, D>>>(); this.mapOwnKey = new HashMap<D, QuadKey<A, B, C, D>>(); } public QuadMap(QuadMap<? extends V, A, B, C, D> m) { this.map = new HashMap<QuadKey<A, B, C, D>, V>(); this.mapAKey = new HashMap<A, List<QuadKey<A, B, C, D>>>(); this.mapBKey = new HashMap<B, List<QuadKey<A, B, C, D>>>(); this.mapCKey = new HashMap<C, List<QuadKey<A, B, C, D>>>(); this.mapOwnKey = new HashMap<D, QuadKey<A, B, C, D>>(); this.putAllForCreate(m); } private void putAllForCreate(QuadMap<? extends V, A, B, C, D> m) { for(Map.Entry<QuadKey<A, B, C, D>, ? extends V> e : m.entrySet()){ QuadKey<A, B, C, D> 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<QuadKey<A, B, C, D>>()); } if(!mapAKey.get(tKey.getAKey()).contains(tKey)){ mapAKey.get(tKey.getAKey()).add(tKey); } if(!mapBKey.containsKey(tKey.getBKey())){ mapBKey.put(tKey.getBKey(), new ArrayList<QuadKey<A, B, C, D>>()); } if(!mapBKey.get(tKey.getBKey()).contains(tKey)){ mapBKey.get(tKey.getBKey()).add(tKey); } if(!mapCKey.containsKey(tKey.getCKey())){ mapCKey.put(tKey.getCKey(), new ArrayList<QuadKey<A, B, C, D>>()); } if(!mapCKey.get(tKey.getCKey()).contains(tKey)){ mapCKey.get(tKey.getCKey()).add(tKey); } } } public List<V> getValuesByAKey(A srcKey){ List<V> list = new ArrayList<V>(); if(mapAKey.containsKey(srcKey)){ for(QuadKey<A, B, C, D> 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(QuadKey<A, B, C, D> 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(QuadKey<A, B, C, D> tKey : mapCKey.get(cKey)){ list.add(map.get(tKey)); } } return list; } public V getValuesByOwnKey(D ownKey){ QuadKey<A, B, C, D> tKey = mapOwnKey.get(ownKey); if(tKey != null){ return this.map.get(tKey); } return null; } public Set<QuadKey<A, B, C, D>> keySet(){ return this.map.keySet(); } public Set<Map.Entry<QuadKey<A, B, C, D>, 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(QuadKey<A, B, C, D> key) { return this.map.containsKey(key); } @Override public boolean containsValue(Object value) { return this.map.containsValue(value); } @Override public V get(QuadKey<A, B, C, D> key) { return map.get(key); } @Override public V put(QuadKey<A, B, C, D> tKey, V value) { if(!mapAKey.containsKey(tKey.getAKey())){ mapAKey.put(tKey.getAKey(), new ArrayList<QuadKey<A, B, C, D>>()); } if(!mapAKey.get(tKey.getAKey()).contains(tKey)){ mapAKey.get(tKey.getAKey()).add(tKey); } if(!mapBKey.containsKey(tKey.getBKey())){ mapBKey.put(tKey.getBKey(), new ArrayList<QuadKey<A, B, C, D>>()); } if(!mapBKey.get(tKey.getBKey()).contains(tKey)){ mapBKey.get(tKey.getBKey()).add(tKey); } if(!mapCKey.containsKey(tKey.getCKey())){ mapCKey.put(tKey.getCKey(), new ArrayList<QuadKey<A, B, C, D>>()); } if(!mapCKey.get(tKey.getCKey()).contains(tKey)){ mapCKey.get(tKey.getCKey()).add(tKey); } this.mapOwnKey.put(tKey.getOwnKey(), tKey); return this.map.put(tKey, value); } @Override public V remove(QuadKey<A, B, C, D> 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); } 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.mapOwnKey.clear(); } @Override public Collection<V> values() { return this.map.values(); } }