# HG changeset patch
# User casties
# Date 1481726980 -3600
# Node ID 6e08ff123ae63af9a4614f410bcbd38f9e7ef676
# Parent 153a0232270b1420b4f3d92876ed4662e8e5cc28
check in complete source of cl.maps.
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/duplex/DuplexKey.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/duplex/DuplexKey.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,81 @@
+package cl.maps.duplex;
+
+
+public class DuplexKey {
+
+ private A aKey;
+ private B ownKey;
+
+ public DuplexKey(A aKey, B ownKey){
+ this.aKey = aKey;
+ this.ownKey = ownKey;
+ }
+
+ public boolean equalsAKey(A key){
+ if(aKey != null && key != null){
+ return aKey.equals(key);
+ }else if(aKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsOwnKey(B key){
+ if(ownKey != null && key != null){
+ return ownKey.equals(key);
+ }else if(ownKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public A getAKey() {
+ return aKey;
+ }
+
+ public void setAKey(A aKey) {
+ this.aKey = aKey;
+ }
+
+ public B getOwnKey() {
+ return ownKey;
+ }
+
+ public void setOwnKey(B ownKey) {
+ this.ownKey = ownKey;
+ }
+
+ @Override
+ public boolean equals(Object o){
+ if(o instanceof DuplexKey){
+ try {
+ DuplexKey other = (DuplexKey)o;
+
+ if(this.equalsOwnKey(other.getOwnKey()) &&
+ this.equalsAKey(other.getAKey())){
+ return true;
+ }
+ } catch (Exception e) {}
+
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((aKey == null) ? 0 : aKey.hashCode());
+ result = prime * result + ((ownKey == null) ? 0 : ownKey.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ if (aKey == null || ownKey == null) {
+ return super.toString();
+ }
+ return "DuplexKey [" + aKey.toString() + ", " + ownKey.toString() + "]";
+ }
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/duplex/IDuplexMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/duplex/IDuplexMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,52 @@
+package cl.maps.duplex;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import cl.maps.quad.QuadKey;
+
+public interface IDuplexMap {
+
+ int size();
+
+ boolean isEmpty();
+
+ boolean containsKey(DuplexKey key);
+
+ boolean containsValue(Object value);
+
+ V get(DuplexKey key);
+
+ V put(DuplexKey key, V value);
+
+ V remove(DuplexKey key);
+
+ //void putAll(Map extends K, ? extends V> m);
+
+ void clear();
+
+ Set> keySet();
+
+ Collection values();
+
+ Set, V>> entrySet();
+
+ boolean equals(Object o);
+
+ /**
+ * Returns the hash code value for this map. The hash code of a map is
+ * defined to be the sum of the hash codes of each entry in the map's
+ * entrySet() view. This ensures that m1.equals(m2)
+ * implies that m1.hashCode()==m2.hashCode() for any two maps
+ * m1 and m2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this map
+ * @see Map.Entry#hashCode()
+ * @see Object#equals(Object)
+ * @see #equals(Object)
+ */
+ int hashCode();
+
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/penta/IPentaMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/penta/IPentaMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,52 @@
+package cl.maps.penta;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+
+public interface IPentaMap {
+
+ int size();
+
+ boolean isEmpty();
+
+ boolean containsKey(PentaKey key);
+
+ boolean containsValue(Object value);
+
+ V get(PentaKey key);
+
+ V put(PentaKey key, V value);
+
+ V remove(PentaKey key);
+
+ //void putAll(Map extends K, ? extends V> m);
+
+ void clear();
+
+ Set> keySet();
+
+ Collection values();
+
+ Set, V>> entrySet();
+
+ boolean equals(Object o);
+
+ /**
+ * Returns the hash code value for this map. The hash code of a map is
+ * defined to be the sum of the hash codes of each entry in the map's
+ * entrySet() view. This ensures that m1.equals(m2)
+ * implies that m1.hashCode()==m2.hashCode() for any two maps
+ * m1 and m2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this map
+ * @see Map.Entry#hashCode()
+ * @see Object#equals(Object)
+ * @see #equals(Object)
+ */
+ int hashCode();
+
+
+}
\ No newline at end of file
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/penta/PentaKey.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/penta/PentaKey.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,146 @@
+package cl.maps.penta;
+
+
+public class PentaKey {
+ private A aKey;
+ private B bKey;
+ private C cKey;
+ private D dKey;
+ private E ownKey;
+
+ public PentaKey(A aKey, B bKey, C cKey, D dKey, E ownKey){
+ this.aKey = aKey;
+ this.bKey = bKey;
+ this.cKey = cKey;
+ this.dKey = dKey;
+ this.ownKey = ownKey;
+ }
+
+ public boolean equalsAKey(A key){
+ if(aKey != null && key != null){
+ return aKey.equals(key);
+ }else if(aKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsBKey(B key){
+ if(bKey != null && key != null){
+ return bKey.equals(key);
+ }else if(bKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsCKey(C key){
+ if(cKey != null && key != null){
+ return cKey.equals(key);
+ }else if(cKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsDKey(D key){
+ if(dKey != null && key != null){
+ return dKey.equals(key);
+ }else if(dKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsOwnKey(E key){
+ if(ownKey != null && key != null){
+ return ownKey.equals(key);
+ }else if(ownKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public A getAKey() {
+ return aKey;
+ }
+
+ public void setAKey(A aKey) {
+ this.aKey = aKey;
+ }
+
+ public B getBKey() {
+ return bKey;
+ }
+
+ public void setBKey(B bKey) {
+ this.bKey = bKey;
+ }
+
+ public D getDKey() {
+ return dKey;
+ }
+
+ public void setDKey(D dKey) {
+ this.dKey = dKey;
+ }
+
+ public C getCKey() {
+ return cKey;
+ }
+
+ public void setCKey(C cKey) {
+ this.cKey = cKey;
+ }
+
+ public E getOwnKey() {
+ return ownKey;
+ }
+
+ public void setOwnKey(E ownKey) {
+ this.ownKey = ownKey;
+ }
+
+ @Override
+ public boolean equals(Object o){
+ if(o instanceof PentaKey){
+ try {
+ PentaKey other = (PentaKey)o;
+
+ if(this.equalsDKey(other.getDKey()) &&
+ this.equalsAKey(other.getAKey()) &&
+ this.equalsBKey(other.getBKey()) &&
+ this.equalsCKey(other.getCKey())){
+ return true;
+ }
+ } catch (Exception e) {}
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((aKey == null) ? 0 : aKey.hashCode());
+ result = prime * result + ((bKey == null) ? 0 : bKey.hashCode());
+ result = prime * result + ((cKey == null) ? 0 : cKey.hashCode());
+ result = prime * result + ((dKey == null) ? 0 : dKey.hashCode());
+ result = prime * result + ((ownKey == null) ? 0 : ownKey.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ if (aKey == null || bKey == null || cKey == null || dKey == null || ownKey == null) {
+ return super.toString();
+ }
+ return "PentaKey [" +
+ aKey.toString() + ", " +
+ bKey.toString() + ", " +
+ cKey.toString() + ", " +
+ dKey.toString() + ", " +
+ ownKey.toString() + "]";
+ }
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/penta/PentaMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/penta/PentaMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,224 @@
+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 implements IPentaMap{
+
+ private Map, V> map;
+ private Map>> mapAKey;
+ private Map>> mapBKey;
+ private Map>> mapCKey;
+ private Map>> mapDKey;
+ private Map> mapOwnKey;
+
+ public PentaMap(){
+ this.map = new HashMap, V>();
+ this.mapAKey = new HashMap>>();
+ this.mapBKey = new HashMap>>();
+ this.mapCKey = new HashMap>>();
+ this.mapDKey = new HashMap>>();
+ this.mapOwnKey = new HashMap>();
+ }
+
+ public PentaMap(PentaMap m) {
+ this.map = new HashMap, V>();
+ this.mapAKey = new HashMap>>();
+ this.mapBKey = new HashMap>>();
+ this.mapCKey = new HashMap>>();
+ this.mapDKey = new HashMap>>();
+ this.mapOwnKey = new HashMap>();
+ this.putAllForCreate(m);
+ }
+
+ private void putAllForCreate(PentaMap extends V, A, B, C, D, E> m) {
+ for(Map.Entry, ? extends V> e : m.entrySet()){
+
+ PentaKey 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>());
+ }
+ if(!mapAKey.get(tKey.getAKey()).contains(tKey)){
+ mapAKey.get(tKey.getAKey()).add(tKey);
+ }
+
+ if(!mapBKey.containsKey(tKey.getBKey())){
+ mapBKey.put(tKey.getBKey(), new ArrayList>());
+ }
+ if(!mapBKey.get(tKey.getBKey()).contains(tKey)){
+ mapBKey.get(tKey.getBKey()).add(tKey);
+ }
+
+ if(!mapCKey.containsKey(tKey.getCKey())){
+ mapCKey.put(tKey.getCKey(), new ArrayList>());
+ }
+ if(!mapCKey.get(tKey.getCKey()).contains(tKey)){
+ mapCKey.get(tKey.getCKey()).add(tKey);
+ }
+ if(!mapDKey.containsKey(tKey.getDKey())){
+ mapDKey.put(tKey.getDKey(), new ArrayList>());
+ }
+ if(!mapDKey.get(tKey.getDKey()).contains(tKey)){
+ mapDKey.get(tKey.getDKey()).add(tKey);
+ }
+ }
+ }
+
+ public List getValuesByAKey(A srcKey){
+ List list = new ArrayList();
+ if(mapAKey.containsKey(srcKey)){
+ for(PentaKey tKey : mapAKey.get(srcKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public List getValuesByBKey(B tarKey){
+ List list = new ArrayList();
+ if(mapBKey.containsKey(tarKey)){
+ for(PentaKey tKey : mapBKey.get(tarKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public List getValuesByCKey(C cKey){
+ List list = new ArrayList();
+ if(mapCKey.containsKey(cKey)){
+ for(PentaKey tKey : mapCKey.get(cKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public List getValuesByDKey(D dKey){
+ List list = new ArrayList();
+ if(mapDKey.containsKey(dKey)){
+ for(PentaKey tKey : mapDKey.get(dKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public V getValuesByOwnKey(E ownKey){
+ PentaKey tKey = mapOwnKey.get(ownKey);
+ if(tKey != null){
+ return this.map.get(tKey);
+ }
+ return null;
+ }
+
+ public Set> keySet(){
+ return this.map.keySet();
+ }
+
+ public Set, 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 key) {
+ return this.map.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return this.map.containsValue(value);
+ }
+
+ @Override
+ public V get(PentaKey key) {
+ return map.get(key);
+ }
+
+ @Override
+ public V put(PentaKey tKey, V value) {
+
+ if(!mapAKey.containsKey(tKey.getAKey())){
+ mapAKey.put(tKey.getAKey(), new ArrayList>());
+ }
+ if(!mapAKey.get(tKey.getAKey()).contains(tKey)){
+ mapAKey.get(tKey.getAKey()).add(tKey);
+ }
+
+ if(!mapBKey.containsKey(tKey.getBKey())){
+ mapBKey.put(tKey.getBKey(), new ArrayList>());
+ }
+ if(!mapBKey.get(tKey.getBKey()).contains(tKey)){
+ mapBKey.get(tKey.getBKey()).add(tKey);
+ }
+
+ if(!mapCKey.containsKey(tKey.getCKey())){
+ mapCKey.put(tKey.getCKey(), new ArrayList>());
+ }
+ if(!mapCKey.get(tKey.getCKey()).contains(tKey)){
+ mapCKey.get(tKey.getCKey()).add(tKey);
+ }
+
+ if(!mapDKey.containsKey(tKey.getDKey())){
+ mapDKey.put(tKey.getDKey(), new ArrayList>());
+ }
+ 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 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 values() {
+ return this.map.values();
+ }
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/quad/IQuadMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/quad/IQuadMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,51 @@
+package cl.maps.quad;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+public interface IQuadMap {
+
+ int size();
+
+ boolean isEmpty();
+
+ boolean containsKey(QuadKey key);
+
+ boolean containsValue(Object value);
+
+ V get(QuadKey key);
+
+ V put(QuadKey key, V value);
+
+ V remove(QuadKey key);
+
+ //void putAll(Map extends K, ? extends V> m);
+
+ void clear();
+
+ Set> keySet();
+
+ Collection values();
+
+ Set, V>> entrySet();
+
+ boolean equals(Object o);
+
+ /**
+ * Returns the hash code value for this map. The hash code of a map is
+ * defined to be the sum of the hash codes of each entry in the map's
+ * entrySet() view. This ensures that m1.equals(m2)
+ * implies that m1.hashCode()==m2.hashCode() for any two maps
+ * m1 and m2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this map
+ * @see Map.Entry#hashCode()
+ * @see Object#equals(Object)
+ * @see #equals(Object)
+ */
+ int hashCode();
+
+
+}
\ No newline at end of file
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/quad/QuadKey.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/quad/QuadKey.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,135 @@
+package cl.maps.quad;
+
+public class QuadKey {
+ private A aKey;
+ private B bKey;
+ private C cKey;
+ private D ownKey;
+
+ public QuadKey(A aKey, B bKey, C cKey, D ownKey){
+ this.aKey = aKey;
+ this.bKey = bKey;
+ this.cKey = cKey;
+ this.ownKey = ownKey;
+ }
+
+ /*
+ public boolean containsKey(Object key){
+ if(key != null){
+ if(key.equals(aKey) || key.equals(bKey) || key.equals(ownKey)){
+ return true;
+ }
+ }
+ return false;
+ }*/
+
+
+ public boolean equalsAKey(Object key){
+ if(aKey != null && key != null){
+ return aKey.equals(key);
+ }else if(aKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsBKey(Object key){
+ if(bKey != null && key != null){
+ return bKey.equals(key);
+ }else if(bKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsCKey(Object key){
+ if(cKey != null && key != null){
+ return cKey.equals(key);
+ }else if(cKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsOwnKey(Object key){
+ if(ownKey != null && key != null){
+ return ownKey.equals(key);
+ }else if(ownKey == null && key == null){
+ return true;
+ }
+ return false;
+ }
+
+ public A getAKey() {
+ return aKey;
+ }
+
+ public void setAKey(A aKey) {
+ this.aKey = aKey;
+ }
+
+ public B getBKey() {
+ return bKey;
+ }
+
+ public void setBKey(B bKey) {
+ this.bKey = bKey;
+ }
+
+ public D getOwnKey() {
+ return ownKey;
+ }
+
+ public void setOwnKey(D ownKey) {
+ this.ownKey = ownKey;
+ }
+
+ public C getCKey() {
+ return cKey;
+ }
+
+ public void setCKey(C cKey) {
+ this.cKey = cKey;
+ }
+
+ @Override
+ public boolean equals(Object o){
+ if(o instanceof QuadKey){
+ try {
+ QuadKey other = (QuadKey)o;
+
+ if(this.equalsOwnKey(other.getOwnKey()) &&
+ this.equalsAKey(other.getAKey()) &&
+ this.equalsBKey(other.getBKey()) &&
+ this.equalsCKey(other.getCKey())){
+ return true;
+ }
+ } catch (Exception e) {}
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((aKey == null) ? 0 : aKey.hashCode());
+ result = prime * result + ((bKey == null) ? 0 : bKey.hashCode());
+ result = prime * result + ((cKey == null) ? 0 : cKey.hashCode());
+ result = prime * result + ((ownKey == null) ? 0 : ownKey.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ if (aKey == null || bKey == null || cKey == null || ownKey == null) {
+ return super.toString();
+ }
+ return "QuadKey [" +
+ aKey.toString() + ", " +
+ bKey.toString() + ", " +
+ cKey.toString() + ", " +
+ ownKey.toString() + "]";
+ }
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/quad/QuadMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/quad/QuadMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,191 @@
+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 implements IQuadMap{
+
+ private Map, V> map;
+ private Map>> mapAKey;
+ private Map>> mapBKey;
+ private Map>> mapCKey;
+ private Map> mapOwnKey;
+
+ public QuadMap(){
+ this.map = new HashMap, V>();
+ this.mapAKey = new HashMap>>();
+ this.mapBKey = new HashMap>>();
+ this.mapCKey = new HashMap>>();
+ this.mapOwnKey = new HashMap>();
+ }
+
+ public QuadMap(QuadMap extends V, A, B, C, D> m) {
+ this.map = new HashMap, V>();
+ this.mapAKey = new HashMap>>();
+ this.mapBKey = new HashMap>>();
+ this.mapCKey = new HashMap>>();
+ this.mapOwnKey = new HashMap>();
+ this.putAllForCreate(m);
+ }
+
+ private void putAllForCreate(QuadMap extends V, A, B, C, D> m) {
+ for(Map.Entry, ? extends V> e : m.entrySet()){
+ QuadKey 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>());
+ }
+ if(!mapAKey.get(tKey.getAKey()).contains(tKey)){
+ mapAKey.get(tKey.getAKey()).add(tKey);
+ }
+
+ if(!mapBKey.containsKey(tKey.getBKey())){
+ mapBKey.put(tKey.getBKey(), new ArrayList>());
+ }
+ if(!mapBKey.get(tKey.getBKey()).contains(tKey)){
+ mapBKey.get(tKey.getBKey()).add(tKey);
+ }
+
+ if(!mapCKey.containsKey(tKey.getCKey())){
+ mapCKey.put(tKey.getCKey(), new ArrayList>());
+ }
+ if(!mapCKey.get(tKey.getCKey()).contains(tKey)){
+ mapCKey.get(tKey.getCKey()).add(tKey);
+ }
+ }
+ }
+
+ public List getValuesByAKey(A srcKey){
+ List list = new ArrayList();
+ if(mapAKey.containsKey(srcKey)){
+ for(QuadKey tKey : mapAKey.get(srcKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public List getValuesByBKey(B tarKey){
+ List list = new ArrayList();
+ if(mapBKey.containsKey(tarKey)){
+ for(QuadKey tKey : mapBKey.get(tarKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public List getValuesByCKey(C cKey){
+ List list = new ArrayList();
+ if(mapCKey.containsKey(cKey)){
+ for(QuadKey tKey : mapCKey.get(cKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public V getValuesByOwnKey(D ownKey){
+ QuadKey tKey = mapOwnKey.get(ownKey);
+ if(tKey != null){
+ return this.map.get(tKey);
+ }
+ return null;
+ }
+
+ public Set> keySet(){
+ return this.map.keySet();
+ }
+
+ public Set, 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 key) {
+ return this.map.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return this.map.containsValue(value);
+ }
+
+ @Override
+ public V get(QuadKey key) {
+ return map.get(key);
+ }
+
+ @Override
+ public V put(QuadKey tKey, V value) {
+
+ if(!mapAKey.containsKey(tKey.getAKey())){
+ mapAKey.put(tKey.getAKey(), new ArrayList>());
+ }
+ if(!mapAKey.get(tKey.getAKey()).contains(tKey)){
+ mapAKey.get(tKey.getAKey()).add(tKey);
+ }
+
+ if(!mapBKey.containsKey(tKey.getBKey())){
+ mapBKey.put(tKey.getBKey(), new ArrayList>());
+ }
+ if(!mapBKey.get(tKey.getBKey()).contains(tKey)){
+ mapBKey.get(tKey.getBKey()).add(tKey);
+ }
+
+ if(!mapCKey.containsKey(tKey.getCKey())){
+ mapCKey.put(tKey.getCKey(), new ArrayList>());
+ }
+ 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 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 values() {
+ return this.map.values();
+ }
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/triple/ITripleMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/triple/ITripleMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,52 @@
+package cl.maps.triple;
+
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+public interface ITripleMap {
+
+ int size();
+
+ boolean isEmpty();
+
+ boolean containsKey(TripleKey key);
+
+ boolean containsValue(Object value);
+
+ V get(TripleKey key);
+
+ V put(TripleKey key, V value);
+
+ V remove(TripleKey key);
+
+ //void putAll(Map extends K, ? extends V> m);
+
+ void clear();
+
+ Set> keySet();
+
+ Collection values();
+
+ Set, V>> entrySet();
+
+ boolean equals(Object o);
+
+ /**
+ * Returns the hash code value for this map. The hash code of a map is
+ * defined to be the sum of the hash codes of each entry in the map's
+ * entrySet() view. This ensures that m1.equals(m2)
+ * implies that m1.hashCode()==m2.hashCode() for any two maps
+ * m1 and m2, as required by the general contract of
+ * {@link Object#hashCode}.
+ *
+ * @return the hash code value for this map
+ * @see Map.Entry#hashCode()
+ * @see Object#equals(Object)
+ * @see #equals(Object)
+ */
+ int hashCode();
+
+
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/triple/TripleKey.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/triple/TripleKey.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,109 @@
+package cl.maps.triple;
+
+/**
+ * Unique ownKey. SrcKey and bKey not unique.
+ *
+ * @author jurzua
+ *
+ */
+public class TripleKey {
+
+ private A aKey;
+ private B bKey;
+ private C ownKey;
+
+ public TripleKey(A aKey, B label, C ownKey) {
+ this.aKey = aKey;
+ this.bKey = label;
+ this.ownKey = ownKey;
+ }
+
+ public boolean equalsAKey(A key) {
+ if (aKey != null && key != null) {
+ return aKey.equals(key);
+ } else if (aKey == null && key == null) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsBKey(B key) {
+ if (bKey != null && key != null) {
+ return bKey.equals(key);
+ } else if (bKey == null && key == null) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean equalsOwnKey(C key) {
+ if (ownKey != null && key != null) {
+ return ownKey.equals(key);
+ } else if (ownKey == null && key == null) {
+ return true;
+ }
+ return false;
+ }
+
+ public A getAKey() {
+ return aKey;
+ }
+
+ public void setAKey(A aKey) {
+ this.aKey = aKey;
+ }
+
+ public B getBKey() {
+ return bKey;
+ }
+
+ public void setBKey(B bKey) {
+ this.bKey = bKey;
+ }
+
+ public C getOwnKey() {
+ return ownKey;
+ }
+
+ public void setOwnKey(C ownKey) {
+ this.ownKey = ownKey;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof TripleKey) {
+ try {
+ TripleKey other = (TripleKey) o;
+
+ if (this.equalsOwnKey(other.getOwnKey())
+ && this.equalsAKey(other.getAKey())
+ && this.equalsBKey(other.getBKey())) {
+ return true;
+ }
+ } catch (Exception e) {
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((aKey == null) ? 0 : aKey.hashCode());
+ result = prime * result + ((bKey == null) ? 0 : bKey.hashCode());
+ result = prime * result + ((ownKey == null) ? 0 : ownKey.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ if (aKey == null || bKey == null || ownKey == null) {
+ return super.toString();
+ }
+ return "TripleKey [" + aKey.toString() + ", " + bKey.toString() + ", "
+ + ownKey.toString() + "]";
+ }
+
+}
diff -r 153a0232270b -r 6e08ff123ae6 src/main/java/cl/maps/triple/TripleMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/cl/maps/triple/TripleMap.java Wed Dec 14 15:49:40 2016 +0100
@@ -0,0 +1,169 @@
+package cl.maps.triple;
+
+
+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 TripleMap implements ITripleMap{
+
+ private Map, V> map;
+ private Map>> mapAKey;
+ private Map>> mapBKey;
+ private Map> mapOwnKey;
+
+ public TripleMap(){
+ this.map = new HashMap, V>();
+ this.mapAKey = new HashMap>>();
+ this.mapBKey = new HashMap>>();
+ this.mapOwnKey = new HashMap>();
+ }
+
+ public TripleMap(TripleMap extends V, A, B, C> m) {
+ this.map = new HashMap, V>();
+ this.mapAKey = new HashMap>>();
+ this.mapBKey = new HashMap>>();
+ this.mapOwnKey = new HashMap>();
+ this.putAllForCreate(m);
+ }
+
+ private void putAllForCreate(TripleMap extends V, A, B, C> m) {
+ for(Map.Entry, ? extends V> e : m.entrySet()){
+ TripleKey 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>());
+ }
+ if(!mapAKey.get(tKey.getAKey()).contains(tKey)){
+ mapAKey.get(tKey.getAKey()).add(tKey);
+ }
+
+ if(!mapBKey.containsKey(tKey.getBKey())){
+ mapBKey.put(tKey.getBKey(), new ArrayList>());
+ }
+ if(!mapBKey.get(tKey.getBKey()).contains(tKey)){
+ mapBKey.get(tKey.getBKey()).add(tKey);
+ }
+ }
+ }
+
+ public List getValuesByAKey(A srcKey){
+ List list = new ArrayList();
+ if(mapAKey.containsKey(srcKey)){
+ for(TripleKey tKey : mapAKey.get(srcKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public List getValuesByBKey(B tarKey){
+ List list = new ArrayList();
+ if(mapBKey.containsKey(tarKey)){
+ for(TripleKey tKey : mapBKey.get(tarKey)){
+ list.add(map.get(tKey));
+ }
+ }
+ return list;
+ }
+
+ public V getValuesByOwnKey(C ownKey){
+ TripleKey tKey = mapOwnKey.get(ownKey);
+ if(tKey != null){
+ return this.map.get(tKey);
+ }
+ return null;
+ }
+
+ public Set> keySet(){
+ return this.map.keySet();
+ }
+
+ public Set, 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(TripleKey key) {
+ return this.map.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return this.map.containsValue(value);
+ }
+
+ @Override
+ public V get(TripleKey key) {
+ return map.get(key);
+ }
+
+ @Override
+ public V put(TripleKey tKey, V value) {
+ if(!mapAKey.containsKey(tKey.getAKey())){
+ mapAKey.put(tKey.getAKey(), new ArrayList>());
+ }
+ if(!mapAKey.get(tKey.getAKey()).contains(tKey)){
+ mapAKey.get(tKey.getAKey()).add(tKey);
+ }
+
+ if(!mapBKey.containsKey(tKey.getBKey())){
+ mapBKey.put(tKey.getBKey(), new ArrayList>());
+ }
+ if(!mapBKey.get(tKey.getBKey()).contains(tKey)){
+ mapBKey.get(tKey.getBKey()).add(tKey);
+ }
+
+ this.mapOwnKey.put(tKey.getOwnKey(), tKey);
+ return this.map.put(tKey, value);
+ }
+
+ @Override
+ public V remove(TripleKey key) {
+ if(mapAKey.containsKey(key.getAKey())){
+ mapAKey.get(key.getAKey()).remove(key);
+ }
+ if(mapBKey.containsKey(key.getBKey())){
+ mapBKey.get(key.getBKey()).remove(key);
+ }
+ this.mapOwnKey.remove(key.getOwnKey());
+
+ int hashCodeInput = key.hashCode();
+ System.out.println(hashCodeInput);
+ if(map.size() == 1){
+ Object uu = new ArrayList>(map.keySet()).get(0);
+ int hashCode2 = uu.hashCode();
+ System.out.println(hashCode2);
+ }
+
+ return this.map.remove(key);
+ }
+
+ @Override
+ public void clear() {
+ this.map.clear();
+ this.mapAKey.clear();
+ this.mapBKey.clear();
+ this.mapOwnKey.clear();
+ }
+
+ @Override
+ public Collection values() {
+ return this.map.values();
+ }
+}