* Multiple sequence alignment.\r
* \r
* Does not give any guarantees on the content of individual FastaSequece\r
- * records. That is it does not guarantee that the neither the names of\r
- * sequences or the sequences themselves are unique.\r
+ * records. It does not guarantee neither the uniqueness of the names of\r
+ * sequences nor it guarantees the uniqueness of the sequences.\r
* \r
* @see FastaSequence\r
* @see AlignmentMetadata\r
* \r
* @author pvtroshin\r
* \r
- * Date September 2009\r
+ * @version 1.0 September 2009\r
* \r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
@Immutable\r
public final class Alignment {\r
\r
- private AlignmentMetadata metadata;\r
- private List<FastaSequence> sequences;\r
-\r
- private Alignment() {\r
- // This has to has a default constructor for JaxB\r
- }\r
-\r
- /**\r
- * @param sequences\r
- * @param program\r
- * @param gapchar\r
- */\r
- public Alignment(List<FastaSequence> sequences, Program program,\r
- char gapchar) {\r
- this.sequences = sequences;\r
- this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);\r
- }\r
-\r
- /**\r
- * \r
- * @param sequences\r
- * @param metadata\r
- */\r
- public Alignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {\r
- this.sequences = sequences;\r
- this.metadata = metadata;\r
- }\r
-\r
- /**\r
- * \r
- * @return list of FastaSequence records\r
- */\r
- public List<FastaSequence> getSequences() {\r
- return sequences;\r
- }\r
-\r
- /**\r
- * \r
- * @return a number of sequence in the alignment\r
- */\r
- public int getSize() {\r
- return this.sequences.size();\r
- }\r
-\r
- /**\r
- * \r
- * @return AlignmentMetadata object\r
- */\r
- public AlignmentMetadata getMetadata() {\r
- return metadata;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String sseq = "";\r
- for (FastaSequence fs : getSequences()) {\r
- sseq += fs.toString() + "\n";\r
+ private AlignmentMetadata metadata;\r
+ private List<FastaSequence> sequences;\r
+\r
+ private Alignment() {\r
+ // This has to has a default constructor for JaxB\r
}\r
- return sseq;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result\r
- + ((metadata == null) ? 0 : metadata.hashCode());\r
- result = prime * result\r
- + ((sequences == null) ? 0 : sequences.hashCode());\r
- return result;\r
- }\r
-\r
- /**\r
- * Please note that this implementation does not take the order of sequences\r
- * into account!\r
- */\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
+\r
+ /**\r
+ * @param sequences\r
+ * @param program\r
+ * @param gapchar\r
+ */\r
+ public Alignment(List<FastaSequence> sequences, Program program,\r
+ char gapchar) {\r
+ this.sequences = sequences;\r
+ this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);\r
}\r
- if (!(obj instanceof Alignment)) {\r
- return false;\r
+\r
+ /**\r
+ * \r
+ * @param sequences\r
+ * @param metadata\r
+ */\r
+ public Alignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {\r
+ this.sequences = sequences;\r
+ this.metadata = metadata;\r
}\r
- Alignment al = (Alignment) obj;\r
- if (this.getSize() != al.getSize()) {\r
- return false;\r
+\r
+ /**\r
+ * \r
+ * @return list of FastaSequence records\r
+ */\r
+ public List<FastaSequence> getSequences() {\r
+ return sequences;\r
}\r
- if (!this.getMetadata().equals(al.getMetadata())) {\r
- return false;\r
+\r
+ /**\r
+ * \r
+ * @return a number of sequence in the alignment\r
+ */\r
+ public int getSize() {\r
+ return this.sequences.size();\r
}\r
- int outerCounter = 0;\r
- int matchCounter = 0;\r
- for (FastaSequence fs : getSequences()) {\r
- outerCounter++;\r
- for (FastaSequence fs1 : al.getSequences()) {\r
- if (fs.equals(fs1)) {\r
- matchCounter++;\r
- continue;\r
+\r
+ /**\r
+ * \r
+ * @return AlignmentMetadata object\r
+ */\r
+ public AlignmentMetadata getMetadata() {\r
+ return metadata;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String sseq = "";\r
+ for (FastaSequence fs : getSequences()) {\r
+ sseq += fs.toString() + "\n";\r
}\r
- }\r
- // Match for at lease one element was not found!\r
- if (outerCounter != matchCounter) {\r
- return false;\r
- }\r
+ return sseq;\r
}\r
\r
- return true;\r
- }\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((metadata == null) ? 0 : metadata.hashCode());\r
+ result = prime * result\r
+ + ((sequences == null) ? 0 : sequences.hashCode());\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Please note that this implementation does not take the order of sequences\r
+ * into account!\r
+ */\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (!(obj instanceof Alignment)) {\r
+ return false;\r
+ }\r
+ Alignment al = (Alignment) obj;\r
+ if (this.getSize() != al.getSize()) {\r
+ return false;\r
+ }\r
+ if (!this.getMetadata().equals(al.getMetadata())) {\r
+ return false;\r
+ }\r
+ int outerCounter = 0;\r
+ int matchCounter = 0;\r
+ for (FastaSequence fs : getSequences()) {\r
+ outerCounter++;\r
+ for (FastaSequence fs1 : al.getSequences()) {\r
+ if (fs.equals(fs1)) {\r
+ matchCounter++;\r
+ continue;\r
+ }\r
+ }\r
+ // Match for at lease one element was not found!\r
+ if (outerCounter != matchCounter) {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ return true;\r
+ }\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date September 2009\r
+ * @version 1.0 September 2009\r
*/\r
@Immutable\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class AlignmentMetadata {\r
\r
- private Program program;\r
- private char gapchar;\r
+ private Program program;\r
+ private char gapchar;\r
\r
- private AlignmentMetadata() {\r
- // Default no args constructor required for JAXB\r
- }\r
-\r
- public AlignmentMetadata(Program program, char gapchar) {\r
- this.program = program;\r
- this.gapchar = gapchar;\r
- }\r
-\r
- public Program getProgram() {\r
- return program;\r
- }\r
-\r
- public char getGapchar() {\r
- return gapchar;\r
- }\r
+ private AlignmentMetadata() {\r
+ // Default no args constructor required for JAXB\r
+ }\r
\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
+ public AlignmentMetadata(Program program, char gapchar) {\r
+ this.program = program;\r
+ this.gapchar = gapchar;\r
}\r
- if (!(obj instanceof AlignmentMetadata)) {\r
- return false;\r
+\r
+ public Program getProgram() {\r
+ return program;\r
}\r
- AlignmentMetadata alm = (AlignmentMetadata) obj;\r
- if (alm.getProgram() != this.getProgram()) {\r
- return false;\r
+\r
+ public char getGapchar() {\r
+ return gapchar;\r
}\r
- if (alm.getGapchar() != this.getGapchar()) {\r
- return false;\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ if (!(obj instanceof AlignmentMetadata)) {\r
+ return false;\r
+ }\r
+ AlignmentMetadata alm = (AlignmentMetadata) obj;\r
+ if (alm.getProgram() != this.getProgram()) {\r
+ return false;\r
+ }\r
+ if (alm.getGapchar() != this.getGapchar()) {\r
+ return false;\r
+ }\r
+ return true;\r
}\r
- return true;\r
- }\r
\r
- @Override\r
- public int hashCode() {\r
- return getProgram().hashCode() * getGapchar() * 13;\r
- }\r
+ @Override\r
+ public int hashCode() {\r
+ return getProgram().hashCode() * getGapchar() * 13;\r
+ }\r
\r
}\r
-/*\r
- * Copyright (c) 2009 Peter Troshin JAva Bioinformatics Analysis Web Services\r
- * (JABAWS) @version: 1.0 This library is free software; you can redistribute it\r
- * and/or modify it under the terms of the Apache License version 2 as published\r
- * by the Apache Software Foundation This library is distributed in the hope\r
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * Apache License for more details. A copy of the license is in\r
- * apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt Any republication or\r
- * derived work distributed in source code form must include this copyright and\r
- * license notice.\r
+/* Copyright (c) 2009 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
*/\r
\r
package compbio.data.sequence;\r
* \r
* @author Petr Troshin based on jimp class\r
* \r
- * Date September 2009\r
+ * @version 1.0 September 2009\r
* \r
*/\r
public final class ClustalAlignmentUtil {\r
// display at most 30 characters in the name, keep the names\r
// 6 spaces away from the alignment for longest sequence names,\r
// and more than this for shorter names\r
- out.format("%-" + maxidLength + "s" + spacer,\r
+ out.format(\r
+ "%-" + maxidLength + "s" + spacer,\r
(name.length() > maxNameLength ? name.substring(0,\r
maxidLength) : name));\r
int start = i * oneLineAlignmentLength;\r
\r
/**\r
* A FASTA formatted sequence. Please note that this class does not make any\r
- * assumptions as to what sequence it store e.g. it could be nucleotide, protein\r
- * or even gapped alignment sequence! The only guarantee it makes is that the\r
- * sequence does not contain white space characters e.g. spaces, new lines etc\r
+ * assumptions as to what sequence it stores e.g. it could be nucleotide,\r
+ * protein or even gapped alignment sequence! The only guarantee it makes is\r
+ * that the sequence does not contain white space characters e.g. spaces, new\r
+ * lines etc\r
* \r
* @author pvtroshin\r
* \r
- * Date September 2009\r
+ * @version 1.0 September 2009\r
*/\r
\r
@XmlAccessorType(XmlAccessType.FIELD)\r
package compbio.data.sequence;\r
\r
/**\r
- * Programmes that can produce alignments\r
+ * The list of programmes that can produce alignments\r
* \r
* @author pvtroshin\r
* \r
*/\r
public enum Program {\r
\r
- /**\r
- * ClustalW\r
- */\r
- CLUSTAL,\r
+ /**\r
+ * ClustalW\r
+ */\r
+ CLUSTAL,\r
\r
- /**\r
- * Mafft\r
- */\r
- MAFFT,\r
+ /**\r
+ * Mafft\r
+ */\r
+ MAFFT,\r
\r
- /**\r
- * Muscle\r
- */\r
- MUSCLE,\r
+ /**\r
+ * Muscle\r
+ */\r
+ MUSCLE,\r
\r
- /**\r
- * Tcoffee\r
- */\r
- Tcoffee,\r
+ /**\r
+ * Tcoffee\r
+ */\r
+ Tcoffee,\r
\r
- /**\r
- * Probcons\r
- */\r
- Probcons\r
+ /**\r
+ * Probcons\r
+ */\r
+ Probcons\r
}\r
/**\r
- * A data model for multiple sequence alignment web services \r
+ * A data model for multiple sequence alignment web services and utility methods\r
+ * that work on the objects of this model. \r
* Classes in this package have no dependencies to other sources in the project. \r
- * They form a base layer of Jalview Web Services v2. \r
+ * They form a base layer of JAva Bioinformatics Analysis Web Services. \r
* \r
* @author Petr Troshin \r
- * \r
- * Date January 2010\r
+ * @version 1.0 January 2010\r
* \r
* \r
*/\r
import javax.xml.bind.annotation.XmlAccessorType;\r
\r
/**\r
- * Represents a chunk of string data together with the position in a file from\r
- * where corresponding to of the data.\r
+ * Represents a chunk of a string data together with the position in a file for\r
+ * the next read operation.\r
* \r
* @author pvtroshin\r
* \r
- * Date December 2009\r
+ * @version 1.0 December 2009\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class ChunkHolder {\r
\r
- String chunk;\r
- long position;\r
+ String chunk;\r
+ long position;\r
\r
- private ChunkHolder() {\r
- // JaxB default constructor\r
- // should not be used otherwise\r
- }\r
-\r
- public ChunkHolder(String chunk, long position) {\r
- if (position < 0) {\r
- throw new IndexOutOfBoundsException(\r
- "Position in a file could not be negative! Given value: "\r
- + position);\r
- }\r
- if (chunk == null) {\r
- throw new NullPointerException("Chunk must not be NULL!");\r
+ private ChunkHolder() {\r
+ // JaxB default constructor\r
+ // should not be used otherwise\r
}\r
- this.chunk = chunk;\r
- this.position = position;\r
- }\r
-\r
- public String getChunk() {\r
- return chunk;\r
- }\r
\r
- public long getNextPosition() {\r
- return position;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
+ public ChunkHolder(String chunk, long position) {\r
+ if (position < 0) {\r
+ throw new IndexOutOfBoundsException(\r
+ "Position in a file could not be negative! Given value: "\r
+ + position);\r
+ }\r
+ if (chunk == null) {\r
+ throw new NullPointerException("Chunk must not be NULL!");\r
+ }\r
+ this.chunk = chunk;\r
+ this.position = position;\r
}\r
- ChunkHolder ch = null;\r
- if (!(obj instanceof ChunkHolder)) {\r
- ch = (ChunkHolder) obj;\r
+\r
+ public String getChunk() {\r
+ return chunk;\r
}\r
- if (this.position != ch.position) {\r
- return false;\r
+\r
+ public long getNextPosition() {\r
+ return position;\r
}\r
- if (!this.chunk.equals(ch.chunk)) {\r
- return false;\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ ChunkHolder ch = null;\r
+ if (!(obj instanceof ChunkHolder)) {\r
+ ch = (ChunkHolder) obj;\r
+ }\r
+ if (this.position != ch.position) {\r
+ return false;\r
+ }\r
+ if (!this.chunk.equals(ch.chunk)) {\r
+ return false;\r
+ }\r
+ return true;\r
}\r
- return true;\r
- }\r
\r
- @Override\r
- public String toString() {\r
- String value = "Position: " + position + "\n";\r
- value += "Chunk size: " + chunk.length() + "\n";\r
- value += "Chunk: " + chunk + "\n";\r
- return value;\r
- }\r
+ @Override\r
+ public String toString() {\r
+ String value = "Position: " + position + "\n";\r
+ value += "Chunk size: " + chunk.length() + "\n";\r
+ value += "Chunk: " + chunk + "\n";\r
+ return value;\r
+ }\r
\r
- @Override\r
- public int hashCode() {\r
- return new Long(position + chunk.hashCode()).intValue();\r
- }\r
+ @Override\r
+ public int hashCode() {\r
+ return new Long(position + chunk.hashCode()).intValue();\r
+ }\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date October 2009\r
+ * @version 1.0 October 2009\r
*/\r
public class JobExecutionException extends Exception {\r
\r
- /**\r
- * Default stable serial for serialization\r
- */\r
- private static final long serialVersionUID = -5477751361755778769L;\r
+ /**\r
+ * Default stable serial for serialization\r
+ */\r
+ private static final long serialVersionUID = -5477751361755778769L;\r
\r
- public JobExecutionException(String message) {\r
- super(message);\r
- }\r
+ public JobExecutionException(String message) {\r
+ super(message);\r
+ }\r
\r
- public JobExecutionException(Throwable cause) {\r
- super(cause);\r
- }\r
+ public JobExecutionException(Throwable cause) {\r
+ super(cause);\r
+ }\r
\r
- public JobExecutionException(String message, Throwable cause) {\r
- super(message, cause);\r
- }\r
+ public JobExecutionException(String message, Throwable cause) {\r
+ super(message, cause);\r
+ }\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date October 2009\r
+ * @version 1.0 October 2009\r
*/\r
public enum JobStatus {\r
\r
- /**\r
- * Jobs which are in the queue and awaiting execution reported for cluster\r
- * jobs only\r
- */\r
- PENDING,\r
+ /**\r
+ * Jobs which are in the queue and awaiting execution reported for cluster\r
+ * jobs only\r
+ */\r
+ PENDING,\r
\r
- /**\r
- * Jobs that are running\r
- */\r
- RUNNING,\r
+ /**\r
+ * Jobs that are running\r
+ */\r
+ RUNNING,\r
\r
- /**\r
- * Jobs that has been cancelled\r
- */\r
- CANCELLED,\r
+ /**\r
+ * Jobs that has been cancelled\r
+ */\r
+ CANCELLED,\r
\r
- /**\r
- * Finished jobs\r
- */\r
- FINISHED,\r
+ /**\r
+ * Finished jobs\r
+ */\r
+ FINISHED,\r
\r
- /**\r
- * Failed jobs\r
- */\r
- FAILED,\r
+ /**\r
+ * Failed jobs\r
+ */\r
+ FAILED,\r
\r
- /**\r
- * Represents jobs with unknown status\r
- */\r
- UNDEFINED,\r
+ /**\r
+ * Represents jobs with unknown status\r
+ */\r
+ UNDEFINED,\r
\r
- // These relates to the status recorded on the file system\r
- /**\r
- * Job calculation has been started. First status reported by the local\r
- * engine\r
- */\r
- STARTED,\r
+ // These relates to the status recorded on the file system\r
+ /**\r
+ * Job calculation has been started. First status reported by the local\r
+ * engine\r
+ */\r
+ STARTED,\r
\r
- /**\r
- * Job has been submitted. This status is only set for cluster jobs\r
- */\r
- SUBMITTED,\r
+ /**\r
+ * Job has been submitted. This status is only set for cluster jobs\r
+ */\r
+ SUBMITTED,\r
\r
- /**\r
- * Results has been collected\r
- */\r
- COLLECTED\r
+ /**\r
+ * Results has been collected\r
+ */\r
+ COLLECTED\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date January 2010\r
+ * @version 1.0 January 2010\r
* \r
* @param <T>\r
* the type of an executable for which this limit is defined.\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class Limit<T> {\r
\r
- private String preset;\r
- private int seqNumber;\r
- private int seqLength;\r
+ private String preset;\r
+ private int seqNumber;\r
+ private int seqLength;\r
\r
- @XmlAttribute\r
- boolean isDefault;\r
+ @XmlAttribute\r
+ boolean isDefault;\r
\r
- private Limit() {\r
- // JAXB default constructor\r
- }\r
+ private Limit() {\r
+ // JAXB default constructor\r
+ }\r
\r
- public Limit(int seqNumber, int seqLength, String preset) {\r
- if (seqNumber <= 0) {\r
- throw new IllegalArgumentException(\r
- "seqNumber - a maximum number of sequences to align must be greater than 0. Value given:"\r
- + seqNumber);\r
+ public Limit(int seqNumber, int seqLength, String preset) {\r
+ if (seqNumber <= 0) {\r
+ throw new IllegalArgumentException(\r
+ "seqNumber - a maximum number of sequences to align must be greater than 0. Value given:"\r
+ + seqNumber);\r
+ }\r
+ if (seqLength <= 0) {\r
+ throw new IllegalArgumentException(\r
+ "seqLength - an average sequence length must be greater than 0. Value given:"\r
+ + seqLength);\r
+ }\r
+ this.seqNumber = seqNumber;\r
+ this.seqLength = seqLength;\r
+ this.preset = preset;\r
+ this.isDefault = false;\r
}\r
- if (seqLength <= 0) {\r
- throw new IllegalArgumentException(\r
- "seqLength - an average sequence length must be greater than 0. Value given:"\r
- + seqLength);\r
+\r
+ public Limit(int seqNumber, int seqLength, String preset, boolean isDefault) {\r
+ this(seqNumber, seqNumber, preset);\r
+ this.isDefault = isDefault;\r
}\r
- this.seqNumber = seqNumber;\r
- this.seqLength = seqLength;\r
- this.preset = preset;\r
- this.isDefault = false;\r
- }\r
-\r
- public Limit(int seqNumber, int seqLength, String preset, boolean isDefault) {\r
- this(seqNumber, seqNumber, preset);\r
- this.isDefault = isDefault;\r
- }\r
-\r
- public String getPreset() {\r
- return preset;\r
- }\r
-\r
- public int getAvgSeqLength() {\r
- return seqLength;\r
- }\r
-\r
- public int getSeqNumber() {\r
- return seqNumber;\r
- }\r
-\r
- public boolean isDefault() {\r
- return isDefault;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((preset == null) ? 0 : preset.hashCode());\r
- result = prime * result + seqLength;\r
- result = prime * result + seqNumber;\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- Limit other = (Limit) obj;\r
- if (preset == null) {\r
- if (other.preset != null)\r
- return false;\r
- } else if (!preset.equals(other.preset))\r
- return false;\r
- if (seqLength != other.seqLength)\r
- return false;\r
- if (seqNumber != other.seqNumber)\r
- return false;\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "";\r
- if (isDefault) {\r
- value = "Default Limit" + SysPrefs.newlinechar;\r
- } else {\r
- value = "Limit for Preset '" + preset + "'" + SysPrefs.newlinechar;\r
+\r
+ public String getPreset() {\r
+ return preset;\r
+ }\r
+\r
+ public int getAvgSeqLength() {\r
+ return seqLength;\r
}\r
- value += "Maximum sequence number=" + seqNumber + SysPrefs.newlinechar;\r
- value += "Average sequence length=" + seqLength + SysPrefs.newlinechar;\r
- value += SysPrefs.newlinechar;\r
- return value;\r
- }\r
-\r
- long numberOfLetters() {\r
- return this.seqNumber * this.seqLength;\r
- }\r
-\r
- /**\r
- * Checks if the number of sequences or their average length in the dataset\r
- * exceeds limits the values defined by this Limit\r
- * \r
- * @param data\r
- * @return true if a limit is exceeded (what is the dataset is larger then\r
- * the limit), false otherwise.\r
- */\r
- public boolean isExceeded(List<FastaSequence> data) {\r
- if (data == null) {\r
- throw new NullPointerException(\r
- "List of fasta sequences is expected!");\r
+\r
+ public int getSeqNumber() {\r
+ return seqNumber;\r
}\r
- if (data.size() > this.seqNumber) {\r
- return true;\r
+\r
+ public boolean isDefault() {\r
+ return isDefault;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result + ((preset == null) ? 0 : preset.hashCode());\r
+ result = prime * result + seqLength;\r
+ result = prime * result + seqNumber;\r
+ return result;\r
}\r
- if (this.seqLength != 0) {\r
- if ((long) getAvgSeqLength() * data.size() > numberOfLetters()) {\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ Limit other = (Limit) obj;\r
+ if (preset == null) {\r
+ if (other.preset != null)\r
+ return false;\r
+ } else if (!preset.equals(other.preset))\r
+ return false;\r
+ if (seqLength != other.seqLength)\r
+ return false;\r
+ if (seqNumber != other.seqNumber)\r
+ return false;\r
return true;\r
- }\r
}\r
- return false;\r
- }\r
-\r
- /**\r
- * Calculates an average sequence length of the dataset\r
- * \r
- * @param data\r
- * @return an average sequence length in the input dataset\r
- */\r
- public static int getAvgSequenceLength(List<FastaSequence> data) {\r
- long length = 0;\r
- for (FastaSequence seq : data) {\r
- length += seq.getLength();\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "";\r
+ if (isDefault) {\r
+ value = "Default Limit" + SysPrefs.newlinechar;\r
+ } else {\r
+ value = "Limit for Preset '" + preset + "'" + SysPrefs.newlinechar;\r
+ }\r
+ value += "Maximum sequence number=" + seqNumber + SysPrefs.newlinechar;\r
+ value += "Average sequence length=" + seqLength + SysPrefs.newlinechar;\r
+ value += SysPrefs.newlinechar;\r
+ return value;\r
}\r
- return (int) (length / data.size());\r
- }\r
-\r
- void validate() {\r
- if (this.seqNumber < 1) {\r
- throw new AssertionError(\r
- "Maximum number of sequences must be defined and be positive! Set value is: "\r
- + this.seqNumber);\r
+\r
+ long numberOfLetters() {\r
+ return this.seqNumber * this.seqLength;\r
}\r
- if (this.seqLength != 0 && this.seqLength < 1) {\r
- throw new AssertionError(\r
- "Average sequence length must be positive! Set value is: "\r
- + this.seqLength);\r
+\r
+ /**\r
+ * Checks if the number of sequences or their average length in the dataset\r
+ * exceeds limits the values defined by this Limit\r
+ * \r
+ * @param data\r
+ * @return true if a limit is exceeded (what is the dataset is larger then\r
+ * the limit), false otherwise.\r
+ */\r
+ public boolean isExceeded(List<FastaSequence> data) {\r
+ if (data == null) {\r
+ throw new NullPointerException(\r
+ "List of fasta sequences is expected!");\r
+ }\r
+ if (data.size() > this.seqNumber) {\r
+ return true;\r
+ }\r
+ if (this.seqLength != 0) {\r
+ if ((long) getAvgSeqLength() * data.size() > numberOfLetters()) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * Calculates an average sequence length of the dataset\r
+ * \r
+ * @param data\r
+ * @return an average sequence length in the input dataset\r
+ */\r
+ public static int getAvgSequenceLength(List<FastaSequence> data) {\r
+ long length = 0;\r
+ for (FastaSequence seq : data) {\r
+ length += seq.getLength();\r
+ }\r
+ return (int) (length / data.size());\r
+ }\r
+\r
+ void validate() {\r
+ if (this.seqNumber < 1) {\r
+ throw new AssertionError(\r
+ "Maximum number of sequences must be defined and be positive! Set value is: "\r
+ + this.seqNumber);\r
+ }\r
+ if (this.seqLength != 0 && this.seqLength < 1) {\r
+ throw new AssertionError(\r
+ "Average sequence length must be positive! Set value is: "\r
+ + this.seqLength);\r
+ }\r
}\r
- }\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date February 2010\r
+ * @version 1.0 February 2010\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class LimitExceededException extends JobSubmissionException {\r
\r
- private static final long serialVersionUID = 15066952180013505L;\r
+ private static final long serialVersionUID = 15066952180013505L;\r
\r
- int numberOfSequencesAllowed;\r
- int actualNumberofSequences;\r
- int aSequenceLenghtAllowed;\r
- int aSequenceLenghtActual;\r
+ int numberOfSequencesAllowed;\r
+ int actualNumberofSequences;\r
+ int aSequenceLenghtAllowed;\r
+ int aSequenceLenghtActual;\r
\r
- public LimitExceededException(String message) {\r
- super(message);\r
- }\r
-\r
- public static LimitExceededException newLimitExceeded(Limit<?> limit,\r
- List<FastaSequence> seqs) {\r
- String message = "Job exceed size limits, maximum number of sequences must be less than "\r
- + limit.getSeqNumber() + "\n";\r
- if (limit.getAvgSeqLength() != 0) {\r
- message += "and an average sequence length must not exceed "\r
- + limit.getAvgSeqLength() + "\n";\r
+ public LimitExceededException(String message) {\r
+ super(message);\r
}\r
- message += " However, the task contained " + seqs.size()\r
- + " sequences " + "\n";\r
- if (limit.getAvgSeqLength() != 0) {\r
- message += "and an average sequence length was "\r
- + Limit.getAvgSequenceLength(seqs) + "\n";\r
+\r
+ public static LimitExceededException newLimitExceeded(Limit<?> limit,\r
+ List<FastaSequence> seqs) {\r
+ String message = "Job exceed size limits, maximum number of sequences must be less than "\r
+ + limit.getSeqNumber() + "\n";\r
+ if (limit.getAvgSeqLength() != 0) {\r
+ message += "and an average sequence length must not exceed "\r
+ + limit.getAvgSeqLength() + "\n";\r
+ }\r
+ message += " However, the task contained " + seqs.size()\r
+ + " sequences " + "\n";\r
+ if (limit.getAvgSeqLength() != 0) {\r
+ message += "and an average sequence length was "\r
+ + Limit.getAvgSequenceLength(seqs) + "\n";\r
+ }\r
+ return new LimitExceededException(message);\r
}\r
- return new LimitExceededException(message);\r
- }\r
\r
- public int getNumberOfSequencesAllowed() {\r
- return numberOfSequencesAllowed;\r
- }\r
+ public int getNumberOfSequencesAllowed() {\r
+ return numberOfSequencesAllowed;\r
+ }\r
\r
- public int getActualNumberofSequences() {\r
- return actualNumberofSequences;\r
- }\r
+ public int getActualNumberofSequences() {\r
+ return actualNumberofSequences;\r
+ }\r
\r
- public int getSequenceLenghtAllowed() {\r
- return aSequenceLenghtAllowed;\r
- }\r
+ public int getSequenceLenghtAllowed() {\r
+ return aSequenceLenghtAllowed;\r
+ }\r
\r
- public int getSequenceLenghtActual() {\r
- return aSequenceLenghtActual;\r
- }\r
+ public int getSequenceLenghtActual() {\r
+ return aSequenceLenghtActual;\r
+ }\r
}\r
* @see Limit\r
* @author pvtroshin\r
* \r
- * Date January 2010\r
+ * @version 1.0 January 2010\r
* @param <T>\r
* executable type\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class LimitsManager<T> {\r
\r
- String runnerClassName;\r
- List<Limit<T>> limit;\r
+ String runnerClassName;\r
+ List<Limit<T>> limit;\r
\r
- /**\r
- * \r
- * @return all limits defined for an executable T\r
- */\r
- public List<Limit<T>> getLimits() {\r
- return limit;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "LimitsManager [limits=" + limit + ", runnerClassName="\r
- + runnerClassName + "]";\r
- }\r
-\r
- /**\r
- * \r
- * @param presetName\r
- * @return Limit defined for the executable T and presetName. If no limit is\r
- * defined for the presetName then default Limit is returned. If\r
- * presetName is empty or null than the default Limit will be\r
- * returned. If not limit defined for the type T than NULL will be\r
- * returned\r
- */\r
- public Limit<T> getLimitByName(String presetName) {\r
- if (Util.isEmpty(presetName)) {\r
- // return default limit\r
- return getDefaultLimit();\r
- }\r
- for (Limit<T> lim : limit) {\r
- String preset = lim.getPreset();\r
- if (preset == null) {\r
- continue;\r
- }\r
- if (preset.equalsIgnoreCase(presetName)) {\r
- return lim;\r
- }\r
+ /**\r
+ * \r
+ * @return all limits defined for an executable T\r
+ */\r
+ public List<Limit<T>> getLimits() {\r
+ return limit;\r
}\r
- return null;\r
- }\r
\r
- /**\r
- * \r
- * @return the default Limit for an executable type T\r
- */\r
- public Limit<T> getDefaultLimit() {\r
- for (Limit<T> lim : limit) {\r
- if (lim.isDefault) {\r
- return lim;\r
- }\r
+ @Override\r
+ public String toString() {\r
+ return "LimitsManager [limits=" + limit + ", runnerClassName="\r
+ + runnerClassName + "]";\r
}\r
- return null;\r
- }\r
\r
- /**\r
- * Validate Limits\r
- * \r
- * @see Limit\r
- * @see Preset\r
- * @param presets\r
- * @throws ValidationException\r
- * if any of the Limit defined is found to be invalid. That is\r
- * when\r
- * \r
- * 1) No default limit is defined\r
- * \r
- * 2) More than 1 default limit is defined\r
- * \r
- * 3) Limit's preset name does not match any presets for type T\r
- */\r
- public void validate(PresetManager<T> presets) throws ValidationException {\r
- int defaults = 0;\r
- for (Limit<T> lim : limit) {\r
- if (lim.isDefault) {\r
- defaults++;\r
- }\r
- }\r
- if (defaults == 0) {\r
- throw new ValidationException("Default limit is not set!");\r
+ /**\r
+ * \r
+ * @param presetName\r
+ * @return Limit defined for the executable T and presetName. If no limit is\r
+ * defined for the presetName then default Limit is returned. If\r
+ * presetName is empty or null than the default Limit will be\r
+ * returned. If not limit defined for the type T than NULL will be\r
+ * returned\r
+ */\r
+ public Limit<T> getLimitByName(String presetName) {\r
+ if (Util.isEmpty(presetName)) {\r
+ // return default limit\r
+ return getDefaultLimit();\r
+ }\r
+ for (Limit<T> lim : limit) {\r
+ String preset = lim.getPreset();\r
+ if (preset == null) {\r
+ continue;\r
+ }\r
+ if (preset.equalsIgnoreCase(presetName)) {\r
+ return lim;\r
+ }\r
+ }\r
+ return null;\r
}\r
- if (defaults > 1) {\r
- throw new ValidationException(\r
- "Default limit is set more than once!");\r
+\r
+ /**\r
+ * \r
+ * @return the default Limit for an executable type T\r
+ */\r
+ public Limit<T> getDefaultLimit() {\r
+ for (Limit<T> lim : limit) {\r
+ if (lim.isDefault) {\r
+ return lim;\r
+ }\r
+ }\r
+ return null;\r
}\r
- if (presets != null) {\r
- for (Limit<T> lim : limit) {\r
- lim.validate();\r
- String presetName = lim.getPreset();\r
- // skip "special" preset\r
- if (presetName != null\r
- && !presetName\r
- .equals(PresetManager.LOCAL_ENGINE_LIMIT_PRESET)) {\r
- Preset<T> preset = presets.getPresetByName(presetName);\r
- if (preset == null) {\r
- throw new ValidationException("Preset " + presetName\r
- + " is not found!");\r
- }\r
+\r
+ /**\r
+ * Validate Limits\r
+ * \r
+ * @see Limit\r
+ * @see Preset\r
+ * @param presets\r
+ * @throws ValidationException\r
+ * if any of the Limit defined is found to be invalid. That is\r
+ * when\r
+ * \r
+ * 1) No default limit is defined\r
+ * \r
+ * 2) More than 1 default limit is defined\r
+ * \r
+ * 3) Limit's preset name does not match any presets for type T\r
+ */\r
+ public void validate(PresetManager<T> presets) throws ValidationException {\r
+ int defaults = 0;\r
+ for (Limit<T> lim : limit) {\r
+ if (lim.isDefault) {\r
+ defaults++;\r
+ }\r
+ }\r
+ if (defaults == 0) {\r
+ throw new ValidationException("Default limit is not set!");\r
+ }\r
+ if (defaults > 1) {\r
+ throw new ValidationException(\r
+ "Default limit is set more than once!");\r
+ }\r
+ if (presets != null) {\r
+ for (Limit<T> lim : limit) {\r
+ lim.validate();\r
+ String presetName = lim.getPreset();\r
+ // skip "special" preset\r
+ if (presetName != null\r
+ && !presetName\r
+ .equals(PresetManager.LOCAL_ENGINE_LIMIT_PRESET)) {\r
+ Preset<T> preset = presets.getPresetByName(presetName);\r
+ if (preset == null) {\r
+ throw new ValidationException("Preset " + presetName\r
+ + " is not found!");\r
+ }\r
+ }\r
+ }\r
}\r
- }\r
}\r
- }\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date October 2009\r
+ * @version 1.0 October 2009\r
* @param <T>\r
* type of executable\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class Option<T> implements Argument<T> {\r
\r
- @XmlElement(required = true)\r
- protected String description;\r
-\r
- @XmlElement(required = true)\r
- Set<String> optionNames = new HashSet<String>();\r
-\r
- @XmlElement(required = true)\r
- protected String name;\r
-\r
- @XmlAttribute\r
- protected boolean isRequired;\r
- @XmlElement\r
- protected URL furtherDetails;\r
- @XmlElement\r
- protected String defaultValue;\r
-\r
- Option() {\r
- // Has to have no arg constructor for JAXB\r
- }\r
-\r
- public Option(String name, String description) {\r
- this.name = name;\r
- this.description = description;\r
- }\r
-\r
- /**\r
- * Human readable name of the option\r
- */\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- /**\r
- * A long description of the Option\r
- */\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- /**\r
- * The URL where further details about the option can be found\r
- */\r
- public URL getFurtherDetails() {\r
- return furtherDetails;\r
- }\r
-\r
- public void setFurtherDetails(URL furtherDetails) {\r
- this.furtherDetails = furtherDetails;\r
- }\r
-\r
- /**\r
- * A default value of the option. Defaults to command line argument name\r
- * e.g. -auto\r
- */\r
- public String getDefaultValue() {\r
- return defaultValue;\r
- }\r
-\r
- /**\r
- * Sets one of the values defined in optionList as default. Attempting set\r
- * the value not listed there will result in WrongParameter exception\r
- * \r
- * @param defaultVal\r
- * @throws WrongParameterException\r
- * is thrown if the defaultValue is not found in optionList\r
- */\r
- public void setDefaultValue(String defaultVal)\r
- throws WrongParameterException {\r
- if (optionNames.isEmpty()) {\r
- throw new IllegalStateException("Please define optionNames first!");\r
+ @XmlElement(required = true)\r
+ protected String description;\r
+\r
+ @XmlElement(required = true)\r
+ Set<String> optionNames = new HashSet<String>();\r
+\r
+ @XmlElement(required = true)\r
+ protected String name;\r
+\r
+ @XmlAttribute\r
+ protected boolean isRequired;\r
+ @XmlElement\r
+ protected URL furtherDetails;\r
+ @XmlElement\r
+ protected String defaultValue;\r
+\r
+ Option() {\r
+ // Has to have no arg constructor for JAXB\r
}\r
- if (!valueExist(defaultVal, getOptionNames())) {\r
- throw new WrongParameterException(\r
- "Attempting to set illegal defaultValue '" + defaultVal\r
- + "' which is not defined optionNames for option: "\r
- + this);\r
+\r
+ public Option(String name, String description) {\r
+ this.name = name;\r
+ this.description = description;\r
}\r
- this.defaultValue = defaultVal;\r
- }\r
\r
- static boolean valueExist(String testValue, List<String> values) {\r
- assert !Util.isEmpty(testValue);\r
- for (String val : values) {\r
- if (testValue.equalsIgnoreCase(val)) {\r
- return true;\r
- }\r
+ /**\r
+ * Human readable name of the option\r
+ */\r
+ public String getName() {\r
+ return name;\r
}\r
- return false;\r
- }\r
-\r
- /**\r
- * Flag that indicated that this option must be specified in the command\r
- * line for an executable to run\r
- * \r
- * @return true is the option is required, false otherwise\r
- */\r
- public boolean isRequired() {\r
- return isRequired;\r
- }\r
-\r
- public void setRequired(boolean isRequired) {\r
- this.isRequired = isRequired;\r
- }\r
-\r
- /**\r
- * \r
- * @return List of option names\r
- */\r
- public List<String> getOptionNames() {\r
- return new ArrayList<String>(optionNames);\r
- }\r
-\r
- public void setOptionNames(Set<String> optionNames) {\r
- this.optionNames = new HashSet<String>(optionNames);\r
- }\r
-\r
- /**\r
- * Adds an option to the optionName list\r
- * \r
- * @param value\r
- * @return modified optionName list\r
- */\r
- public Set<String> addOptionNames(String... value) {\r
- for (String v : value) {\r
- boolean added = this.optionNames.add(v);\r
- assert added : "Duplicated optionName is detected!";\r
+\r
+ public void setName(String name) {\r
+ this.name = name;\r
}\r
- return this.optionNames;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "Option name: " + this.name + SysPrefs.newlinechar;\r
- value += "Description: " + this.description + SysPrefs.newlinechar;\r
- if (!Util.isEmpty(defaultValue)) {\r
- value += "Default value: " + this.defaultValue\r
- + SysPrefs.newlinechar;\r
+\r
+ /**\r
+ * A long description of the Option\r
+ */\r
+ public String getDescription() {\r
+ return description;\r
}\r
- value += "URL: " + this.furtherDetails + SysPrefs.newlinechar;\r
- value += "Is required: " + this.isRequired + SysPrefs.newlinechar;\r
- if (!this.optionNames.isEmpty()) {\r
- Set<String> sortedPosval = new TreeSet<String>(this.optionNames);\r
- value += "Option Names: " + SysPrefs.newlinechar;\r
- for (String val : sortedPosval) {\r
- value += val + SysPrefs.newlinechar;\r
- }\r
+\r
+ public void setDescription(String description) {\r
+ this.description = description;\r
}\r
- return value;\r
- }\r
-\r
- /**\r
- * Convert the option to the command string.\r
- * \r
- * @return If only one optionName is defined, than it is returned, if many\r
- * option names are defined, then the defaultValue is returned.\r
- * Option must have a default value if there are many optionNames to\r
- * be valid.\r
- */\r
- public String toCommand(String nameValueSeparator) {\r
- if (optionNames.size() == 1) {\r
- return optionNames.iterator().next();\r
+\r
+ /**\r
+ * The URL where further details about the option can be found\r
+ */\r
+ public URL getFurtherDetails() {\r
+ return furtherDetails;\r
}\r
- return getDefaultValue();\r
- }\r
\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
+ public void setFurtherDetails(URL furtherDetails) {\r
+ this.furtherDetails = furtherDetails;\r
}\r
- Option<?> objArg = null;\r
- if (obj instanceof Option<?>) {\r
- objArg = (Option<?>) obj;\r
- } else {\r
- return false;\r
+\r
+ /**\r
+ * A default value of the option. Defaults to command line argument name\r
+ * e.g. -auto\r
+ */\r
+ public String getDefaultValue() {\r
+ return defaultValue;\r
}\r
- if (!Util.isEmpty(objArg.name) && !Util.isEmpty(name)) {\r
- if (!objArg.name.equals(this.name)) {\r
- return false;\r
- }\r
+\r
+ /**\r
+ * Sets one of the values defined in optionList as default. Attempting set\r
+ * the value not listed there will result in WrongParameter exception\r
+ * \r
+ * @param defaultVal\r
+ * @throws WrongParameterException\r
+ * is thrown if the defaultValue is not found in optionList\r
+ */\r
+ public void setDefaultValue(String defaultVal)\r
+ throws WrongParameterException {\r
+ if (optionNames.isEmpty()) {\r
+ throw new IllegalStateException("Please define optionNames first!");\r
+ }\r
+ if (!valueExist(defaultVal, getOptionNames())) {\r
+ throw new WrongParameterException(\r
+ "Attempting to set illegal defaultValue '" + defaultVal\r
+ + "' which is not defined optionNames for option: "\r
+ + this);\r
+ }\r
+ this.defaultValue = defaultVal;\r
}\r
- if (!Util.isEmpty(objArg.description) && !Util.isEmpty(description)) {\r
- if (!objArg.description.equals(this.description)) {\r
+\r
+ static boolean valueExist(String testValue, List<String> values) {\r
+ assert !Util.isEmpty(testValue);\r
+ for (String val : values) {\r
+ if (testValue.equalsIgnoreCase(val)) {\r
+ return true;\r
+ }\r
+ }\r
return false;\r
- }\r
}\r
- if (objArg.isRequired != this.isRequired) {\r
- return false;\r
+\r
+ /**\r
+ * Flag that indicated that this option must be specified in the command\r
+ * line for an executable to run\r
+ * \r
+ * @return true is the option is required, false otherwise\r
+ */\r
+ public boolean isRequired() {\r
+ return isRequired;\r
}\r
- if (!Util.isEmpty(objArg.defaultValue) && !Util.isEmpty(defaultValue)) {\r
- if (!objArg.defaultValue.equals(this.defaultValue)) {\r
- return false;\r
- }\r
+\r
+ public void setRequired(boolean isRequired) {\r
+ this.isRequired = isRequired;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return List of option names\r
+ */\r
+ public List<String> getOptionNames() {\r
+ return new ArrayList<String>(optionNames);\r
}\r
- if (objArg.optionNames.size() != this.optionNames.size()) {\r
- return false;\r
+\r
+ public void setOptionNames(Set<String> optionNames) {\r
+ this.optionNames = new HashSet<String>(optionNames);\r
+ }\r
+\r
+ /**\r
+ * Adds an option to the optionName list\r
+ * \r
+ * @param value\r
+ * @return modified optionName list\r
+ */\r
+ public Set<String> addOptionNames(String... value) {\r
+ for (String v : value) {\r
+ boolean added = this.optionNames.add(v);\r
+ assert added : "Duplicated optionName is detected!";\r
+ }\r
+ return this.optionNames;\r
}\r
- int matchCount = 0;\r
- for (String oname : objArg.optionNames) {\r
- if (Util.isEmpty(oname)) {\r
- continue;\r
- }\r
- for (String thisoname : this.optionNames) {\r
- if (oname.equals(thisoname)) {\r
- matchCount++;\r
- break;\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "Option name: " + this.name + SysPrefs.newlinechar;\r
+ value += "Description: " + this.description + SysPrefs.newlinechar;\r
+ if (!Util.isEmpty(defaultValue)) {\r
+ value += "Default value: " + this.defaultValue\r
+ + SysPrefs.newlinechar;\r
}\r
- }\r
+ value += "URL: " + this.furtherDetails + SysPrefs.newlinechar;\r
+ value += "Is required: " + this.isRequired + SysPrefs.newlinechar;\r
+ if (!this.optionNames.isEmpty()) {\r
+ Set<String> sortedPosval = new TreeSet<String>(this.optionNames);\r
+ value += "Option Names: " + SysPrefs.newlinechar;\r
+ for (String val : sortedPosval) {\r
+ value += val + SysPrefs.newlinechar;\r
+ }\r
+ }\r
+ return value;\r
}\r
- if (matchCount != objArg.optionNames.size()) {\r
- return false;\r
+\r
+ /**\r
+ * Convert the option to the command string.\r
+ * \r
+ * @return If only one optionName is defined, than it is returned, if many\r
+ * option names are defined, then the defaultValue is returned.\r
+ * Option must have a default value if there are many optionNames to\r
+ * be valid.\r
+ */\r
+ public String toCommand(String nameValueSeparator) {\r
+ if (optionNames.size() == 1) {\r
+ return optionNames.iterator().next();\r
+ }\r
+ return getDefaultValue();\r
}\r
- return true;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- int code = this.name.hashCode() * this.description.hashCode();\r
- if (this.isRequired) {\r
- code += this.furtherDetails.hashCode() * 3;\r
- } else {\r
- if (defaultValue != null) {\r
- code += this.defaultValue.hashCode() * 2;\r
- }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ Option<?> objArg = null;\r
+ if (obj instanceof Option<?>) {\r
+ objArg = (Option<?>) obj;\r
+ } else {\r
+ return false;\r
+ }\r
+ if (!Util.isEmpty(objArg.name) && !Util.isEmpty(name)) {\r
+ if (!objArg.name.equals(this.name)) {\r
+ return false;\r
+ }\r
+ }\r
+ if (!Util.isEmpty(objArg.description) && !Util.isEmpty(description)) {\r
+ if (!objArg.description.equals(this.description)) {\r
+ return false;\r
+ }\r
+ }\r
+ if (objArg.isRequired != this.isRequired) {\r
+ return false;\r
+ }\r
+ if (!Util.isEmpty(objArg.defaultValue) && !Util.isEmpty(defaultValue)) {\r
+ if (!objArg.defaultValue.equals(this.defaultValue)) {\r
+ return false;\r
+ }\r
+ }\r
+ if (objArg.optionNames.size() != this.optionNames.size()) {\r
+ return false;\r
+ }\r
+ int matchCount = 0;\r
+ for (String oname : objArg.optionNames) {\r
+ if (Util.isEmpty(oname)) {\r
+ continue;\r
+ }\r
+ for (String thisoname : this.optionNames) {\r
+ if (oname.equals(thisoname)) {\r
+ matchCount++;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ if (matchCount != objArg.optionNames.size()) {\r
+ return false;\r
+ }\r
+ return true;\r
}\r
- if (this.description != null) {\r
- code += this.description.hashCode() * 4;\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ int code = this.name.hashCode() * this.description.hashCode();\r
+ if (this.isRequired) {\r
+ code += this.furtherDetails.hashCode() * 3;\r
+ } else {\r
+ if (defaultValue != null) {\r
+ code += this.defaultValue.hashCode() * 2;\r
+ }\r
+ }\r
+ if (this.description != null) {\r
+ code += this.description.hashCode() * 4;\r
+ }\r
+\r
+ return code;\r
}\r
\r
- return code;\r
- }\r
-\r
- /**\r
- * List of possible optionNames\r
- */\r
- @Override\r
- public List<String> getPossibleValues() {\r
- return new ArrayList<String>(optionNames);\r
- }\r
-\r
- @Override\r
- public void setValue(String dValue) throws WrongParameterException {\r
- this.setDefaultValue(dValue);\r
- }\r
-\r
- /**\r
- * Validate the option\r
- * \r
- * @throws ValidationException\r
- * is the option is invalid. This happens if option does not\r
- * have a default value but have multiple option names, or no\r
- * option names is defined\r
- */\r
- void validate() throws ValidationException {\r
- if (optionNames == null) {\r
- throw new ValidationException(\r
- "Option names are not defined for option: " + this);\r
+ /**\r
+ * List of possible optionNames\r
+ */\r
+ @Override\r
+ public List<String> getPossibleValues() {\r
+ return new ArrayList<String>(optionNames);\r
}\r
- if (optionNames.size() > 1 && Util.isEmpty(getDefaultValue())) {\r
- throw new ValidationException(\r
- "Default value is required as multiple optionNames are defined for option: "\r
- + this);\r
+\r
+ @Override\r
+ public void setValue(String dValue) throws WrongParameterException {\r
+ this.setDefaultValue(dValue);\r
}\r
- if (Util.isEmpty(name)) {\r
- throw new ValidationException("No name is defined for option: "\r
- + this);\r
+\r
+ /**\r
+ * Validate the option\r
+ * \r
+ * @throws ValidationException\r
+ * is the option is invalid. This happens if option does not\r
+ * have a default value but have multiple option names, or no\r
+ * option names is defined\r
+ */\r
+ void validate() throws ValidationException {\r
+ if (optionNames == null) {\r
+ throw new ValidationException(\r
+ "Option names are not defined for option: " + this);\r
+ }\r
+ if (optionNames.size() > 1 && Util.isEmpty(getDefaultValue())) {\r
+ throw new ValidationException(\r
+ "Default value is required as multiple optionNames are defined for option: "\r
+ + this);\r
+ }\r
+ if (Util.isEmpty(name)) {\r
+ throw new ValidationException("No name is defined for option: "\r
+ + this);\r
+ }\r
}\r
- }\r
}
\ No newline at end of file
import compbio.util.Util;\r
\r
/**\r
- * A single value containing option supported by the web service e.g.\r
+ * A single value containing an option supported by the web service e.g.\r
* seqType=protein. Where seqType is a optionName and protein is one of\r
* possibleValues\r
* \r
* \r
* @author pvtroshin\r
* \r
- * Date November 2009\r
+ * @version 1.0 November 2009\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class Parameter<T> extends Option<T> {\r
\r
- @XmlElement\r
- Set<String> possibleValues = new HashSet<String>();\r
-\r
- ValueConstrain validValue;\r
-\r
- private Parameter() {\r
- // JAXB noargs const\r
- }\r
-\r
- public Parameter(String name, String description) {\r
- super(name, description);\r
- }\r
-\r
- public ValueConstrain getValidValue() {\r
- return validValue;\r
- }\r
-\r
- public void setValidValue(ValueConstrain validValue) {\r
- if (validValue == null) {\r
- throw new NullPointerException("ValueConstrain is expected!");\r
- }\r
- this.validValue = validValue;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = super.toString();\r
- if (validValue != null) {\r
- value += validValue.toString();\r
- }\r
- if (!this.possibleValues.isEmpty()) {\r
- Set<String> sortedPosval = new TreeSet<String>(this.possibleValues);\r
- value += "POSSIBLE VALUES:" + SysPrefs.newlinechar;\r
- for (String val : sortedPosval) {\r
- value += val + SysPrefs.newlinechar;\r
- }\r
- }\r
- value += SysPrefs.newlinechar;\r
- return value;\r
- }\r
-\r
- @Override\r
- public String toCommand(String nameValueSeparator) {\r
- if (nameValueSeparator == null) {\r
- throw new NullPointerException("Name value separator is expected!");\r
- }\r
- return getOptionName() + nameValueSeparator + getValue();\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (!super.equals(obj)) {\r
- return false;\r
- }\r
- Parameter<?> objp = null;\r
- if (obj instanceof Parameter<?>) {\r
- objp = (Parameter<?>) obj;\r
- } else {\r
- return false;\r
- }\r
-\r
- if (objp.possibleValues.size() != this.possibleValues.size()) {\r
- return false;\r
- }\r
- int matchCount = 0;\r
- for (String pv : objp.possibleValues) {\r
- if (Util.isEmpty(pv)) {\r
- continue;\r
- }\r
- for (String thispv : this.possibleValues) {\r
- if (pv.equals(thispv)) {\r
- matchCount++;\r
- break;\r
+ @XmlElement\r
+ Set<String> possibleValues = new HashSet<String>();\r
+\r
+ ValueConstrain validValue;\r
+\r
+ private Parameter() {\r
+ // JAXB noargs const\r
+ }\r
+\r
+ public Parameter(String name, String description) {\r
+ super(name, description);\r
+ }\r
+\r
+ public ValueConstrain getValidValue() {\r
+ return validValue;\r
+ }\r
+\r
+ public void setValidValue(ValueConstrain validValue) {\r
+ if (validValue == null) {\r
+ throw new NullPointerException("ValueConstrain is expected!");\r
+ }\r
+ this.validValue = validValue;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = super.toString();\r
+ if (validValue != null) {\r
+ value += validValue.toString();\r
+ }\r
+ if (!this.possibleValues.isEmpty()) {\r
+ Set<String> sortedPosval = new TreeSet<String>(this.possibleValues);\r
+ value += "POSSIBLE VALUES:" + SysPrefs.newlinechar;\r
+ for (String val : sortedPosval) {\r
+ value += val + SysPrefs.newlinechar;\r
+ }\r
+ }\r
+ value += SysPrefs.newlinechar;\r
+ return value;\r
+ }\r
+\r
+ @Override\r
+ public String toCommand(String nameValueSeparator) {\r
+ if (nameValueSeparator == null) {\r
+ throw new NullPointerException("Name value separator is expected!");\r
+ }\r
+ return getOptionName() + nameValueSeparator + getValue();\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (!super.equals(obj)) {\r
+ return false;\r
+ }\r
+ Parameter<?> objp = null;\r
+ if (obj instanceof Parameter<?>) {\r
+ objp = (Parameter<?>) obj;\r
+ } else {\r
+ return false;\r
+ }\r
+\r
+ if (objp.possibleValues.size() != this.possibleValues.size()) {\r
+ return false;\r
}\r
- }\r
- }\r
- if (matchCount != objp.possibleValues.size()) {\r
- return false;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- /**\r
- * List is more convenient to work with\r
- * \r
- * @return List of String\r
- */\r
- @Override\r
- public List<String> getPossibleValues() {\r
- return new ArrayList<String>(possibleValues);\r
- }\r
-\r
- public void setPossibleValues(Set<String> possibleValues) {\r
- this.possibleValues = new HashSet<String>(possibleValues);\r
- }\r
-\r
- public Set<String> addPossibleValues(String... value) {\r
- for (String v : value) {\r
- this.possibleValues.add(v);\r
- }\r
- return this.possibleValues;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- int code = super.hashCode();\r
- if (possibleValues != null) {\r
- code += possibleValues.hashCode();\r
- }\r
- return code;\r
- }\r
-\r
- @Override\r
- public void setOptionNames(Set<String> optionName) {\r
- if (optionName.size() != 1) {\r
- throw new IllegalArgumentException(\r
- "Parameter must have a single option name! But given "\r
- + optionName.size() + " names: " + optionName);\r
- }\r
- super.setOptionNames(optionName);\r
- }\r
-\r
- @Override\r
- public Set<String> addOptionNames(String... value) {\r
- throw new UnsupportedOperationException(\r
- "Parameter must have only one optionName! If you setting the only name that use setOptionName instead");\r
- }\r
-\r
- public String getOptionName() {\r
- assert optionNames.size() == 1;\r
- return optionNames.iterator().next();\r
- }\r
-\r
- public void setOptionName(String optionName) {\r
- assert !Util.isEmpty(optionName);\r
- setOptionNames(Collections.singleton(optionName));\r
- }\r
-\r
- String getValue() {\r
- if (this.possibleValues.size() == 1) {\r
- return this.possibleValues.iterator().next();\r
- }\r
- return getDefaultValue();\r
- }\r
-\r
- @Override\r
- void validate() throws ValidationException {\r
- super.validate();\r
- if (validValue == null) {\r
- if (this.possibleValues.isEmpty()) {\r
- throw new ValidationException(\r
- "No possible values defined for parameter: " + this);\r
- }\r
- if (this.possibleValues.size() > 1\r
- && Util.isEmpty(getDefaultValue())) {\r
- throw new ValidationException(\r
- "Multiple possible values are defined but no default value for parameter: "\r
- + this);\r
- }\r
- } else {\r
- if (Util.isEmpty(getDefaultValue())) {\r
- throw new ValidationException(\r
- "Default value is not defined for numeric parameter! "\r
- + this);\r
- }\r
- validValue.checkValue(getDefaultValue());\r
- }\r
- }\r
-\r
- boolean isValidValue(String value) {\r
- assert !Util.isEmpty(value);\r
- return Option.valueExist(value, getPossibleValues());\r
- }\r
-\r
- @Override\r
- public void setDefaultValue(String defaultVal)\r
- throws WrongParameterException {\r
- // If valid value constrain is not defined, then possible values must\r
- // be, and they must contain the value which is\r
- // about to be set!\r
- if (validValue == null) {\r
- if (getPossibleValues().isEmpty()) {\r
- throw new IllegalStateException(\r
- "Attempting to set default value for parameter: "\r
- + this\r
- + " Without possible values! Please define possible value first!");\r
- }\r
- if (!isValidValue(defaultVal)) {\r
- throw new WrongParameterException(\r
- "Attempting to set illegal value '" + defaultVal\r
- + "' for the parameter: " + this);\r
- }\r
- } else {\r
- try {\r
- validValue.checkValue(defaultVal);\r
- } catch (IndexOutOfBoundsException e) {\r
- throw new WrongParameterException(\r
- "Attempting to set default value outside boundaries defined by the constraint: "\r
- + validValue + "\n For parameter: " + this);\r
- }\r
- }\r
- this.defaultValue = defaultVal;\r
- }\r
+ int matchCount = 0;\r
+ for (String pv : objp.possibleValues) {\r
+ if (Util.isEmpty(pv)) {\r
+ continue;\r
+ }\r
+ for (String thispv : this.possibleValues) {\r
+ if (pv.equals(thispv)) {\r
+ matchCount++;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ if (matchCount != objp.possibleValues.size()) {\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * List is more convenient to work with\r
+ * \r
+ * @return List of String\r
+ */\r
+ @Override\r
+ public List<String> getPossibleValues() {\r
+ return new ArrayList<String>(possibleValues);\r
+ }\r
+\r
+ public void setPossibleValues(Set<String> possibleValues) {\r
+ this.possibleValues = new HashSet<String>(possibleValues);\r
+ }\r
+\r
+ public Set<String> addPossibleValues(String... value) {\r
+ for (String v : value) {\r
+ this.possibleValues.add(v);\r
+ }\r
+ return this.possibleValues;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ int code = super.hashCode();\r
+ if (possibleValues != null) {\r
+ code += possibleValues.hashCode();\r
+ }\r
+ return code;\r
+ }\r
+\r
+ @Override\r
+ public void setOptionNames(Set<String> optionName) {\r
+ if (optionName.size() != 1) {\r
+ throw new IllegalArgumentException(\r
+ "Parameter must have a single option name! But given "\r
+ + optionName.size() + " names: " + optionName);\r
+ }\r
+ super.setOptionNames(optionName);\r
+ }\r
+\r
+ @Override\r
+ public Set<String> addOptionNames(String... value) {\r
+ throw new UnsupportedOperationException(\r
+ "Parameter must have only one optionName! If you setting the only name that use setOptionName instead");\r
+ }\r
+\r
+ public String getOptionName() {\r
+ assert optionNames.size() == 1;\r
+ return optionNames.iterator().next();\r
+ }\r
+\r
+ public void setOptionName(String optionName) {\r
+ assert !Util.isEmpty(optionName);\r
+ setOptionNames(Collections.singleton(optionName));\r
+ }\r
+\r
+ String getValue() {\r
+ if (this.possibleValues.size() == 1) {\r
+ return this.possibleValues.iterator().next();\r
+ }\r
+ return getDefaultValue();\r
+ }\r
+\r
+ @Override\r
+ void validate() throws ValidationException {\r
+ super.validate();\r
+ if (validValue == null) {\r
+ if (this.possibleValues.isEmpty()) {\r
+ throw new ValidationException(\r
+ "No possible values defined for parameter: " + this);\r
+ }\r
+ if (this.possibleValues.size() > 1\r
+ && Util.isEmpty(getDefaultValue())) {\r
+ throw new ValidationException(\r
+ "Multiple possible values are defined but no default value for parameter: "\r
+ + this);\r
+ }\r
+ } else {\r
+ if (Util.isEmpty(getDefaultValue())) {\r
+ throw new ValidationException(\r
+ "Default value is not defined for numeric parameter! "\r
+ + this);\r
+ }\r
+ validValue.checkValue(getDefaultValue());\r
+ }\r
+ }\r
+\r
+ boolean isValidValue(String value) {\r
+ assert !Util.isEmpty(value);\r
+ return Option.valueExist(value, getPossibleValues());\r
+ }\r
+\r
+ @Override\r
+ public void setDefaultValue(String defaultVal)\r
+ throws WrongParameterException {\r
+ // If valid value constrain is not defined, then possible values must\r
+ // be, and they must contain the value which is\r
+ // about to be set!\r
+ if (validValue == null) {\r
+ if (getPossibleValues().isEmpty()) {\r
+ throw new IllegalStateException(\r
+ "Attempting to set default value for parameter: "\r
+ + this\r
+ + " Without possible values! Please define possible value first!");\r
+ }\r
+ if (!isValidValue(defaultVal)) {\r
+ throw new WrongParameterException(\r
+ "Attempting to set illegal value '" + defaultVal\r
+ + "' for the parameter: " + this);\r
+ }\r
+ } else {\r
+ try {\r
+ validValue.checkValue(defaultVal);\r
+ } catch (IndexOutOfBoundsException e) {\r
+ throw new WrongParameterException(\r
+ "Attempting to set default value outside boundaries defined by the constraint: "\r
+ + validValue + "\n For parameter: " + this);\r
+ }\r
+ }\r
+ this.defaultValue = defaultVal;\r
+ }\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date December 2009\r
+ * @version 1.0 December 2009\r
* @param <T>\r
* executable type\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class Preset<T> {\r
\r
- @XmlTransient\r
- private static final String SPACE = " ";\r
-\r
- @XmlElement(required = true, nillable = false)\r
- // @XmlID - ? require no spaces (!)\r
- String name;\r
-\r
- String description;\r
-\r
- @XmlElement(required = true, nillable = false)\r
- @XmlElementWrapper(name = "optlist")\r
- List<String> option;\r
-\r
- public void setOptions(List<String> option) {\r
- this.option = option;\r
- }\r
-\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
-\r
- /**\r
- * @return a List of Options as a String\r
- */\r
- public List<String> getOptions() {\r
- return new ArrayList<String>(option);\r
- }\r
-\r
- /**\r
- * \r
- * @return - name of the Preset\r
- */\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- /**\r
- * \r
- * @return - a long description of the Preset\r
- */\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- /**\r
- * Converts list of options as String to type Option\r
- * \r
- * @param rconfig\r
- * @return List of Options\r
- * @throws WrongParameterException\r
- * if the value of the parameter is invalid @see\r
- * {@link Parameter}\r
- */\r
- public List<Option<T>> getArguments(RunnerConfig<T> rconfig)\r
- throws WrongParameterException {\r
- List<Option<T>> options = new ArrayList<Option<T>>();\r
- for (String optionName : option) {\r
- optionName = optionName.trim();\r
- String oname = getName(optionName);\r
- Option<T> option = rconfig.getArgumentByOptionName(oname);\r
- if (option != null) {\r
- // Set default value to the preset value\r
- if (containValue(optionName)) {\r
- // extract and set value to the parameter \r
- option.setDefaultValue(getValue(optionName));\r
- } else {\r
- // set value to the option as default, as this could be a multi-option value\r
- option.setDefaultValue(oname);\r
- }\r
- options.add(option);\r
- }\r
+ @XmlTransient\r
+ private static final String SPACE = " ";\r
+\r
+ @XmlElement(required = true, nillable = false)\r
+ // @XmlID - ? require no spaces (!)\r
+ String name;\r
+\r
+ String description;\r
+\r
+ @XmlElement(required = true, nillable = false)\r
+ @XmlElementWrapper(name = "optlist")\r
+ List<String> option;\r
+\r
+ public void setOptions(List<String> option) {\r
+ this.option = option;\r
}\r
- return options;\r
- }\r
\r
- boolean containValue(String option) {\r
- if (option.trim().contains(SPACE)) {\r
- return true;\r
+ public void setName(String name) {\r
+ this.name = name;\r
}\r
- return false;\r
- }\r
\r
- String getName(String option) {\r
- option = option.trim();\r
- if (containValue(option)) {\r
- return option.substring(0, option.indexOf(SPACE)).trim();\r
+ public void setDescription(String description) {\r
+ this.description = description;\r
}\r
- return option;\r
- }\r
-\r
- String getValue(String option) {\r
- assert containValue(option);\r
- option = option.trim();\r
- return option.substring(option.indexOf(SPACE) + 1).trim();\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "Preset name: '" + name + "'" + SysPrefs.newlinechar;\r
- value += "Description: " + description + SysPrefs.newlinechar;\r
- value += "Options: " + SysPrefs.newlinechar;\r
- for (String oname : this.option) {\r
- value += oname + SysPrefs.newlinechar;\r
+\r
+ /**\r
+ * @return a List of Options as a String\r
+ */\r
+ public List<String> getOptions() {\r
+ return new ArrayList<String>(option);\r
}\r
- value += SysPrefs.newlinechar;\r
- return value;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result\r
- + ((description == null) ? 0 : description.hashCode());\r
- result = prime * result + ((name == null) ? 0 : name.hashCode());\r
- result = prime * result + ((option == null) ? 0 : option.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- Preset other = (Preset) obj;\r
- if (description == null) {\r
- if (other.description != null)\r
- return false;\r
- } else if (!description.equals(other.description))\r
- return false;\r
- if (name == null) {\r
- if (other.name != null)\r
- return false;\r
- } else if (!name.equals(other.name))\r
- return false;\r
- if (option == null) {\r
- if (other.option != null)\r
+\r
+ /**\r
+ * \r
+ * @return - name of the Preset\r
+ */\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return - a long description of the Preset\r
+ */\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ /**\r
+ * Converts list of options as String to type Option\r
+ * \r
+ * @param rconfig\r
+ * @return List of Options\r
+ * @throws WrongParameterException\r
+ * if the value of the parameter is invalid @see\r
+ * {@link Parameter}\r
+ */\r
+ public List<Option<T>> getArguments(RunnerConfig<T> rconfig)\r
+ throws WrongParameterException {\r
+ List<Option<T>> options = new ArrayList<Option<T>>();\r
+ for (String optionName : option) {\r
+ optionName = optionName.trim();\r
+ String oname = getName(optionName);\r
+ Option<T> option = rconfig.getArgumentByOptionName(oname);\r
+ if (option != null) {\r
+ // Set default value to the preset value\r
+ if (containValue(optionName)) {\r
+ // extract and set value to the parameter\r
+ option.setDefaultValue(getValue(optionName));\r
+ } else {\r
+ // set value to the option as default, as this could be a\r
+ // multi-option value\r
+ option.setDefaultValue(oname);\r
+ }\r
+ options.add(option);\r
+ }\r
+ }\r
+ return options;\r
+ }\r
+\r
+ boolean containValue(String option) {\r
+ if (option.trim().contains(SPACE)) {\r
+ return true;\r
+ }\r
return false;\r
- } else if (!option.equals(other.option))\r
- return false;\r
- return true;\r
- }\r
+ }\r
+\r
+ String getName(String option) {\r
+ option = option.trim();\r
+ if (containValue(option)) {\r
+ return option.substring(0, option.indexOf(SPACE)).trim();\r
+ }\r
+ return option;\r
+ }\r
+\r
+ String getValue(String option) {\r
+ assert containValue(option);\r
+ option = option.trim();\r
+ return option.substring(option.indexOf(SPACE) + 1).trim();\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "Preset name: '" + name + "'" + SysPrefs.newlinechar;\r
+ value += "Description: " + description + SysPrefs.newlinechar;\r
+ value += "Options: " + SysPrefs.newlinechar;\r
+ for (String oname : this.option) {\r
+ value += oname + SysPrefs.newlinechar;\r
+ }\r
+ value += SysPrefs.newlinechar;\r
+ return value;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ final int prime = 31;\r
+ int result = 1;\r
+ result = prime * result\r
+ + ((description == null) ? 0 : description.hashCode());\r
+ result = prime * result + ((name == null) ? 0 : name.hashCode());\r
+ result = prime * result + ((option == null) ? 0 : option.hashCode());\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (this == obj)\r
+ return true;\r
+ if (obj == null)\r
+ return false;\r
+ if (getClass() != obj.getClass())\r
+ return false;\r
+ Preset other = (Preset) obj;\r
+ if (description == null) {\r
+ if (other.description != null)\r
+ return false;\r
+ } else if (!description.equals(other.description))\r
+ return false;\r
+ if (name == null) {\r
+ if (other.name != null)\r
+ return false;\r
+ } else if (!name.equals(other.name))\r
+ return false;\r
+ if (option == null) {\r
+ if (other.option != null)\r
+ return false;\r
+ } else if (!option.equals(other.option))\r
+ return false;\r
+ return true;\r
+ }\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date December 2009\r
+ * @version 1.0 December 2009\r
* @param <T>\r
* type of executable.\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class PresetManager<T> {\r
\r
- @XmlElement(required = true)\r
- String runnerClassName;\r
-\r
- @XmlElement(required = true)\r
- List<Preset<T>> preset;\r
-\r
- public static final String LOCAL_ENGINE_LIMIT_PRESET = "# LocalEngineExecutionLimit #";\r
-\r
- public List<Preset<T>> getPresets() {\r
- return preset;\r
- }\r
-\r
- public void setPresets(List<Preset<T>> presets) {\r
- this.preset = presets;\r
- }\r
-\r
- /**\r
- * \r
- * @return fully qualified class name of type T\r
- */\r
- public String getRunnerClassName() {\r
- return runnerClassName;\r
- }\r
-\r
- public void setRunnerClassName(String runnerClassName) {\r
- this.runnerClassName = runnerClassName;\r
- }\r
-\r
- /**\r
- * \r
- * @param presetName\r
- * @return preset by its name, null if no preset found\r
- */\r
- public Preset<T> getPresetByName(String presetName) {\r
- for (Preset<T> p : preset) {\r
- if (p.getName().equalsIgnoreCase(presetName)) {\r
- return p;\r
- }\r
+ @XmlElement(required = true)\r
+ String runnerClassName;\r
+\r
+ @XmlElement(required = true)\r
+ List<Preset<T>> preset;\r
+\r
+ public static final String LOCAL_ENGINE_LIMIT_PRESET = "# LocalEngineExecutionLimit #";\r
+\r
+ public List<Preset<T>> getPresets() {\r
+ return preset;\r
}\r
- return null;\r
- }\r
-\r
- boolean isComposite(String value) {\r
- assert value != null;\r
- return value.contains(" ");\r
- }\r
-\r
- boolean containsValue(List<String> values, String value) {\r
- assert !Util.isEmpty(value);\r
- for (String v : values) {\r
- if (v.equals(value)) {\r
- return true;\r
- }\r
+\r
+ public void setPresets(List<Preset<T>> presets) {\r
+ this.preset = presets;\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return fully qualified class name of type T\r
+ */\r
+ public String getRunnerClassName() {\r
+ return runnerClassName;\r
}\r
- return false;\r
- }\r
-\r
- boolean isNumeric(String value) {\r
- assert value != null;\r
- try {\r
- Double.parseDouble(value);\r
- return true;\r
- } catch (NumberFormatException e) {\r
- // ignore\r
- return false;\r
+\r
+ public void setRunnerClassName(String runnerClassName) {\r
+ this.runnerClassName = runnerClassName;\r
}\r
- }\r
-\r
- /**\r
- * Checks whether preset option and parameter are defined in RunnerConfig\r
- * object.\r
- * \r
- * TODO handle parameters with values properly!\r
- * \r
- * @throws ValidationException\r
- * if preset is found to be invalid.\r
- * \r
- */\r
- public void validate(RunnerConfig<T> options) throws ValidationException {\r
- for (Preset<T> p : preset) {\r
- if (Util.isEmpty(p.name)) {\r
- throw new ValidationException("Preset name must not be empty!");\r
- }\r
- List<String> optionNames = p.getOptions();\r
- if (optionNames == null || optionNames.size() == 0) {\r
- throw new ValidationException(\r
- "At lease one option must be defined for a preset!");\r
- }\r
- for (String oName : optionNames) {\r
- if (isComposite(oName)) {\r
- String name = oName.split(" ")[0];\r
- Argument<T> arg = getArgument(options, name);\r
- String value = oName.split(" ")[1];\r
- // Ignore numeric values\r
- if (!isNumeric(value)\r
- && !containsValue(arg.getPossibleValues(), value)) {\r
- throw new ValidationException("Value " + value\r
- + " is not found in the option " + name);\r
- }\r
- } else {\r
- getArgument(options, oName);\r
+\r
+ /**\r
+ * \r
+ * @param presetName\r
+ * @return preset by its name, null if no preset found\r
+ */\r
+ public Preset<T> getPresetByName(String presetName) {\r
+ for (Preset<T> p : preset) {\r
+ if (p.getName().equalsIgnoreCase(presetName)) {\r
+ return p;\r
+ }\r
}\r
- }\r
+ return null;\r
+ }\r
+\r
+ boolean isComposite(String value) {\r
+ assert value != null;\r
+ return value.contains(" ");\r
}\r
- }\r
-\r
- Argument<T> getArgument(RunnerConfig<T> options, String optionName)\r
- throws ValidationException {\r
- Argument<T> arg = options.getArgumentByOptionName(optionName);\r
- if (arg == null) {\r
- throw new ValidationException(\r
- "Option "\r
- + optionName\r
- + " is not found in the option list (<RunnerName>Parameter.xml file)");\r
+\r
+ boolean containsValue(List<String> values, String value) {\r
+ assert !Util.isEmpty(value);\r
+ for (String v : values) {\r
+ if (v.equals(value)) {\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
}\r
- return arg;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "Runner: " + this.runnerClassName;\r
- for (Preset<T> p : preset) {\r
- value += p.toString() + "\n";\r
+\r
+ boolean isNumeric(String value) {\r
+ assert value != null;\r
+ try {\r
+ Double.parseDouble(value);\r
+ return true;\r
+ } catch (NumberFormatException e) {\r
+ // ignore\r
+ return false;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Checks whether preset option and parameter are defined in RunnerConfig\r
+ * object.\r
+ * \r
+ * TODO handle parameters with values properly!\r
+ * \r
+ * @throws ValidationException\r
+ * if preset is found to be invalid.\r
+ * \r
+ */\r
+ public void validate(RunnerConfig<T> options) throws ValidationException {\r
+ for (Preset<T> p : preset) {\r
+ if (Util.isEmpty(p.name)) {\r
+ throw new ValidationException("Preset name must not be empty!");\r
+ }\r
+ List<String> optionNames = p.getOptions();\r
+ if (optionNames == null || optionNames.size() == 0) {\r
+ throw new ValidationException(\r
+ "At lease one option must be defined for a preset!");\r
+ }\r
+ for (String oName : optionNames) {\r
+ if (isComposite(oName)) {\r
+ String name = oName.split(" ")[0];\r
+ Argument<T> arg = getArgument(options, name);\r
+ String value = oName.split(" ")[1];\r
+ // Ignore numeric values\r
+ if (!isNumeric(value)\r
+ && !containsValue(arg.getPossibleValues(), value)) {\r
+ throw new ValidationException("Value " + value\r
+ + " is not found in the option " + name);\r
+ }\r
+ } else {\r
+ getArgument(options, oName);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ Argument<T> getArgument(RunnerConfig<T> options, String optionName)\r
+ throws ValidationException {\r
+ Argument<T> arg = options.getArgumentByOptionName(optionName);\r
+ if (arg == null) {\r
+ throw new ValidationException(\r
+ "Option "\r
+ + optionName\r
+ + " is not found in the option list (<RunnerName>Parameter.xml file)");\r
+ }\r
+ return arg;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "Runner: " + this.runnerClassName;\r
+ for (Preset<T> p : preset) {\r
+ value += p.toString() + "\n";\r
+ }\r
+ return value;\r
}\r
- return value;\r
- }\r
\r
}\r
\r
/**\r
* The list of {@link Parameter}s and {@link Option}s supported by executable.\r
+ * The lists is defined in and loaded from <ExecutableName>Parameters.xml file.\r
* \r
* @author pvtroshin\r
* \r
- * Date October 2009\r
+ * @version 1.0 October 2009\r
* @param <T>\r
* type of an Executable\r
*/\r
@NotThreadSafe\r
public class RunnerConfig<T> {\r
\r
- /**\r
- * Please note that the order of the fields is important to generate xml\r
- * compliant to the hand written schema!!!\r
- */\r
- /**\r
- * The class name of a runnable e.g. T\r
- */\r
- private String runnerClassName;\r
- List<Option<T>> options = new ArrayList<Option<T>>();\r
- String prmSeparator;\r
- List<Parameter<T>> parameters = new ArrayList<Parameter<T>>();\r
+ /*\r
+ * Please note that the order of the fields in this class is important to\r
+ * generate xml compliant to the hand written schema!!!\r
+ */\r
\r
- @XmlTransient\r
- List<Option<T>> arguments;\r
+ /**\r
+ * The class name of a runnable e.g. T\r
+ */\r
+ private String runnerClassName;\r
+ List<Option<T>> options = new ArrayList<Option<T>>();\r
+ String prmSeparator;\r
+ List<Parameter<T>> parameters = new ArrayList<Parameter<T>>();\r
\r
- public RunnerConfig() {\r
- // JAXB default constructor\r
- }\r
+ @XmlTransient\r
+ List<Option<T>> arguments;\r
\r
- public RunnerConfig<T> copyAndValidateRConfig(RunnerConfig<?> runnerConf) {\r
- if (this.runnerClassName != runnerConf.runnerClassName) {\r
- throw new InvalidParameterException("Wrong runner configuration! ");\r
+ public RunnerConfig() {\r
+ // JAXB default constructor\r
}\r
- RunnerConfig<T> newrconfig = new RunnerConfig<T>();\r
- newrconfig.runnerClassName = runnerConf.runnerClassName;\r
- newrconfig.options = new ArrayList<Option<T>>(options);\r
- return newrconfig;\r
- }\r
\r
- /**\r
- * \r
- * @return list of {@link Option} supported by type T\r
- */\r
- public List<Option<T>> getOptions() {\r
- return options;\r
- }\r
-\r
- public void addParameter(Parameter<T> param) {\r
- assert param != null;\r
- parameters.add(param);\r
- }\r
-\r
- public void addOption(Option<T> option) {\r
- assert option != null;\r
- options.add(option);\r
- }\r
-\r
- /**\r
- * \r
- * @return list of {@link Option} and {@link Parameter} supported by type T\r
- */\r
- @XmlTransient\r
- public List<Option<T>> getArguments() {\r
- arguments = new ArrayList<Option<T>>(options);\r
- arguments.addAll(parameters);\r
- return arguments;\r
- }\r
-\r
- /**\r
- * \r
- * @return name value separator character\r
- */\r
- public String getPrmSeparator() {\r
- return prmSeparator;\r
- }\r
-\r
- public void setPrmSeparator(String prmSeparator) {\r
- this.prmSeparator = prmSeparator;\r
- }\r
-\r
- public void setOptions(List<Option<T>> parameters) {\r
- this.options = parameters;\r
- }\r
-\r
- /**\r
- * \r
- * @return fully qualified class name for type T\r
- */\r
- @XmlElement(required = true)\r
- public String getRunnerClassName() {\r
- return runnerClassName;\r
- }\r
-\r
- public void setRunnerClassName(String runnerClassName) {\r
- this.runnerClassName = runnerClassName;\r
- }\r
+ public RunnerConfig<T> copyAndValidateRConfig(RunnerConfig<?> runnerConf) {\r
+ if (this.runnerClassName != runnerConf.runnerClassName) {\r
+ throw new InvalidParameterException("Wrong runner configuration! ");\r
+ }\r
+ RunnerConfig<T> newrconfig = new RunnerConfig<T>();\r
+ newrconfig.runnerClassName = runnerConf.runnerClassName;\r
+ newrconfig.options = new ArrayList<Option<T>>(options);\r
+ return newrconfig;\r
+ }\r
\r
- public void setParameters(List<Parameter<T>> parameters) {\r
- this.parameters = parameters;\r
- }\r
+ /**\r
+ * Returns the list of the Options supported by the executable of type T\r
+ * \r
+ * @return list of {@link Option} supported by type T\r
+ * @see Option\r
+ */\r
+ public List<Option<T>> getOptions() {\r
+ return options;\r
+ }\r
\r
- /**\r
- * \r
- * @return List of {@link Parameter} supported by type T.\r
- */\r
- public List<Parameter<T>> getParameters() {\r
- return parameters;\r
- }\r
+ /**\r
+ * Adds parameter to the internal parameter list\r
+ * \r
+ * @param param\r
+ * the {@link Parameter} to add\r
+ * @see Parameter\r
+ */\r
+ public void addParameter(Parameter<T> param) {\r
+ assert param != null;\r
+ parameters.add(param);\r
+ }\r
\r
- @Override\r
- public String toString() {\r
- String value = "Runner: " + this.runnerClassName + SysPrefs.newlinechar;\r
- for (Option<T> par : this.getArguments()) {\r
- value += par;\r
+ /**\r
+ * Adds Option to the internal list of options\r
+ * \r
+ * @param option\r
+ * the {@link Option} to add\r
+ */\r
+ public void addOption(Option<T> option) {\r
+ assert option != null;\r
+ options.add(option);\r
}\r
- return value;\r
- }\r
\r
- /*\r
- * Cast is safe as runnerClassNames equality checked (non-Javadoc)\r
- * \r
- * @see java.lang.Object#equals(java.lang.Object)\r
- */\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
+ /**\r
+ * Returns list of {@link Parameter} and {@link Option} supported by current\r
+ * runner\r
+ * \r
+ * @return list of {@link Option} and {@link Parameter} supported by type T\r
+ */\r
+ @XmlTransient\r
+ public List<Option<T>> getArguments() {\r
+ arguments = new ArrayList<Option<T>>(options);\r
+ arguments.addAll(parameters);\r
+ return arguments;\r
}\r
- RunnerConfig<?> rconf = null;\r
- if (obj instanceof RunnerConfig) {\r
- rconf = (RunnerConfig) obj;\r
+\r
+ /**\r
+ * \r
+ * @return name value separator character\r
+ */\r
+ public String getPrmSeparator() {\r
+ return prmSeparator;\r
}\r
- if (!rconf.runnerClassName.equals(this.runnerClassName)) {\r
- return false;\r
+\r
+ /**\r
+ * Sets name value separator character\r
+ * \r
+ * @param prmSeparator\r
+ * the separator char\r
+ */\r
+ public void setPrmSeparator(String prmSeparator) {\r
+ this.prmSeparator = prmSeparator;\r
}\r
- if (this.options.size() != rconf.options.size()) {\r
- return false;\r
+\r
+ /**\r
+ * Adds the list of options or parameters to the internal list of options\r
+ * \r
+ * @param parameters\r
+ * the list of parameters to add\r
+ * \r
+ */\r
+ public void setOptions(List<Option<T>> parameters) {\r
+ this.options = parameters;\r
}\r
- if (this.parameters.size() != rconf.parameters.size()) {\r
- return false;\r
+\r
+ /**\r
+ * \r
+ * @return fully qualified class name for type T\r
+ */\r
+ @XmlElement(required = true)\r
+ public String getRunnerClassName() {\r
+ return runnerClassName;\r
}\r
- if (!this.prmSeparator.equals(rconf.prmSeparator)) {\r
- return false;\r
+\r
+ /**\r
+ * Set the name of a runner class\r
+ * \r
+ * @param runnerClassName\r
+ * the name of the executable wrapping class\r
+ */\r
+ public void setRunnerClassName(String runnerClassName) {\r
+ this.runnerClassName = runnerClassName;\r
}\r
- // Size of option list is the same at that point\r
- for (Option<T> op : options) {\r
- Option<T> roption = (Option<T>) rconf.getArgument(op.getName());\r
- if (roption == null) {\r
- return false;\r
- }\r
- if (!op.equals(roption)) {\r
- return false;\r
- }\r
+\r
+ /**\r
+ * Sets the list of parameters as internal list\r
+ * \r
+ * @param parameters\r
+ * the list of parameters\r
+ */\r
+ public void setParameters(List<Parameter<T>> parameters) {\r
+ this.parameters = parameters;\r
}\r
- // Size of parameters list is the same at that point\r
- for (Parameter<T> par : parameters) {\r
- Parameter<T> rpar = (Parameter<T>) rconf.getArgument(par.getName());\r
- if (rpar == null) {\r
- return false;\r
- }\r
- if (!par.equals(rpar)) {\r
- return false;\r
- }\r
+\r
+ /**\r
+ * Returns the list of parameters supported executable of type T. Where\r
+ * {@link Parameter} is an {@link Option} with value.\r
+ * \r
+ * @return List of {@link Parameter} supported by type T.\r
+ */\r
+ public List<Parameter<T>> getParameters() {\r
+ return parameters;\r
}\r
- return true;\r
- }\r
\r
- /**\r
- * Returns the argument by its name if found, NULL otherwise\r
- * \r
- * @param name\r
- * @return {@link Argument}\r
- */\r
- public Option<T> getArgument(String name) {\r
- for (Option<T> par : getArguments()) {\r
- if (par.getName().equalsIgnoreCase(name)) {\r
- return par;\r
- }\r
+ @Override\r
+ public String toString() {\r
+ String value = "Runner: " + this.runnerClassName + SysPrefs.newlinechar;\r
+ for (Option<T> par : this.getArguments()) {\r
+ value += par;\r
+ }\r
+ return value;\r
}\r
- return null;\r
- }\r
\r
- /**\r
- * Removes the argument {@link Argument} if found.\r
- * \r
- * @param name\r
- * of the argument\r
- * @return true if argument was removed, false otherwise\r
- */\r
- @SuppressWarnings("unchecked")\r
- // Just use raw type in instanceof this is safe\r
- public boolean removeArgument(String name) {\r
- Option<T> par = getArgument(name);\r
- if (par != null) {\r
- if (par instanceof Parameter) {\r
- parameters.remove(par);\r
- return true;\r
- } else {\r
- this.options.remove(par);\r
+ /*\r
+ * Cast is safe as runnerClassNames equality checked (non-Javadoc)\r
+ * @see java.lang.Object#equals(java.lang.Object)\r
+ */\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ RunnerConfig<?> rconf = null;\r
+ if (obj instanceof RunnerConfig) {\r
+ rconf = (RunnerConfig) obj;\r
+ }\r
+ if (!rconf.runnerClassName.equals(this.runnerClassName)) {\r
+ return false;\r
+ }\r
+ if (this.options.size() != rconf.options.size()) {\r
+ return false;\r
+ }\r
+ if (this.parameters.size() != rconf.parameters.size()) {\r
+ return false;\r
+ }\r
+ if (!this.prmSeparator.equals(rconf.prmSeparator)) {\r
+ return false;\r
+ }\r
+ // Size of option list is the same at that point\r
+ for (Option<T> op : options) {\r
+ Option<T> roption = (Option<T>) rconf.getArgument(op.getName());\r
+ if (roption == null) {\r
+ return false;\r
+ }\r
+ if (!op.equals(roption)) {\r
+ return false;\r
+ }\r
+ }\r
+ // Size of parameters list is the same at that point\r
+ for (Parameter<T> par : parameters) {\r
+ Parameter<T> rpar = (Parameter<T>) rconf.getArgument(par.getName());\r
+ if (rpar == null) {\r
+ return false;\r
+ }\r
+ if (!par.equals(rpar)) {\r
+ return false;\r
+ }\r
+ }\r
return true;\r
- }\r
}\r
- return false;\r
- }\r
\r
- /**\r
- * Returns the argument by option name, NULL if the argument is not found\r
- * \r
- * @param optionName\r
- * - the name of the option\r
- * @return Option\r
- */\r
- public Option<T> getArgumentByOptionName(String optionName) {\r
- for (Option<T> opt : getArguments()) {\r
- for (String val : opt.getOptionNames()) {\r
- if (val.equalsIgnoreCase(optionName)) {\r
- return opt;\r
+ /**\r
+ * Returns the argument by its name if found, NULL otherwise. Where the\r
+ * Argument is a common interface for {@link Option} and {@link Parameter}\r
+ * therefore this method can return either. If you need to retrieve the\r
+ * Option by its optionNames use @link\r
+ * {@link RunnerConfig#getArgumentByOptionName(String)} method. The\r
+ * difference between option name and optionName is explained by the\r
+ * following example:\r
+ * \r
+ * <pre>\r
+ * <name>Sequence type</name>\r
+ * <description>\r
+ * --nuc - Assume the sequences are nucleotide.\r
+ * --amino - Assume the sequences are amino acid. </description>\r
+ * <optionNames>--amino</optionNames>\r
+ * <optionNames>--nuc</optionNames>\r
+ * <optionNames>--auto</optionNames>\r
+ * </pre>\r
+ * \r
+ * In the example, the "Sequence type" is a name whereas --amino, --nuc and\r
+ * --auto are all optionNames. This dichotomy only manifests in\r
+ * <code>Option</code> never in <code>Parameters</code> as the latter can\r
+ * only have single <optioNames> element\r
+ * \r
+ * @param name\r
+ * the Parameter of Option name\r
+ * @return {@link Argument}\r
+ */\r
+ public Option<T> getArgument(String name) {\r
+ for (Option<T> par : getArguments()) {\r
+ if (par.getName().equalsIgnoreCase(name)) {\r
+ return par;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Removes the argument {@link Argument} if found. Where Argument is either\r
+ * {@link Option} or {@link Parameter}.\r
+ * \r
+ * @param name\r
+ * of the argument\r
+ * @return true if argument was removed, false otherwise\r
+ */\r
+ @SuppressWarnings("unchecked")\r
+ // Just use raw type in instanceof this is safe\r
+ public boolean removeArgument(String name) {\r
+ Option<T> par = getArgument(name);\r
+ if (par != null) {\r
+ if (par instanceof Parameter) {\r
+ parameters.remove(par);\r
+ return true;\r
+ } else {\r
+ this.options.remove(par);\r
+ return true;\r
+ }\r
}\r
- }\r
+ return false;\r
}\r
\r
- return null;\r
- }\r
+ /**\r
+ * Returns the argument by option name, NULL if the argument is not found\r
+ * \r
+ * @param optionName\r
+ * - the optionName. This is not the same as an Option name.\r
+ * \r
+ * For example:\r
+ * \r
+ * <pre>\r
+ * <name>Output sequences order</name>\r
+ * <description>--inputorder - Output order: same as input. \r
+ * --reorder - Output order: aligned. Default: same as input</description>\r
+ * <optionNames>--inputorder</optionNames>\r
+ * <optionNames>--reorder</optionNames>\r
+ * </pre>\r
+ * \r
+ * The name of the option in the example is\r
+ * "Output sequences order" whereas optionNames are\r
+ * "--inputorder" and "--reorder". If you need to retrieve the\r
+ * Option or Parameter by its names use\r
+ * {@link RunnerConfig#getArgument(String)} method\r
+ * @return Option\r
+ */\r
+ public Option<T> getArgumentByOptionName(String optionName) {\r
+ for (Option<T> opt : getArguments()) {\r
+ for (String val : opt.getOptionNames()) {\r
+ if (val.equalsIgnoreCase(optionName)) {\r
+ return opt;\r
+ }\r
+ }\r
+ }\r
\r
- /**\r
- * Removes the argument\r
- * \r
- * @param optionName\r
- * @return true if argument with optionName exists and was removed, false\r
- * otherwise\r
- */\r
- @SuppressWarnings("unchecked")\r
- // Just use raw type in instanceof this is safe\r
- public boolean removeArgumentByOptionName(String optionName) {\r
- Option<T> par = getArgumentByOptionName(optionName);\r
- if (par != null) {\r
- if (par instanceof Parameter) {\r
- this.parameters.remove(par);\r
- return true;\r
- } else {\r
- this.options.remove(par);\r
- return true;\r
- }\r
+ return null;\r
}\r
- return false;\r
- }\r
\r
- /**\r
- * Validate the arguments\r
- * \r
- * @throws ValidationException\r
- * if any of the arguments found invalid which is when\r
- * <dl>\r
- * <li>Parameter value outside {@link ValueConstrain} boundary</li>\r
- * <li>Parameter name is not listed in possible values</li>\r
- * </dl>\r
- */\r
- public void validate() throws ValidationException {\r
- for (Option<?> option : getArguments()) {\r
- option.validate();\r
+ /**\r
+ * Removes the argument which can be a Parameter or an Option instance by\r
+ * the value in <optionNames> element of the runner configuration\r
+ * descriptor.\r
+ * \r
+ * @param optionName\r
+ * the optionName of the option, do not confuse with the name!\r
+ * @return true if argument with optionName exists and was removed, false\r
+ * otherwise\r
+ * @see RunnerConfig#getArgumentByOptionName(String) for destinctions\r
+ * between optionNames and the name of the Option\r
+ */\r
+ @SuppressWarnings("unchecked")\r
+ // Just use raw type in instanceof this is safe\r
+ public boolean removeArgumentByOptionName(String optionName) {\r
+ Option<T> par = getArgumentByOptionName(optionName);\r
+ if (par != null) {\r
+ if (par instanceof Parameter) {\r
+ this.parameters.remove(par);\r
+ return true;\r
+ } else {\r
+ this.options.remove(par);\r
+ return true;\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ /**\r
+ * Validate the value of the argument. Checks whether the argument value is\r
+ * in the valid values range.\r
+ * \r
+ * @throws ValidationException\r
+ * if any of the arguments found invalid which is when\r
+ * <dl>\r
+ * <li>Parameter value outside {@link ValueConstrain} boundary</li>\r
+ * <li>Parameter name is not listed in possible values</li>\r
+ * </dl>\r
+ */\r
+ public void validate() throws ValidationException {\r
+ for (Option<?> option : getArguments()) {\r
+ option.validate();\r
+ }\r
}\r
- }\r
}\r
\r
/**\r
* Indicates that the server could not execute native executables. e.g. If Mafft\r
- * (unix executable) is asked to be run on Windows. In context of JWS2 this\r
+ * (unix executable) is asked to be run on Windows. In context of JABAWS this\r
* exception indicates that the service is deployed but is not able to run.\r
* \r
* @author pvtroshin\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class UnsupportedRuntimeException extends JobSubmissionException {\r
\r
- public UnsupportedRuntimeException(String message) {\r
- super(message);\r
- }\r
+ public UnsupportedRuntimeException(String message) {\r
+ super(message);\r
+ }\r
\r
- public UnsupportedRuntimeException(Throwable cause) {\r
- super(cause);\r
- }\r
+ public UnsupportedRuntimeException(Throwable cause) {\r
+ super(cause);\r
+ }\r
\r
- /**\r
+ /**\r
* \r
*/\r
- private static final long serialVersionUID = -86624836785110293L;\r
+ private static final long serialVersionUID = -86624836785110293L;\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date November 2009\r
+ * @version 1.0 November 2009\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
public class ValueConstrain {\r
\r
- public static enum Type {\r
- Integer, Float\r
- };\r
-\r
- @XmlElement(required = true)\r
- Type type;\r
- // These can contain different numeric types values, thus they are strings\r
- String max;\r
- String min;\r
-\r
- public Type getType() {\r
- return type;\r
- }\r
-\r
- public void setType(Type type) {\r
- this.type = type;\r
- }\r
-\r
- public Number getMax() {\r
- if (Util.isEmpty(max)) {\r
- return null;\r
- }\r
- switch (type) {\r
- case Float:\r
- return Double.parseDouble(max);\r
- case Integer:\r
- return Integer.parseInt(max);\r
- }\r
- // should not happened\r
- throw new RuntimeException("Type is undefined! ");\r
- }\r
-\r
- public void setMax(String max) {\r
- this.max = max;\r
- }\r
-\r
- public Number getMin() {\r
- if (Util.isEmpty(min)) {\r
- return null;\r
- }\r
- switch (type) {\r
- case Float:\r
- return Double.parseDouble(min);\r
- case Integer:\r
- return Integer.parseInt(min);\r
- }\r
- // should not happened\r
- throw new RuntimeException("Type is undefined! ");\r
- }\r
-\r
- public void setMin(String min) {\r
- this.min = min;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null) {\r
- return false;\r
- }\r
- ValueConstrain constr = null;\r
- if (obj instanceof ValueConstrain) {\r
- constr = (ValueConstrain) obj;\r
- } else {\r
- return false;\r
- }\r
- if (this.type != constr.type) {\r
- return false;\r
- }\r
- if (this.max != null && constr.max != null) {\r
- if (!this.max.equals(constr.max)) {\r
- return false;\r
- }\r
- } else {\r
- return false;\r
- }\r
-\r
- if (this.min != null && constr.min != null) {\r
- if (!this.min.equals(constr.min)) {\r
- return false;\r
- }\r
- } else {\r
- return false;\r
- }\r
-\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- String value = "Type: " + this.type + "\n";\r
- if (this.min != null) {\r
- value += "Min: " + this.min + "\n";\r
- }\r
- if (this.max != null) {\r
- value += "Max: " + this.max + "\n";\r
- }\r
- return value;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- int code = type.hashCode();\r
- if (this.max != null) {\r
- code *= this.max.hashCode();\r
- }\r
- if (this.min != null) {\r
- code *= this.min.hashCode();\r
- }\r
- return code;\r
- }\r
-\r
- boolean hasMinValue() {\r
- return !Util.isEmpty(min);\r
- }\r
-\r
- boolean hasMaxValue() {\r
- return !Util.isEmpty(max);\r
- }\r
-\r
- /**\r
- * Validate that the value is within the constrain boundaries\r
- * \r
- * @param value\r
- * @throws IndexOutOfBoundsException\r
- * when the value is outside the defined boundaries\r
- */\r
- void checkValue(String value) {\r
- switch (type) {\r
- case Float:\r
- float val = Float.parseFloat(value);\r
- if (getMin() != null\r
- && new Float(this.getMin().floatValue()).compareTo(val) == 1) {\r
- throw new IndexOutOfBoundsException("Value '" + value\r
- + "' is lower that minumim value '" + getMin() + "'");\r
- }\r
- if (getMax() != null\r
- && new Float(this.getMax().floatValue()).compareTo(val) == -1) {\r
- throw new IndexOutOfBoundsException("Value '" + value\r
- + "' is greater that maximum value '" + getMax() + "'");\r
- }\r
- break;\r
- case Integer:\r
- int ival = Integer.parseInt(value);\r
- if (getMin() != null\r
- && new Integer(this.getMin().intValue()).compareTo(ival) == 1) {\r
- throw new IndexOutOfBoundsException("Value '" + value\r
- + "' is lower that minumim value '" + getMin() + "'");\r
- }\r
- if (getMax() != null\r
- && new Integer(this.getMax().intValue()).compareTo(ival) == -1) {\r
- throw new IndexOutOfBoundsException("Value '" + value\r
- + "' is greater that maximum value '" + getMax() + "'");\r
- }\r
- break;\r
- }\r
- }\r
-\r
- /**\r
- * Validate the ValueConstrain object. For the ValueConstrain object the\r
- * type and at least one boundary has to be defined\r
- * \r
- * @throws ValidationException\r
- * - if the type or no boundaries are defined\r
- */\r
- void validate() throws ValidationException {\r
- if (this.type == null) {\r
- throw new ValidationException(\r
- "Type is not defined for ValueConstrain: " + this);\r
- }\r
- if (Util.isEmpty(min) && Util.isEmpty(max)) {\r
- throw new ValidationException(\r
- "Both boundaries (min and max) is undefined for ValueConstrain: "\r
- + this);\r
+ public static enum Type {\r
+ Integer, Float\r
+ };\r
+\r
+ @XmlElement(required = true)\r
+ Type type;\r
+ // These can contain different numeric types values, thus they are strings\r
+ String max;\r
+ String min;\r
+\r
+ public Type getType() {\r
+ return type;\r
+ }\r
+\r
+ public void setType(Type type) {\r
+ this.type = type;\r
+ }\r
+\r
+ public Number getMax() {\r
+ if (Util.isEmpty(max)) {\r
+ return null;\r
+ }\r
+ switch (type) {\r
+ case Float:\r
+ return Double.parseDouble(max);\r
+ case Integer:\r
+ return Integer.parseInt(max);\r
+ }\r
+ // should not happened\r
+ throw new RuntimeException("Type is undefined! ");\r
+ }\r
+\r
+ public void setMax(String max) {\r
+ this.max = max;\r
+ }\r
+\r
+ public Number getMin() {\r
+ if (Util.isEmpty(min)) {\r
+ return null;\r
+ }\r
+ switch (type) {\r
+ case Float:\r
+ return Double.parseDouble(min);\r
+ case Integer:\r
+ return Integer.parseInt(min);\r
+ }\r
+ // should not happened\r
+ throw new RuntimeException("Type is undefined! ");\r
+ }\r
+\r
+ public void setMin(String min) {\r
+ this.min = min;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ if (obj == null) {\r
+ return false;\r
+ }\r
+ ValueConstrain constr = null;\r
+ if (obj instanceof ValueConstrain) {\r
+ constr = (ValueConstrain) obj;\r
+ } else {\r
+ return false;\r
+ }\r
+ if (this.type != constr.type) {\r
+ return false;\r
+ }\r
+ if (this.max != null && constr.max != null) {\r
+ if (!this.max.equals(constr.max)) {\r
+ return false;\r
+ }\r
+ } else {\r
+ return false;\r
+ }\r
+\r
+ if (this.min != null && constr.min != null) {\r
+ if (!this.min.equals(constr.min)) {\r
+ return false;\r
+ }\r
+ } else {\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ String value = "Type: " + this.type + "\n";\r
+ if (this.min != null) {\r
+ value += "Min: " + this.min + "\n";\r
+ }\r
+ if (this.max != null) {\r
+ value += "Max: " + this.max + "\n";\r
+ }\r
+ return value;\r
+ }\r
+\r
+ @Override\r
+ public int hashCode() {\r
+ int code = type.hashCode();\r
+ if (this.max != null) {\r
+ code *= this.max.hashCode();\r
+ }\r
+ if (this.min != null) {\r
+ code *= this.min.hashCode();\r
+ }\r
+ return code;\r
+ }\r
+\r
+ boolean hasMinValue() {\r
+ return !Util.isEmpty(min);\r
+ }\r
+\r
+ boolean hasMaxValue() {\r
+ return !Util.isEmpty(max);\r
+ }\r
+\r
+ /**\r
+ * Validate that the value is within the constrain boundaries\r
+ * \r
+ * @param value\r
+ * @throws IndexOutOfBoundsException\r
+ * when the value is outside the defined boundaries\r
+ */\r
+ void checkValue(String value) {\r
+ switch (type) {\r
+ case Float:\r
+ float val = Float.parseFloat(value);\r
+ if (getMin() != null\r
+ && new Float(this.getMin().floatValue()).compareTo(val) == 1) {\r
+ throw new IndexOutOfBoundsException("Value '" + value\r
+ + "' is lower that minumim value '" + getMin() + "'");\r
+ }\r
+ if (getMax() != null\r
+ && new Float(this.getMax().floatValue()).compareTo(val) == -1) {\r
+ throw new IndexOutOfBoundsException("Value '" + value\r
+ + "' is greater that maximum value '" + getMax() + "'");\r
+ }\r
+ break;\r
+ case Integer:\r
+ int ival = Integer.parseInt(value);\r
+ if (getMin() != null\r
+ && new Integer(this.getMin().intValue()).compareTo(ival) == 1) {\r
+ throw new IndexOutOfBoundsException("Value '" + value\r
+ + "' is lower that minumim value '" + getMin() + "'");\r
+ }\r
+ if (getMax() != null\r
+ && new Integer(this.getMax().intValue()).compareTo(ival) == -1) {\r
+ throw new IndexOutOfBoundsException("Value '" + value\r
+ + "' is greater that maximum value '" + getMax() + "'");\r
+ }\r
+ break;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Validate the ValueConstrain object. For the ValueConstrain object the\r
+ * type and at least one boundary has to be defined\r
+ * \r
+ * @throws ValidationException\r
+ * - if the type or no boundaries are defined\r
+ */\r
+ void validate() throws ValidationException {\r
+ if (this.type == null) {\r
+ throw new ValidationException(\r
+ "Type is not defined for ValueConstrain: " + this);\r
+ }\r
+ if (Util.isEmpty(min) && Util.isEmpty(max)) {\r
+ throw new ValidationException(\r
+ "Both boundaries (min and max) is undefined for ValueConstrain: "\r
+ + this);\r
+ }\r
}\r
- }\r
\r
}\r
* \r
* @author pvtroshin\r
* \r
- * Date October 2009\r
+ * @version 1.0 October 2009\r
*/\r
public class WrongParameterException extends Exception {\r
\r
- /**\r
- * Default stable serial for serialization\r
- */\r
- private static final long serialVersionUID = -547775417557345769L;\r
+ /**\r
+ * Default stable serial for serialization\r
+ */\r
+ private static final long serialVersionUID = -547775417557345769L;\r
\r
- public WrongParameterException(Option<?> option) {\r
- this("Wrong option is: " + option.toString());\r
- }\r
+ public WrongParameterException(Option<?> option) {\r
+ this("Wrong option is: " + option.toString());\r
+ }\r
\r
- public WrongParameterException(String message) {\r
- super(message);\r
- }\r
+ public WrongParameterException(String message) {\r
+ super(message);\r
+ }\r
\r
- public WrongParameterException(Throwable cause) {\r
- super(cause);\r
- }\r
+ public WrongParameterException(Throwable cause) {\r
+ super(cause);\r
+ }\r
\r
- public WrongParameterException(String message, Throwable cause) {\r
- super(message, cause);\r
- }\r
+ public WrongParameterException(String message, Throwable cause) {\r
+ super(message, cause);\r
+ }\r
\r
}\r
/**\r
* A meta-data model for multiple sequence alignment web services \r
* Classes in this package have no dependencies to other sources in the project. \r
- * They form a base layer of JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0. \r
- * \r
- * @author Petr Troshin \r
- * \r
- * Date January 2010\r
+ * They form a base layer of JAva Bioinformatics Analysis Web Services (JABAWS)\r
* \r
+ * @author Peter Troshin \r
* \r
+ * @version 1.0 January 2010\r
*/\r
package compbio.metadata;\r
\r