Java Reference
In-Depth Information
public class StringVectorRms {
RecordStore store;
String storeName;
int size;
static int openedStores = 0;
public StringVectorRms() {
storeName = "StringVectorRms"+(openedStores++);
size = 0;
try {
store = RecordStore.openRecordStore (storeName, true);
if (store.getNumRecords() > 0) {
store.closeRecordStore();
RecordStore.deleteRecordStore (storeName);
store = RecordStore.openRecordStore (storeName, true);
}
}
catch (Exception e) {
throw new RuntimeException (e.toString());
}
}
public void addString (String text) {
try {
byte[] data = text.getBytes();
if (size < store.getNumRecords())
store.setRecord (size+1, data, 0, data.length);
else
store.addRecord (data, 0, data.length);
size++;
}
catch (Exception e) {
throw new RuntimeException (e.toString());
}
}
public String stringAt (int index) {
try {
return new String (store.getRecord (index+1));
}
catch (Exception e) {
throw new RuntimeException (e.toString());
}
}
public void removeStringAt (int index) {
try {
for (int i = index; i < size-1; i++) {
byte[] data = store.getRecord (i+2);
store.setRecord (i+1, data, 0, data.length);
}
size--;
}
catch (Exception e) {
throw new RuntimeException (e.toString());
Search WWH ::




Custom Search