1 19 package org.netbeans.mdr.persistence.btreeimpl.btreestorage; 20 21 import java.io.*; 22 import java.text.*; 23 import java.util.*; 24 import org.netbeans.mdr.persistence.*; 25 import org.netbeans.mdr.persistence.btreeimpl.btreeindex.*; 26 27 31 public class CounterIndex extends NameIndex { 32 33 34 int nextInt = 0; 35 36 37 public CounterIndex() { 38 } 39 40 43 public synchronized int get(String name) throws StorageException { 44 return ((Integer )getObj(name)).intValue(); 45 } 46 47 50 public synchronized Integer getIf(String name) throws StorageException { 51 return (Integer )getObjIf(name); 52 } 53 54 60 public synchronized int add(String name) throws StorageException { 61 int i = nextInt++; 62 addObj(name, new Integer (i)); 63 return i; 64 } 65 66 68 public synchronized void write(DataOutputStream dstrm) throws StorageException{ 69 super.write(dstrm); 70 try { 71 dstrm.writeInt(nextInt); 72 } 73 catch (IOException ex) { 74 throw new StorageIOException(ex); 75 } 76 } 77 78 80 public synchronized void read(DataInputStream dstrm) throws StorageException{ 81 super.read(dstrm); 82 try { 83 nextInt = dstrm.readInt(); 84 } 85 catch (IOException ex) { 86 throw new StorageIOException(ex); 87 } 88 } 89 90 95 protected void writeObjectToStream(Object obj, DataOutputStream strm) 96 throws StorageException { 97 try { 98 strm.writeInt(((Integer )obj).intValue()); 99 } 100 catch (IOException ex) { 101 throw new StorageIOException(ex); 102 } 103 } 104 105 110 protected Object readObjectFromStream(DataInputStream strm) 111 throws StorageException { 112 try { 113 return new Integer (strm.readInt()); 114 } 115 catch (IOException ex) { 116 throw new StorageIOException(ex); 117 } 118 119 } 120 } 121 122 123 124 | Popular Tags |