1 10 package com.hp.hpl.jena.reasoner; 11 12 import com.hp.hpl.jena.util.iterator.*; 13 14 22 public class FinderUtil { 23 24 30 public static Finder cascade(Finder first, Finder second) { 31 if (first == null || (first instanceof FGraph && ((FGraph)first).getGraph() == null)) return second; 32 if (second == null || (second instanceof FGraph && ((FGraph)second).getGraph() == null)) return first; 33 return new Cascade(first, second); 34 } 35 36 43 public static Finder cascade(Finder first, Finder second, Finder third) { 44 return new Cascade(first, cascade(second, third)); 45 } 46 47 55 public static Finder cascade(Finder first, Finder second, Finder third, Finder fourth) { 56 return new Cascade(first, cascade(second, cascade(third, fourth))); 57 } 58 59 62 private static class Cascade implements Finder { 63 64 Finder first; 65 66 67 Finder second; 68 69 72 Cascade(Finder first, Finder second) { 73 this.first = first; 74 this.second = second; 75 } 76 77 83 public ExtendedIterator find(TriplePattern pattern) { 84 if (second == null) { 85 return first.find(pattern); 86 } else if (first == null) { 87 return second.find(pattern); 88 } else { 89 return first.findWithContinuation(pattern, second); 90 } 91 } 92 93 104 public ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation) { 105 return (FinderUtil.cascade(first, second, continuation)).find(pattern); 106 } 107 108 111 public boolean contains(TriplePattern pattern) { 112 ClosableIterator it = find(pattern); 113 boolean result = it.hasNext(); 114 it.close(); 115 return result; 116 } 117 118 } 119 } 120 121 150 151 | Popular Tags |