1 24 package org.objectweb.jalisto.se.impl.server.page.info; 25 26 import org.objectweb.jalisto.se.impl.InFileAddress; 27 28 import java.io.Serializable ; 29 import java.util.Iterator ; 30 import java.util.LinkedList ; 31 32 public class PageInfo implements Serializable { 33 public PageInfo(short pageSize, short pageType) { 34 this.freePlaces = new LinkedList (); 35 this.size = pageSize; 36 this.pageType = pageType; 37 38 for (int i = 0; i < size; i++) { 39 freePlaces.addLast(new Integer (i)); 40 } 41 } 42 43 public short getPageType() { 44 return pageType; 45 } 46 47 public Iterator getAllFreePlace() { 48 return freePlaces.iterator(); 49 } 50 51 public boolean isEmpty() { 52 return (freePlaces.size() == size); 53 } 54 55 public int getEmptySpace() { 56 return freePlaces.size(); 57 } 58 59 public Integer getAFreePlace() { 60 Integer result = (Integer ) freePlaces.getFirst(); 61 freePlaces.removeFirst(); 62 return result; 63 } 64 65 public void allocateFreeSpaceAt(Integer index) { 66 freePlaces.addLast(index); 67 } 68 69 public boolean hasFreeSpaceAt(Integer index) { 70 return freePlaces.contains(index); 71 } 72 73 public void noMorefreeSpaceAt(Integer index) { 74 freePlaces.remove(index); 75 } 76 77 public void setPageIfa(InFileAddress pageIfa) { 78 this.pageIfa = pageIfa; 79 } 80 81 public InFileAddress getPageIfa() { 82 return pageIfa.getClone(); 83 } 84 85 public void setPid(Object pid) { 86 this.pid = pid; 87 } 88 89 public Object getPid() { 90 return pid; 91 } 92 93 public PageInfo getClone() { 94 PageInfo clone = new PageInfo(size, pageType); 95 clone.pageIfa = pageIfa.getClone(); 96 clone.freePlaces = new LinkedList (freePlaces); 97 clone.pid = pid; 98 return clone; 99 } 100 101 public String toString() { 102 StringBuffer sb = new StringBuffer (); 103 sb.append("PageInfo:").append(pid).append(':').append(pageIfa) 104 .append(':').append(getEmptySpace()); 105 106 return sb.toString(); 107 } 108 109 110 private InFileAddress pageIfa; 111 private LinkedList freePlaces; 112 private Object pid; 113 private short size; 114 private short pageType; 115 116 117 static final long serialVersionUID = -7589377097964761459L; 118 } 119 | Popular Tags |