Skip to content

Commit

Permalink
Use an enum, instead of ints
Browse files Browse the repository at this point in the history
Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Jan 23, 2012
1 parent f878785 commit 1cdd680
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/io/CDKSourceCodeWriter.java
Expand Up @@ -244,15 +244,15 @@ public int getRequiredDataFeatures() {
}

private void initIOSettings() {
write2DCoordinates = new BooleanIOSetting("write2DCoordinates", IOSetting.LOW,
write2DCoordinates = new BooleanIOSetting("write2DCoordinates", IOSetting.Importance.LOW,
"Should 2D coordinates be added?",
"true");

write3DCoordinates = new BooleanIOSetting("write3DCoordinates", IOSetting.LOW,
write3DCoordinates = new BooleanIOSetting("write3DCoordinates", IOSetting.Importance.LOW,
"Should 3D coordinates be added?",
"true");

builder = new StringIOSetting("builder", IOSetting.LOW,
builder = new StringIOSetting("builder", IOSetting.Importance.LOW,
"Which IChemObjectBuilder should be used?",
"DefaultChemObjectBuilder");
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/org/openscience/cdk/io/CMLWriter.java
Expand Up @@ -292,31 +292,31 @@ public void write(IChemObject object) throws CDKException {
}

private void initIOSettings() {
cmlIds = new BooleanIOSetting("CMLIDs", IOSetting.LOW,
cmlIds = new BooleanIOSetting("CMLIDs", IOSetting.Importance.LOW,
"Should the output use CML identifiers?",
"true");

namespacedOutput = new BooleanIOSetting("NamespacedOutput", IOSetting.LOW,
namespacedOutput = new BooleanIOSetting("NamespacedOutput", IOSetting.Importance.LOW,
"Should the output use namespaced output?",
"true");

namespacePrefix = new StringIOSetting("NamespacePrefix", IOSetting.LOW,
namespacePrefix = new StringIOSetting("NamespacePrefix", IOSetting.Importance.LOW,
"What should the namespace prefix be? [empty is no prefix]",
"");

schemaInstanceOutput = new BooleanIOSetting("SchemaInstance", IOSetting.LOW,
schemaInstanceOutput = new BooleanIOSetting("SchemaInstance", IOSetting.Importance.LOW,
"Should the output use the Schema-Instance attribute?",
"false");

instanceLocation = new StringIOSetting("InstanceLocation", IOSetting.LOW,
instanceLocation = new StringIOSetting("InstanceLocation", IOSetting.Importance.LOW,
"Where is the schema found?",
"");

indent = new BooleanIOSetting("Indenting", IOSetting.LOW,
indent = new BooleanIOSetting("Indenting", IOSetting.Importance.LOW,
"Should the output be indented?",
"true");

xmlDeclaration = new BooleanIOSetting("XMLDeclaration", IOSetting.LOW,
xmlDeclaration = new BooleanIOSetting("XMLDeclaration", IOSetting.Importance.LOW,
"Should the output contain an XML declaration?",
"true");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/openscience/cdk/io/Gaussian98Reader.java
Expand Up @@ -548,7 +548,7 @@ private String parseLevelOfTheory(String line) {


private void initIOSettings() {
readOptimizedStructureOnly = new BooleanIOSetting("ReadOptimizedStructureOnly", IOSetting.LOW,
readOptimizedStructureOnly = new BooleanIOSetting("ReadOptimizedStructureOnly", IOSetting.Importance.LOW,
"Should I only read the optimized structure from a geometry optimization?",
"false");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/openscience/cdk/io/MDLReader.java
Expand Up @@ -581,7 +581,7 @@ public void close() throws IOException {
}

private void initIOSettings() {
forceReadAs3DCoords = new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.LOW,
forceReadAs3DCoords = new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.Importance.LOW,
"Should coordinates always be read as 3D?",
"false");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -944,10 +944,10 @@ public void close() throws IOException {
}

private void initIOSettings() {
forceReadAs3DCoords = new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.LOW,
forceReadAs3DCoords = new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.Importance.LOW,
"Should coordinates always be read as 3D?",
"false");
interpretHydrogenIsotopes = new BooleanIOSetting("InterpretHydrogenIsotopes", IOSetting.LOW,
interpretHydrogenIsotopes = new BooleanIOSetting("InterpretHydrogenIsotopes", IOSetting.Importance.LOW,
"Should D and T be interpreted as hydrogen isotopes?",
"true");
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/io/MDLV2000Writer.java
Expand Up @@ -557,19 +557,19 @@ protected static String formatMDLString(String s, int le) {
private void initIOSettings() {
forceWriteAs2DCoords = new BooleanIOSetting(
"ForceWriteAs2DCoordinates",
IOSetting.LOW,
IOSetting.Importance.LOW,
"Should coordinates always be written as 2D?",
"false"
);
writeAromaticBondTypes = new BooleanIOSetting(
"WriteAromaticBondTypes",
IOSetting.LOW,
IOSetting.Importance.LOW,
"Should aromatic bonds be written as bond type 4?",
"false"
);
writeQueryFormatValencies = new BooleanIOSetting(
"WriteQueryFormatValencies",
IOSetting.LOW,
IOSetting.Importance.LOW,
"Should valencies be written in the MDL Query format?",
"false"
);
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/io/PDBReader.java
Expand Up @@ -741,13 +741,13 @@ public void close() throws IOException {
}

private void initIOSettings() {
useRebondTool = new BooleanIOSetting("UseRebondTool", IOSetting.LOW,
useRebondTool = new BooleanIOSetting("UseRebondTool", IOSetting.Importance.LOW,
"Should the PDBReader deduce bonding patterns?",
"false");
readConnect = new BooleanIOSetting("ReadConnectSection", IOSetting.LOW,
readConnect = new BooleanIOSetting("ReadConnectSection", IOSetting.Importance.LOW,
"Should the CONECT be read?",
"true");
useHetDictionary = new BooleanIOSetting("UseHetDictionary", IOSetting.LOW,
useHetDictionary = new BooleanIOSetting("UseHetDictionary", IOSetting.Importance.LOW,
"Should the PDBReader use the HETATM dictionary for atom types?",
"false");
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/org/openscience/cdk/io/PDBWriter.java
Expand Up @@ -97,16 +97,16 @@ public PDBWriter(Writer out) {
}
} catch (Exception exc) {
}
writeAsHET = new BooleanIOSetting("WriteAsHET", IOSetting.LOW,
writeAsHET = new BooleanIOSetting("WriteAsHET", IOSetting.Importance.LOW,
"Should the output file use HETATM", "false");
useElementSymbolAsAtomName = new BooleanIOSetting(
"UseElementSymbolAsAtomName", IOSetting.LOW,
"UseElementSymbolAsAtomName", IOSetting.Importance.LOW,
"Should the element symbol be written as the atom name", "false");
writeCONECTRecords = new BooleanIOSetting("WriteCONECT", IOSetting.LOW,
writeCONECTRecords = new BooleanIOSetting("WriteCONECT", IOSetting.Importance.LOW,
"Should the bonds be written as CONECT records?", "true");
writeTERRecord = new BooleanIOSetting("WriteTER", IOSetting.LOW,
writeTERRecord = new BooleanIOSetting("WriteTER", IOSetting.Importance.LOW,
"Should a TER record be put at the end of the atoms?", "false");
writeENDRecord = new BooleanIOSetting("WriteEND", IOSetting.LOW,
writeENDRecord = new BooleanIOSetting("WriteEND", IOSetting.Importance.LOW,
"Should an END record be put at the end of the file?", "true");
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/org/openscience/cdk/io/SDFWriter.java
Expand Up @@ -253,7 +253,7 @@ private boolean isCDKInternalProperty(Object propKey) {

private void initIOSettings() {
writerProperties = new BooleanIOSetting("writeProperties",
IOSetting.LOW,
IOSetting.Importance.LOW,
"Should molecular properties be written?",
"true"
);
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/openscience/cdk/io/SMILESWriter.java
Expand Up @@ -195,7 +195,7 @@ public void writeAtomContainer(IAtomContainer molecule) {
private void initIOSettings() {
useAromaticityFlag = new BooleanIOSetting(
"UseAromaticity",
IOSetting.LOW,
IOSetting.Importance.LOW,
"Should aromaticity information be stored in the SMILES?",
"false"
);
Expand Down
Expand Up @@ -280,7 +280,7 @@ public void setReader(InputStream reader) {
}

private void initIOSettings() {
forceReadAs3DCoords = new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.LOW,
forceReadAs3DCoords = new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.Importance.LOW,
"Should coordinates always be read as 3D?",
"false");
}
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.openscience.cdk.io.ReaderEvent;
import org.openscience.cdk.io.setting.BooleanIOSetting;
import org.openscience.cdk.io.setting.IOSetting;
import org.openscience.cdk.io.setting.IOSetting.Importance;
import org.openscience.cdk.io.setting.OptionIOSetting;
import org.openscience.cdk.io.setting.StringIOSetting;

Expand All @@ -50,18 +51,18 @@
public class SwingGUIListener implements IReaderListener, IWriterListener {

private Component frame = null;
private int level = 0;
private Importance level = Importance.HIGH;

/**
* 0 = ask no questions
* 3 = ask all questions
*/
public SwingGUIListener(Component frame, int level) {
public SwingGUIListener(Component frame, Importance level) {
this.level = level;
this.frame = frame;
}

public void setLevel(int level) {
public void setLevel(Importance level) {
this.level = level;
}

Expand All @@ -77,7 +78,7 @@ public void frameRead(ReaderEvent event) {
*/
public void processIOSettingQuestion(IOSetting setting) {
// post the question
if (setting.getLevel() < this.level) {
if (setting.getLevel().ordinal() <= this.level.ordinal()) {
String answer = setting.getSetting();

if (setting instanceof BooleanIOSetting) {
Expand Down
13 changes: 5 additions & 8 deletions src/main/org/openscience/cdk/io/listener/TextGUIListener.java
Expand Up @@ -36,6 +36,7 @@
import org.openscience.cdk.io.ReaderEvent;
import org.openscience.cdk.io.setting.BooleanIOSetting;
import org.openscience.cdk.io.setting.IOSetting;
import org.openscience.cdk.io.setting.IOSetting.Importance;
import org.openscience.cdk.io.setting.OptionIOSetting;

/**
Expand All @@ -55,19 +56,15 @@ public class TextGUIListener implements IReaderListener, IWriterListener {
private BufferedReader in;
private PrintWriter out;

private int level = 0;
private Importance level = Importance.HIGH;

/**
* 0 = ask no questions
* 3 = ask all questions
*/
public TextGUIListener(int level) {
public TextGUIListener(Importance level) {
this.level = level;
this.setInputReader(new InputStreamReader(System.in));
this.setOutputWriter(new OutputStreamWriter(System.out));
}

public void setLevel(int level) {
public void setLevel(Importance level) {
this.level = level;
}

Expand Down Expand Up @@ -108,7 +105,7 @@ public void frameRead(ReaderEvent event) {}
*/
public void processIOSettingQuestion(IOSetting setting) {
// post the question
if (setting.getLevel() < this.level) {
if (setting.getLevel().ordinal() <= this.level.ordinal()) {
// output the option name
this.out.print("[" + setting.getName() + "]: ");
// post the question
Expand Down
16 changes: 8 additions & 8 deletions src/main/org/openscience/cdk/io/program/GaussianInputWriter.java
Expand Up @@ -239,42 +239,42 @@ private void initIOSettings() {
basisOptions.add("6-31g(d)");
basisOptions.add("6-311g");
basisOptions.add("6-311+g**");
basis = new OptionIOSetting("Basis", IOSetting.MEDIUM,
basis = new OptionIOSetting("Basis", IOSetting.Importance.MEDIUM,
"Which basis set do you want to use?", basisOptions, "6-31g");

List<String> methodOptions = new ArrayList<String>();
methodOptions.add("rb3lyp");
methodOptions.add("b3lyp");
methodOptions.add("rhf");
method = new OptionIOSetting("Method", IOSetting.MEDIUM,
method = new OptionIOSetting("Method", IOSetting.Importance.MEDIUM,
"Which method do you want to use?", methodOptions, "b3lyp");

List<String> commandOptions = new ArrayList<String>();
commandOptions.add("energy calculation");
commandOptions.add("geometry optimization");
commandOptions.add("IR frequency calculation");
commandOptions.add("IR frequency calculation (with Raman)");
command = new OptionIOSetting("Command", IOSetting.HIGH,
command = new OptionIOSetting("Command", IOSetting.Importance.HIGH,
"What kind of job do you want to perform?", commandOptions,
"energy calculation");

comment = new StringIOSetting("Comment", IOSetting.LOW,
comment = new StringIOSetting("Comment", IOSetting.Importance.LOW,
"What comment should be put in the file?",
"Created with CDK (http://cdk.sf.net/)");

memory = new StringIOSetting("Memory", IOSetting.LOW,
memory = new StringIOSetting("Memory", IOSetting.Importance.LOW,
"How much memory do you want to use?",
"unset");

shell = new BooleanIOSetting("OpenShell", IOSetting.MEDIUM,
shell = new BooleanIOSetting("OpenShell", IOSetting.Importance.MEDIUM,
"Should the calculation be open shell?",
"false");

proccount = new IntegerIOSetting("ProcessorCount", IOSetting.LOW,
proccount = new IntegerIOSetting("ProcessorCount", IOSetting.Importance.LOW,
"How many processors should be used by Gaussian?",
"1");

usecheckpoint = new BooleanIOSetting("UseCheckPointFile", IOSetting.LOW,
usecheckpoint = new BooleanIOSetting("UseCheckPointFile", IOSetting.Importance.LOW,
"Should a check point file be saved?",
"false");
}
Expand Down
Expand Up @@ -35,7 +35,7 @@
*/
public class BooleanIOSetting extends IOSetting {

public BooleanIOSetting(String name, int level,
public BooleanIOSetting(String name, Importance level,
String question, String defaultSetting) {
super(name, level, question, defaultSetting);
}
Expand Down
21 changes: 9 additions & 12 deletions src/main/org/openscience/cdk/io/setting/IOSetting.java
Expand Up @@ -36,16 +36,13 @@
*/
public abstract class IOSetting {

/** The levels available:
* HIGH important question
* MEDIUM
* LOW unimportant question
*/
public static final int HIGH = 0;
public static final int MEDIUM = 1;
public static final int LOW = 2;

protected int level;
public enum Importance {
HIGH,
MEDIUM,
LOW
}

protected Importance level;
protected String name;
protected String question;
protected String setting;
Expand All @@ -62,7 +59,7 @@ public abstract class IOSetting {
* @param defaultSetting The default setting, used if not overwritten
* by a user
*/
public IOSetting(String name, int level,
public IOSetting(String name, Importance level,
String question, String defaultSetting) {
this.level = level;
this.name = name;
Expand All @@ -82,7 +79,7 @@ public String getDefaultSetting() {
return this.setting;
}

public int getLevel() {
public Importance getLevel() {
return this.level;
}

Expand Down
Expand Up @@ -35,7 +35,7 @@
*/
public class IntegerIOSetting extends IOSetting {

public IntegerIOSetting(String name, int level,
public IntegerIOSetting(String name, Importance level,
String question, String defaultSetting) {
super(name, level, question, defaultSetting);
}
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class OptionIOSetting extends IOSetting {
* OptionIOSetting is IOSetting for which the value must be
* in the list of possible options.
*/
public OptionIOSetting(String name, int level,
public OptionIOSetting(String name, Importance level,
String question, List<String> settings,
String defaultSetting) {
super(name, level, question, defaultSetting);
Expand Down
Expand Up @@ -35,7 +35,7 @@
*/
public class StringIOSetting extends IOSetting {

public StringIOSetting(String name, int level,
public StringIOSetting(String name, Importance level,
String question, String defaultSetting) {
super(name, level, question, defaultSetting);
}
Expand Down

0 comments on commit 1cdd680

Please sign in to comment.