1 10 package com.hp.hpl.jena.reasoner.rulesys.impl; 11 12 import java.util.*; 13 14 import com.hp.hpl.jena.graph.Node; 15 import com.hp.hpl.jena.reasoner.InfGraph; 16 import com.hp.hpl.jena.util.OneToManyMap; 17 18 28 29 33 public class TempNodeCache { 34 35 36 protected OneToManyMap ipMap = new OneToManyMap(); 37 38 39 protected Map classMap = new HashMap(); 40 41 46 public TempNodeCache(InfGraph infgraph) { 47 } 48 49 56 public synchronized Node getTemp(Node instance, Node prop, Node pclass) { 57 NodePair ip = new NodePair(instance, prop); 58 Node result = null; 59 for (Iterator i = ipMap.getAll(ip); i.hasNext(); ) { 60 Node t = (Node)i.next(); 61 if (pclass != null) { 62 Object tClass = classMap.get(t); 63 if (tClass != null && tClass.equals(pclass)) { 64 result = t; 65 break; 66 } 67 } else { 68 result = t; 69 break; 70 } 71 } 72 if (result == null) { 73 result = Node.createAnon(); 75 ipMap.put(ip, result); 76 if (pclass != null) { 77 classMap.put(result, pclass); 78 } 79 } 80 return result; 81 } 82 83 86 public static class NodePair { 87 88 protected Node first; 89 90 91 protected Node second; 92 93 94 public NodePair(Node first, Node second) { 95 this.first = first; 96 this.second = second; 97 } 98 99 102 public Node getFirst() { 103 return first; 104 } 105 106 109 public Node getSecond() { 110 return second; 111 } 112 113 116 public boolean equals(Object o) { 117 return o instanceof NodePair && 118 first.equals(((NodePair)o).first) && 119 second.equals(((NodePair)o).second); 120 } 121 124 public int hashCode() { 125 return first.hashCode() ^ (second.hashCode() << 1); 126 } 127 128 } 129 130 } 131 132 133 134 | Popular Tags |