1 package com.daffodilwoods.daffodildb.client; 2 3 import java.util.*; 4 import com.daffodilwoods.database.resource.*; 5 import com.daffodilwoods.database.utility.P; 6 public class UnFetchStatus { 7 8 11 Hashtable status; 12 13 15 public UnFetchStatus() { 16 status = new Hashtable(); 17 } 18 19 22 public void remove(Object key) throws DException { 23 if(status.containsKey(key)) 24 status.remove(key); 25 } 26 27 34 public boolean isFetched(Object key,boolean after) throws DException { 35 if(key == null) 36 return false; 37 if(! status.containsKey(key)) 38 return true; 39 Object values = status.get(key); 40 boolean[] afterBefore = (boolean[])values; 41 return after ? afterBefore[1]: afterBefore[0] ; 42 } 43 44 51 public void setFetched(Object key,boolean after) throws DException { 52 if(! status.containsKey(key)){ 53 boolean [] afterBefore = after ? new boolean[]{true,false} :new boolean[]{false,true}; 54 status.put(key,afterBefore); 55 } 56 else{ 57 Object values = status.get(key); 58 boolean[] afterBefore = (boolean[])values; 59 if(after ? afterBefore[1] == false && afterBefore[0] == true 60 : afterBefore[0] == false && afterBefore[1] == true) 61 62 remove(key); 63 else{ 64 int index = after? 1 : 0; 65 afterBefore[index] = ! afterBefore[index]; 66 } 67 } 68 69 } 70 71 public int size() throws DException { 72 return status.size(); 73 } 74 75 public void showMap() throws DException { 76 Set set =status.entrySet(); 77 Iterator i=set.iterator(); 78 while(i.hasNext()){ 79 Map.Entry m=(Map.Entry)i.next(); 80 P.pln(" key " + m.getKey() + " values " + P.print(m.getValue())); 81 } 82 } 83 84 public Object [] getKeys(){ 85 Set keySet = status.keySet(); 86 return keySet == null ? null : keySet.toArray(); 87 } 88 89 } 90 | Popular Tags |