# HG changeset patch # User Jorge Urzua # Date 1365686726 -7200 # Node ID dfce13a5f5f9fa50ce1a3982abef2e6235d312b7 nit project! diff -r 000000000000 -r dfce13a5f5f9 bin/de/mpiwg/indexmeta/AnnotateIndexMeta.class Binary file bin/de/mpiwg/indexmeta/AnnotateIndexMeta.class has changed diff -r 000000000000 -r dfce13a5f5f9 bin/de/mpiwg/indexmeta/IndexMetaParser.class Binary file bin/de/mpiwg/indexmeta/IndexMetaParser.class has changed diff -r 000000000000 -r dfce13a5f5f9 bin/de/mpiwg/indexmeta/bo/Contextualization.class Binary file bin/de/mpiwg/indexmeta/bo/Contextualization.class has changed diff -r 000000000000 -r dfce13a5f5f9 bin/de/mpiwg/indexmeta/bo/Message.class Binary file bin/de/mpiwg/indexmeta/bo/Message.class has changed diff -r 000000000000 -r dfce13a5f5f9 data/index.meta/01index.meta --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/index.meta/01index.meta Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,100 @@ + + + 04.10.2010 + HSPGZ0AE + /mpiwg/online/permanent/library/HSPGZ0AE + digigroup + + /mpiwg/archive/data/library/R2QPGF06 + + + en + scanned document + + + + + + Harriot, Thomas + + + Harriot, Thomas + http://d-nb.info/gnd/118720473 + + + + + Stedall, Jacqueline + http://d-nb.info/gnd/1019195649 + + + Schemmel, Matthias + http://d-nb.info/gnd/123937299 + + + 505 Bl. + + Mss. 6782 + + Harriot, Thomas + test + + + + + + + + + + /echo/en/Harriot_Add_MS_6782_HSPGZ0AE.xml + pageimg +
figures
+ ltr + right + 1 + pb + yes + http://echo.mpiwg-berlin.mpg.de/zogilib? +
+ + + + British Library + http://www.bl.uk/index.shtml + + + British Library + http://www.bl.uk/index.shtml + + + Stedall, Jacqueline + http://www.maths.ox.ac.uk/contact/details/stedall/ + + + Schemmel, Matthias + http://www.mpiwg-berlin.mpg.de/en/staff/members/schemmel + + + + British Library + http://www.bl.uk/index.shtml + + + + + British Library + http://www.bl.uk/index.shtml + + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + + + escidoc:153332escidoc:186920MPIWG:5PYT50NY +
\ No newline at end of file diff -r 000000000000 -r dfce13a5f5f9 data/index.meta/01index.meta.anno.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/index.meta/01index.meta.anno.xml Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,93 @@ + + + 04.10.2010 + HSPGZ0AE + /mpiwg/online/permanent/library/HSPGZ0AE + digigroup + + /mpiwg/archive/data/library/R2QPGF06 + + + en + scanned document + + Berlin + Harriot, Thomas + + Harriot, Thomas + http://d-nb.info/gnd/118720473 + + + Stedall, Jacqueline + http://d-nb.info/gnd/1019195649 + + + Schemmel, Matthias + http://d-nb.info/gnd/123937299 + + Talca + 505 Bl. + + Mss. 6782 + + publisher + + + + + + + + + + /echo/en/Harriot_Add_MS_6782_HSPGZ0AE.xml + pageimg +
figures
+ ltr + right + 1 + pb + yes + http://echo.mpiwg-berlin.mpg.de/zogilib? +
+ + + + British Library + http://www.bl.uk/index.shtml + + + British Library + http://www.bl.uk/index.shtml + + + Stedall, Jacqueline + http://www.maths.ox.ac.uk/contact/details/stedall/ + + + Schemmel, Matthias + http://www.mpiwg-berlin.mpg.de/en/staff/members/schemmel + + + + British Library + http://www.bl.uk/index.shtml + + + + + British Library + http://www.bl.uk/index.shtml + + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + + + escidoc:153332escidoc:186920MPIWG:5PYT50NY +
\ No newline at end of file diff -r 000000000000 -r dfce13a5f5f9 data/index.meta/02index.meta --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/index.meta/02index.meta Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,91 @@ + + + + 18.03.2013 + PUBSU9QD + /mpiwg/online/permanent/library/PUBSU9QD + Max Planck Institute for the History of Science, Library + + /mpiwg/archive/data/library/SZF2P707 + + image + + scanned document + lat + + Apian, Petrus + + Apian, Petrus + http://d-nb.info/gnd/118645455 + + Gemma Frisius, Rainer + + Gemma Frisius, Rainer + http://d-nb.info/gnd/111548993 + + Cosmographia + 1550 + Antwerpiae + Bontius + [2], 65, [1] Bl. : Ill. + Cosmography - Early works to 1800 + + 520 + + Erstausgabe 1524 in Landshut.; Enthält: astronomische Grundlagen der Erdbeschreibung; physische Geographie (mit Beschreibung der 4 Erdteile) + Max Planck Institute for the History of Science, Library + Rara A642c + + + rgb + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + + + Max Planck Institute for the History of Science, Library + http://www.mpiwg-berlin.mpg.de/ + + + + + + pageimg + figures + /echo/la/Apian_1550_PUBSU9QD.xml + 3 + + MPIWG:WBGMR64C + + diff -r 000000000000 -r dfce13a5f5f9 pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,66 @@ + + + 4.0.0 + de.mpiwg.indexmeta + indexmeta + jar + 1.0-SNAPSHOT + de.mpiwg.indexmeta + + + target + src/main/java + + + + org.apache.maven.plugins + maven-compiler-plugin + + + resources + + + + + + + + + + org.hibernate + hibernate-entitymanager + 3.5.5-Final + + + commons-logging + commons-logging + 1.0.4 + + + c3p0 + c3p0 + 0.9.1 + + + org.slf4j + slf4j-api + 1.6.6 + + + org.slf4j + slf4j-log4j12 + 1.6.6 + + + mysql + mysql-connector-java + 5.1.13 + jar + compile + + + + + \ No newline at end of file diff -r 000000000000 -r dfce13a5f5f9 src/main/java/META-INF/persistence.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/META-INF/persistence.xml Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,38 @@ + + + + + org.hibernate.ejb.HibernatePersistence + de.mpiwg.indexmeta.bo.Contextualization + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/AnnotateIndexMeta.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/AnnotateIndexMeta.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,94 @@ +package de.mpiwg.indexmeta; +// import stuff +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import javax.print.attribute.standard.MediaSize.Other; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class AnnotateIndexMeta { + + public static void main(String argv[]) { + System.out.println("in main"); + + // Methodenaufruf + String filepath = "/Users/kthoden/eclipse/workspace/dm2eStuff/data/index.meta"; + // this is a list of all the elements we want to contextualize + List contextualizableList = Arrays.asList(new String[]{"author","editor","publisher","city","holding-library","keywords"}); + xmlParse(filepath,contextualizableList); + System.out.println("Done"); + } + + /** + * Parses the XML file given as first argument and writes attributes in elements that are to be contextualized. + * @param filepath path to the file. It will also be used as the basis for the output file (this adds "-annot"). + * @param contextualizableList contains the elements that shall be given a context identifier which is later used to grab the contents and put them into the database to have it contextualized. + * + */ + public static void xmlParse(String filepath, List contextualizableList) { + try { + // this is how the outputfile will be called + String outfilepath = filepath + "-annot"; + // open the file and parse it + DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + Document doc = docBuilder.parse(filepath); + + // iterate through the document + Integer count = 0; + for(String contextElement : contextualizableList){ + NodeList nodeList = doc.getElementsByTagName(contextElement); + for(int i=0; i < nodeList.getLength(); i++){ + Node iter2 = nodeList.item(i); + NamedNodeMap attr = iter2.getAttributes(); + // make a new attribute + // DONE would be good if it left existing outputs alone + if (attr.getNamedItem("context-id") == null){ + Attr attribute = doc.createAttribute ("context-id"); + attribute.setValue (count.toString()); + attr.setNamedItem (attribute); + } + else { + System.out.println("schon da: " + attr.getNamedItem("context-id")); + } + // Just for comfort. Print it out. + System.out.println(contextElement); + count++; + } + // get the element by name (so they should be unique?) + //Node iter2 = doc.getElementsByTagName(contextElement).item(0); + } + // write the content into xml file + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(new File(outfilepath)); + transformer.transform(source, result); + + } catch (ParserConfigurationException pce) { + pce.printStackTrace(); + } catch (TransformerException tfe) { + tfe.printStackTrace(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } catch (SAXException sae) { + sae.printStackTrace(); + } + } +} \ No newline at end of file diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/DataProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/DataProvider.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,36 @@ +package de.mpiwg.indexmeta; + +import java.util.ArrayList; +import java.util.List; + +import de.mpiwg.indexmeta.bo.Contextualization; +import de.mpiwg.indexmeta.utils.QuadKey; + +public class DataProvider { + + private PersistentService ps = new PersistentService(); + + public List getCtxByIndexMetaId(String indexMetaId){ + //QuadKey(indexMetaId, elementId, remoteId, id) + return ps.getCtxMap().getValuesByFirstKey(indexMetaId); + } + + public List getCtxByElementId(String elementId){ + //QuadKey(indexMetaId, elementId, remoteId, id) + return ps.getCtxMap().getValuesBySecondKey(elementId); + } + + public List getCtxByRemoteId(String remoteId){ + //QuadKey(indexMetaId, elementId, remoteId, id) + return ps.getCtxMap().getValuesByThirdKey(remoteId); + } + + public Contextualization getCtx(Long id){ + return ps.getCtxMap().getValuesByOwnKey(id); + } + + public void saveCtx(Contextualization ctx){ + ps.saveCtx(ctx); + } + +} diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/IndexMetaParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/IndexMetaParser.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,127 @@ +package de.mpiwg.indexmeta; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.mpiwg.indexmeta.bo.Contextualization; + +public class IndexMetaParser { + + + public static List getCtxItems(String filePath){ + List rs = new ArrayList(); + + try { + File file = new File("/Users/jurzua/Projects/workspace/contextualization/data/index.meta/01index.meta.anno.xml"); + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(file); + + List nodes = getNodeList(doc, Contextualization.AUTHOR); + for(Node node : nodes){ + Contextualization ctx = getCtx(node, "XX"); + if(ctx != null){ + rs.add(ctx); + } + } + + nodes = getNodeList(doc, Contextualization.CITY); + for(Node node : nodes){ + Contextualization ctx = getCtx(node, "XX"); + if(ctx != null){ + rs.add(ctx); + } + } + + for(Contextualization ctx : rs){ + System.out.println(ctx.toString()); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + return rs; + } + + public static List getNodeList(Document doc, String tagName){ + List rs = new ArrayList(); + + try { + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + XPathExpression expr = xpath.compile("//" + tagName); + + Object result = expr.evaluate(doc, XPathConstants.NODESET); + + NodeList nodes = (NodeList) result; + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + rs.add(node); + } + } catch (Exception e) { + e.printStackTrace(); + } + + return rs; + + } + + public static Contextualization getCtx(Node node, String indexMetaId){ + if(node instanceof Element){ + try{ + Element elem = (Element)node; + Contextualization ctx = new Contextualization(); + ctx.setIndexMetaId(indexMetaId); + ctx.setType(elem.getNodeName()); + ctx.setElementId(elem.getAttribute("context-id")); + + Node child = elem.getFirstChild(); + if(child != null){ + ctx.setContent(child.getNodeValue()); + } + return ctx; + }catch (Exception e) { + e.printStackTrace(); + } + } + + + return null; + } + + public static void main(String[] args){ + + getCtxItems("/Users/jurzua/Projects/workspace/contextualization/data/index.meta/01index.meta"); + } + + public static void printXpathResult(Object result){ + NodeList nodes = (NodeList) result; + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if(node instanceof Element){ + Element e = (Element)node; + + System.out.println("Local Name= " + node.getLocalName()); + System.out.println("Value= " + node.getNodeValue()); + System.out.println("Name= " + node.getNodeName()); + System.out.println("getFirstChild value= " + node.getFirstChild().getNodeValue()); + System.out.println(node); + } + } + } +} diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/PersistentService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/PersistentService.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,71 @@ +package de.mpiwg.indexmeta; + +import java.util.List; + +import javax.persistence.Query; + +import de.mpiwg.indexmeta.bo.Contextualization; +import de.mpiwg.indexmeta.utils.QuadMap; + +public class PersistentService { + + private QuadMap ctxMap = null; + private javax.persistence.EntityManagerFactory emf; + private javax.persistence.EntityManager em; + private String PERSISTENCE_UNIT_NAME = "uno"; + + + public QuadMap getCtxMap() { + if(ctxMap == null){ + this.loadCtxMap(); + } + return ctxMap; + } + + public void saveCtx(Contextualization ctx){ + System.out.println("Saving= " + ctx.toString()); + + initEntityManager(); + em.getTransaction().begin(); + + em.persist(ctx); + ctxMap.put(ctx.getKey(), ctx); + + em.getTransaction().commit(); + closeEntityManager(); + + System.out.println("Saved= " + ctx.toString()); + } + + + private void loadCtxMap(){ + ctxMap = new QuadMap(); + + initEntityManager(); + em.getTransaction().begin(); + + Query q = em.createQuery("from Contextualization"); + List list = q.getResultList(); + + for(Contextualization ctx : list){ + ctxMap.put(ctx.getKey(), ctx); + } + + em.getTransaction().commit(); + closeEntityManager(); + } + + + private void initEntityManager() { + emf = javax.persistence.Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); + em = emf.createEntityManager(); + } + + private void closeEntityManager() { + em.close(); + emf.close(); + } + + + +} diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/bo/Contextualization.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/bo/Contextualization.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,104 @@ + package de.mpiwg.indexmeta.bo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import de.mpiwg.indexmeta.utils.QuadKey; + +@Entity +public class Contextualization { + + @Id + @GeneratedValue + private Long id; + + private String indexMetaId; + private String elementId; + private String xpath; + private String remoteId; + private String state; + private String comment; + private String content; + + public static String PUBLISHER = "publisher"; + public static String CITY = "city"; + public static String HOLDING_LIBRARY = "holding-library"; + public static String AUTHOR = "author"; + + //"publisher","city","holding-library", "author" + private String type; + + public String getIndexMetaId() { + return indexMetaId; + } + public void setIndexMetaId(String indexMetaId) { + this.indexMetaId = indexMetaId; + } + public String getElementId() { + return elementId; + } + public void setElementId(String elementId) { + this.elementId = elementId; + } + public String getXpath() { + return xpath; + } + public void setXpath(String xpath) { + this.xpath = xpath; + } + public String getRemoteId() { + return remoteId; + } + public void setRemoteId(String remoteId) { + this.remoteId = remoteId; + } + public String getState() { + return state; + } + public void setState(String state) { + this.state = state; + } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getContent() { + return content; + } + public void setContent(String content) { + this.content = content; + } + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + public QuadKey getKey(){ + return new QuadKey(indexMetaId, elementId, remoteId, id); + } + + @Override + public String toString(){ + StringBuilder sb = new StringBuilder("Ctx ["); + + sb.append("indexMetaId=" + indexMetaId); + sb.append(", type=" + type); + sb.append(", elementId=" + elementId); + sb.append(", remoteId=" + remoteId); + sb.append(", content=" + content); + + sb.append("]"); + return sb.toString(); + } +} diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/utils/IQuadMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/utils/IQuadMap.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,51 @@ +package de.mpiwg.indexmeta.utils; + +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 m); + + void clear(); + + Set keySet(); + + Collection values(); + + Set> 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 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/utils/QuadKey.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/utils/QuadKey.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,116 @@ +package de.mpiwg.indexmeta.utils; + +public class QuadKey { + private F firstKey; + private S secondKey; + private T thirdKey; + private Object ownKey; + /* + public QuadKey(Long firstKey, Long secondKey, Long thirdKey, Long ownKey){ + this.firstKey = firstKey; + this.secondKey = secondKey; + this.thirdKey = thirdKey; + this.ownKey = ownKey; + }*/ + + public QuadKey(F firstKey, S secondKey, T thirdKey, Long ownKey){ + this.firstKey = firstKey; + this.secondKey = secondKey; + this.thirdKey = thirdKey; + this.ownKey = ownKey; + } + + /* + public boolean containsKey(Object key){ + if(key != null){ + if(key.equals(firstKey) || key.equals(secondKey) || key.equals(ownKey)){ + return true; + } + } + return false; + }*/ + + + public boolean equalsFirstKey(Object key){ + if(firstKey != null && key != null){ + return firstKey.equals(key); + }else if(firstKey == null && key == null){ + return true; + } + return false; + } + + public boolean equalsSecondKey(Object key){ + if(secondKey != null && key != null){ + return secondKey.equals(key); + }else if(secondKey == null && key == null){ + return true; + } + return false; + } + + public boolean equalsThirdKey(Object key){ + if(thirdKey != null && key != null){ + return thirdKey.equals(key); + }else if(thirdKey == 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 Object getFirstKey() { + return firstKey; + } + + public void setFirstKey(F firstKey) { + this.firstKey = firstKey; + } + + public Object getSecondKey() { + return secondKey; + } + + public void setSecondKey(S secondKey) { + this.secondKey = secondKey; + } + + public Object getOwnKey() { + return ownKey; + } + + public void setOwnKey(Object ownKey) { + this.ownKey = ownKey; + } + + public Object getThirdKey() { + return thirdKey; + } + + public void setThirdKey(T thirdKey) { + this.thirdKey = thirdKey; + } + + @Override + public boolean equals(Object o){ + if(o instanceof QuadKey){ + QuadKey other = (QuadKey)o; + + if(this.equalsOwnKey(other.getOwnKey()) && + this.equalsFirstKey(other.getFirstKey()) && + this.equalsSecondKey(other.getSecondKey()) && + this.equalsThirdKey(other.getThirdKey())){ + return true; + } + } + return false; + } +} diff -r 000000000000 -r dfce13a5f5f9 src/main/java/de/mpiwg/indexmeta/utils/QuadMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/indexmeta/utils/QuadMap.java Thu Apr 11 15:25:26 2013 +0200 @@ -0,0 +1,191 @@ +package de.mpiwg.indexmeta.utils; + +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 map; + private Map> mapFirstKey; + private Map> mapSecondKey; + private Map> mapThirdKey; + private Map mapOwnKey; + + public QuadMap(){ + this.map = new HashMap(); + this.mapFirstKey = new HashMap>(); + this.mapSecondKey = new HashMap>(); + this.mapThirdKey = new HashMap>(); + this.mapOwnKey = new HashMap(); + } + + public QuadMap(QuadMap m) { + this.map = new HashMap(); + this.mapFirstKey = new HashMap>(); + this.mapSecondKey = new HashMap>(); + this.mapThirdKey = new HashMap>(); + this.mapOwnKey = new HashMap(); + this.putAllForCreate(m); + } + + private void putAllForCreate(QuadMap m) { + for(Map.Entry e : m.entrySet()){ + QuadKey tKey = e.getKey(); + this.map.put(tKey, e.getValue()); + this.mapOwnKey.put(tKey.getOwnKey(), tKey); + + if(!mapFirstKey.containsKey(tKey.getFirstKey())){ + mapFirstKey.put(tKey.getFirstKey(), new ArrayList()); + } + if(!mapFirstKey.get(tKey.getFirstKey()).contains(tKey)){ + mapFirstKey.get(tKey.getFirstKey()).add(tKey); + } + + if(!mapSecondKey.containsKey(tKey.getSecondKey())){ + mapSecondKey.put(tKey.getSecondKey(), new ArrayList()); + } + if(!mapSecondKey.get(tKey.getSecondKey()).contains(tKey)){ + mapSecondKey.get(tKey.getSecondKey()).add(tKey); + } + + if(!mapThirdKey.containsKey(tKey.getThirdKey())){ + mapThirdKey.put(tKey.getThirdKey(), new ArrayList()); + } + if(!mapThirdKey.get(tKey.getThirdKey()).contains(tKey)){ + mapThirdKey.get(tKey.getThirdKey()).add(tKey); + } + } + } + + public List getValuesByFirstKey(Object srcKey){ + List list = new ArrayList(); + if(mapFirstKey.containsKey(srcKey)){ + for(QuadKey tKey : mapFirstKey.get(srcKey)){ + list.add(map.get(tKey)); + } + } + return list; + } + + public List getValuesBySecondKey(Object tarKey){ + List list = new ArrayList(); + if(mapSecondKey.containsKey(tarKey)){ + for(QuadKey tKey : mapSecondKey.get(tarKey)){ + list.add(map.get(tKey)); + } + } + return list; + } + + public List getValuesByThirdKey(Object thirdKey){ + List list = new ArrayList(); + if(mapThirdKey.containsKey(thirdKey)){ + for(QuadKey tKey : mapThirdKey.get(thirdKey)){ + list.add(map.get(tKey)); + } + } + return list; + } + + public V getValuesByOwnKey(Object 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> 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(!mapFirstKey.containsKey(tKey.getFirstKey())){ + mapFirstKey.put(tKey.getFirstKey(), new ArrayList()); + } + if(!mapFirstKey.get(tKey.getFirstKey()).contains(tKey)){ + mapFirstKey.get(tKey.getFirstKey()).add(tKey); + } + + if(!mapSecondKey.containsKey(tKey.getSecondKey())){ + mapSecondKey.put(tKey.getSecondKey(), new ArrayList()); + } + if(!mapSecondKey.get(tKey.getSecondKey()).contains(tKey)){ + mapSecondKey.get(tKey.getSecondKey()).add(tKey); + } + + if(!mapThirdKey.containsKey(tKey.getThirdKey())){ + mapThirdKey.put(tKey.getThirdKey(), new ArrayList()); + } + if(!mapThirdKey.get(tKey.getThirdKey()).contains(tKey)){ + mapThirdKey.get(tKey.getThirdKey()).add(tKey); + } + + this.mapOwnKey.put(tKey.getOwnKey(), tKey); + return this.map.put(tKey, value); + } + + @Override + public V remove(QuadKey key) { + if(mapFirstKey.containsKey(key.getFirstKey())){ + mapFirstKey.get(key.getFirstKey()).remove(key); + } + if(mapSecondKey.containsKey(key.getSecondKey())){ + mapSecondKey.get(key.getSecondKey()).remove(key); + } + if(mapThirdKey.containsKey(key.getThirdKey())){ + mapThirdKey.get(key.getThirdKey()).remove(key); + } + this.mapOwnKey.remove(key.getOwnKey()); + return this.map.remove(key); + } + + @Override + public void clear() { + this.map.clear(); + this.mapFirstKey.clear(); + this.mapSecondKey.clear(); + this.mapThirdKey.clear(); + this.mapOwnKey.clear(); + } + + @Override + public Collection values() { + return this.map.values(); + } +}