X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=datamodel%2Fcompbio%2Fmetadata%2FLimit.java;h=81328321226d4af8415d201ab43fae3d789fd5a7;hb=b05d1f756857fa5e4f67ad00d51d0a7ecbcbb505;hp=cbbb3a71fde992588573ade1f5d323b4e6c239bf;hpb=73ca89ba470d6251d2f37ae6b7f443f133c35ab9;p=jabaws.git diff --git a/datamodel/compbio/metadata/Limit.java b/datamodel/compbio/metadata/Limit.java index cbbb3a7..8132832 100644 --- a/datamodel/compbio/metadata/Limit.java +++ b/datamodel/compbio/metadata/Limit.java @@ -29,9 +29,9 @@ import compbio.util.SysPrefs; /** * A value object containing a maximum number of sequences and a maximum average - * sequence length for a preset. + * sequence length for a preset. Also contains static method for determining the + * number of sequence and their average length in the List * - * @see LimitsManager * * @author pvtroshin * @@ -40,12 +40,16 @@ import compbio.util.SysPrefs; * @param * the type of an executable for which this limit is defined. * + * @see LimitsManager */ @XmlAccessorType(XmlAccessType.FIELD) public class Limit { + // Allowed to be null private String preset; + // Cannot be 0 or below private int seqNumber; + // Can be 0 - i.e. undefined private int seqLength; @XmlAttribute @@ -55,13 +59,26 @@ public class Limit { // JAXB default constructor } + /** + * Instantiate the limit + * + * @param seqNumber + * the maximum number of sequences allowed for calculation. + * Required + * @param seqLength + * the average length of the sequence, optional + * @param preset + * the name of preset if any, optional + * @throws IllegalArgumentException + * if the seqNumber is not supplied or the seqLength is negative + */ 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) { + if (seqLength < 0) { throw new IllegalArgumentException( "seqLength - an average sequence length must be greater than 0. Value given:" + seqLength); @@ -81,14 +98,26 @@ public class Limit { return preset; } + /** + * + * @return the allowed average sequence length + */ public int getAvgSeqLength() { return seqLength; } + /** + * + * @return the maximum number of sequences allowed + */ public int getSeqNumber() { return seqNumber; } + /** + * + * @return true is this is a default limit to be used, false otherwise + */ public boolean isDefault() { return isDefault; } @@ -128,27 +157,38 @@ public class Limit { public String toString() { String value = ""; if (isDefault) { - value = "Default Limit" + SysPrefs.newlinechar; + value = "Default Limits:" + SysPrefs.newlinechar; } else { - value = "Limit for Preset '" + preset + "'" + SysPrefs.newlinechar; + value = "Limits for Preset '" + preset + "'" + SysPrefs.newlinechar; } value += "Maximum sequence number=" + seqNumber + SysPrefs.newlinechar; value += "Average sequence length=" + seqLength + SysPrefs.newlinechar; - value += SysPrefs.newlinechar; return value; } + /* + * Calculates total number of letters allowed + */ 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 + * exceeds this limit. * * @param data + * the dataset to measure * @return true if a limit is exceeded (what is the dataset is larger then - * the limit), false otherwise. + * the limit), false otherwise. First check the number of sequences + * in the dataset and if it exceeds the limit return true + * irrespective of the average length. If the number of sequences in + * the dataset is less than the limit and average length is defined, + * then check whether the total number of letters (number of + * sequence multiplied by the average sequence length) is greater + * then the total number of letters in the dataset. Returns true if + * the total number of letters in the dataset is greater than the + * limit, false otherwise. */ public boolean isExceeded(List data) { if (data == null) { @@ -158,8 +198,8 @@ public class Limit { if (data.size() > this.seqNumber) { return true; } - if (this.seqLength != 0) { - if ((long) getAvgSeqLength() * data.size() > numberOfLetters()) { + if (this.seqLength != 0 && data.size() > 0) { + if ((long) getAvgSequenceLength(data) * data.size() > numberOfLetters()) { return true; } }