| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MetaSetRule |
|
| 1.8333333333333333;1.833 |
| 1 | /****************************************************************************** | |
| 2 | * MetaSetRule.java - Define one rule in a MetaSet | |
| 3 | * | |
| 4 | * PicMan - The BuckoSoft Picture Manager in Java | |
| 5 | * Copyright(c) 2006 - Dick Balaska | |
| 6 | * | |
| 7 | */ | |
| 8 | package com.buckosoft.PicMan.domain; | |
| 9 | ||
| 10 | /** Define one rule in a MetaSet. | |
| 11 | * A rule contains either a value, which is the name of the Set we are filtering, | |
| 12 | * or if the rule is an operator than this rule is the type of operator to apply to the next rule. <br/> | |
| 13 | * function -2 is a datestamp where the value string is a date of YYYY-MM-DD | |
| 14 | * @author Dick Balaska | |
| 15 | * @since 20060704 | |
| 16 | */ | |
| 17 | public class MetaSetRule { | |
| 18 | private int sid; // The set we belong to | |
| 19 | private int index; // The rule number | |
| 20 | ||
| 21 | private int type; // enum name, operator, function | |
| 22 | private String value; // value for this rule | |
| 23 | private int operator; // if the type is operator, then this is the value of the operator | |
| 24 | 0 | private int rateOp = 0; // operator for the rating filter (<, >, ==, !=) |
| 25 | private int rateVal; // value for the rating filter | |
| 26 | // if the type is function, then this is the function number | |
| 27 | ||
| 28 | /** Default constructor */ | |
| 29 | 0 | public MetaSetRule() {} |
| 30 | ||
| 31 | /** Convienence constructor that fills in the attributes of this Rule. | |
| 32 | * @param sid The Set ID that this rule belongs to | |
| 33 | * @param index The index into the list that is this rule. | |
| 34 | * @param type name or operator | |
| 35 | * @param value if this rule is a name, then this is the Set name that makes up this rule | |
| 36 | * @param operator If this rule is an operator, than this is value of the operator. | |
| 37 | */ | |
| 38 | 0 | public MetaSetRule(int sid, int index, int type, String value, int operator) { |
| 39 | 0 | this.sid = sid; |
| 40 | 0 | this.index = index; |
| 41 | 0 | this.type = type; |
| 42 | 0 | this.value = value; |
| 43 | 0 | this.operator = operator; |
| 44 | 0 | } |
| 45 | ||
| 46 | /** Get the Set ID for this rule | |
| 47 | * @return Returns the sid. | |
| 48 | */ | |
| 49 | public int getSid() { | |
| 50 | 0 | return sid; |
| 51 | } | |
| 52 | /** Set the Set ID for the MetaSet that this rule belongs to. | |
| 53 | * @param sid The sid to set. | |
| 54 | */ | |
| 55 | public void setSid(int sid) { | |
| 56 | 0 | this.sid = sid; |
| 57 | 0 | } |
| 58 | /** Get the index into the list of rules that is this rule. | |
| 59 | * @return Returns the index. | |
| 60 | */ | |
| 61 | public int getIndex() { | |
| 62 | 0 | return index; |
| 63 | } | |
| 64 | /** Set the index into the list of rules that is this rule. | |
| 65 | * While it may be apparant that just existing at a particular index is sufficient to identify a rule, | |
| 66 | * this attribute is needed for persistence. | |
| 67 | * @param index The index to set. | |
| 68 | */ | |
| 69 | public void setIndex(int index) { | |
| 70 | 0 | this.index = index; |
| 71 | 0 | } |
| 72 | /** Is this rule a MetaSet.NAME or a MetaSet.OPERATOR | |
| 73 | * @return Returns the type. | |
| 74 | */ | |
| 75 | public int getType() { | |
| 76 | 0 | return type; |
| 77 | } | |
| 78 | /** | |
| 79 | * @param type The type to set. | |
| 80 | */ | |
| 81 | public void setType(int type) { | |
| 82 | 0 | this.type = type; |
| 83 | 0 | } |
| 84 | /** | |
| 85 | * @return Returns the value. | |
| 86 | */ | |
| 87 | public String getValue() { | |
| 88 | 0 | if (this.type == MetaSet.OPERATOR) { |
| 89 | 0 | if (this.operator == MetaSet.NONE) |
| 90 | 0 | return(MetaSet.s_NONE); |
| 91 | 0 | else if (this.operator == MetaSet.AND) |
| 92 | 0 | return(MetaSet.s_AND); |
| 93 | 0 | else if (this.operator == MetaSet.OR) |
| 94 | 0 | return(MetaSet.s_OR); |
| 95 | 0 | else if (this.operator == MetaSet.NOT) |
| 96 | 0 | return(MetaSet.s_NOT); |
| 97 | 0 | return(MetaSet.s_UNKNOWN); |
| 98 | } | |
| 99 | 0 | return value; |
| 100 | } | |
| 101 | /** | |
| 102 | * @param value The value to set. | |
| 103 | */ | |
| 104 | public void setValue(String value) { | |
| 105 | 0 | this.value = value; |
| 106 | 0 | if (this.type == MetaSet.OPERATOR) { |
| 107 | 0 | if (value.equals(MetaSet.s_NONE)) |
| 108 | 0 | this.setOperator(MetaSet.NONE); |
| 109 | 0 | else if (value.equals(MetaSet.s_AND)) |
| 110 | 0 | this.setOperator(MetaSet.AND); |
| 111 | 0 | else if (value.equals(MetaSet.s_OR)) |
| 112 | 0 | this.setOperator(MetaSet.OR); |
| 113 | 0 | else if (value.equals(MetaSet.s_NOT)) |
| 114 | 0 | this.setOperator(MetaSet.NOT); |
| 115 | } | |
| 116 | 0 | } |
| 117 | /** | |
| 118 | * @return Returns the operator. | |
| 119 | */ | |
| 120 | public int getOperator() { | |
| 121 | 0 | return operator; |
| 122 | } | |
| 123 | /** | |
| 124 | * @param operator The operator to set. | |
| 125 | */ | |
| 126 | public void setOperator(int operator) { | |
| 127 | 0 | this.operator = operator; |
| 128 | 0 | } |
| 129 | ||
| 130 | /** | |
| 131 | * @return the rateOp | |
| 132 | */ | |
| 133 | public int getRateOp() { | |
| 134 | 0 | return rateOp; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * @param rateOp the rateOp to set | |
| 139 | */ | |
| 140 | public void setRateOp(int rateOp) { | |
| 141 | 0 | this.rateOp = rateOp; |
| 142 | 0 | } |
| 143 | ||
| 144 | /** | |
| 145 | * @return the rateVal | |
| 146 | */ | |
| 147 | public int getRateVal() { | |
| 148 | 0 | return rateVal; |
| 149 | } | |
| 150 | ||
| 151 | /** | |
| 152 | * @param rateVal the rateVal to set | |
| 153 | */ | |
| 154 | public void setRateVal(int rateVal) { | |
| 155 | 0 | this.rateVal = rateVal; |
| 156 | 0 | } |
| 157 | ||
| 158 | /** Return the function number of this rule, if we are a function | |
| 159 | * @return The function number | |
| 160 | */ | |
| 161 | public int getFunc() { | |
| 162 | 0 | return(rateVal); |
| 163 | } | |
| 164 | ||
| 165 | public void setFunc(int func) { | |
| 166 | 0 | this.rateVal = func; |
| 167 | 0 | } |
| 168 | ||
| 169 | } |