/* * GNTOptions.java * * Created on November 30, 2003, 6:51 PM */ package gnt; import java.io.*; import java.util.*; // can remove this later: import palm.conduit.*; /** * * @author Mike Kirschman */ public class GNTOptions { private int openFile = 0; private int openGraphics = 0xFFFF; private int numRecs = 0; private long optionsRecSize = 0; /** Creates a new instance of GNTOptions */ public GNTOptions() { } public boolean equals(Object o) { if (o == null) return false; GNTOptions opt = (GNTOptions) o; if (this.getOpenFile() != opt.getOpenFile()) return false; if (this.getOpenGraphics() != opt.getOpenGraphics()) return false; if (this.getNumRecs() != getNumRecs()) return false; return true; } public void readData(DataInputStream dataInputStream) throws IOException { setOpenFile(gnt.Util.readUInt16(dataInputStream)); setOpenGraphics(gnt.Util.readUInt16(dataInputStream)); setNumRecs(gnt.Util.readUInt16(dataInputStream)); setOptionsRecSize(gnt.Util.readUInt32(dataInputStream)); } public void writeData(DataOutputStream out) throws IOException { gnt.Util.writeUInt16(out, getOpenFile()); gnt.Util.writeUInt16(out, getOpenGraphics()); gnt.Util.writeUInt16(out, getNumRecs()); gnt.Util.writeUInt32(out, getOptionsRecSize()); } public void printRecord(PrintWriter out, String delimiter) throws IOException { out.print("openFileNumber=" + getOpenFile() + delimiter); out.print("openGraphicsNumber=" + getOpenGraphics() + delimiter); out.print("numberOfRecords=" + getNumRecs() + delimiter); out.print("optionsRecordSize=" + getOptionsRecSize() + delimiter); } public void readRecord(String data, String delimiter){ String nameValue; // Break out the individual fields inside this options section of the data String[] tokens = Util.split(data, delimiter); // Cycle through each field in the options for (int i = 0; i < tokens.length; i++) { nameValue = tokens[i]; int equalIdx = nameValue.indexOf('='); // call the appropriate method based on the name String name = nameValue.substring(0, equalIdx); if (name.equals("openFileNumber")) setOpenFile(Integer.parseInt(nameValue.substring(equalIdx + 1))); else if (name.equals("openGraphicsNumber")) setOpenGraphics(Integer.parseInt(nameValue.substring(equalIdx + 1))); else if (name.equals("numberOfRecords")) setNumRecs(Integer.parseInt(nameValue.substring(equalIdx + 1))); else if (name.equals("optionsRecordSize")) setOptionsRecSize(Long.parseLong(nameValue.substring(equalIdx + 1))); } } int getOpenFile() { return openFile; } int getOpenGraphics() { return openGraphics; } int getNumRecs() { return numRecs; } long getOptionsRecSize() { return optionsRecSize; } void setOpenFile(int openFile) { this.openFile = openFile; } void setOpenGraphics(int openGraphics) { this.openGraphics = this.openGraphics; } void setNumRecs(int numRecs) { this.numRecs = numRecs; } void setOptionsRecSize(long optionsRecSize) { this.optionsRecSize = optionsRecSize; } }