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