1 23 24 package org.objectweb.medor.eval.cache.lib; 25 26 29 30 import org.objectweb.medor.api.MedorException; 31 import org.objectweb.medor.api.TupleStructure; 32 import org.objectweb.medor.eval.cache.api.CachedTupleCollection; 33 import org.objectweb.medor.eval.cache.api.CollectionCache; 34 import org.objectweb.medor.tuple.api.Tuple; 35 import org.objectweb.medor.tuple.api.TupleCollection; 36 37 public class WindowCachedTupleCollection implements CachedTupleCollection { 38 39 private boolean closed = false; 40 public WindowCachedTupleCollection(TupleCollection tc, 41 CollectionCache tupleCache) 42 throws MedorException { 43 this.tupleCache = tupleCache; 44 this.tc = tc; 45 } 46 47 private CollectionCache tupleCache; 48 private TupleCollection tc; 49 private int cursor = 1; 50 51 public void close() throws MedorException { 52 closed =true; 53 } 54 55 public TupleStructure getMetaData() throws MedorException{ 56 return tc.getMetaData(); 57 } 58 59 public CollectionCache getCache() { 60 return tupleCache; 61 } 62 63 public boolean isLast() throws MedorException { 64 if (tc.getRow() == cursor) { 65 return tc.isLast(); 66 } else 67 return (!tupleCache.contains(cursor + 1)); 68 } 69 70 public boolean next() throws MedorException { 71 if (!isLast()) { 72 cursor++; 73 if (!tupleCache.contains(cursor + 1)) tc.next(); 74 return true; 75 } else 76 return false; 77 } 78 79 public void first() throws MedorException { 80 cursor = 1; 81 tupleCache.initialize(); 82 tc.first(); 83 } 84 85 public Tuple getTuple() throws MedorException { 86 Tuple t = null; 87 t = tupleCache.getTuple(cursor); 88 if (t == null) { 89 t = (Tuple) tc.getTuple(); 93 tupleCache.putTuple(cursor, t); 94 if (tc.isLast()) { 95 tupleCache.setCanInsert(false); 96 } 97 } else { 98 } 100 return t; 101 } 102 103 public Tuple getTuple(int row) throws MedorException { 104 Tuple t = null; 105 t = tupleCache.getTuple(row); 106 if (t == null) { 107 t = (Tuple)tc.getTuple(row); 111 tupleCache.putTuple(row, t); 112 if (tc.isLast()) { 113 tupleCache.setCanInsert(false); 114 } 115 } return t; 117 } 118 119 public boolean row(int numTuple) throws MedorException { 120 cursor = numTuple; 122 tupleCache.initialize(); 123 return (tc.row(numTuple)); 124 } 125 126 public int getRow() throws MedorException { 127 return cursor; 128 } 129 130 public boolean isEmpty() throws MedorException{ 131 return tc.isEmpty(); 132 } 133 134 137 public int getLeftTCCursor() { 138 return 0; 139 } 140 141 144 public int getRightTCCursor() { 145 return 0; 146 } 147 148 } 149 | Popular Tags |