View Javadoc
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  	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  	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  	public MetaSetRule(int sid, int index, int type, String value, int operator) {
39  		this.sid = sid;
40  		this.index = index;
41  		this.type = type;
42  		this.value = value;
43  		this.operator = operator;
44  	}
45  
46  	/** Get the Set ID for this rule
47  	 * @return Returns the sid.
48  	 */
49  	public int getSid() {
50  		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  		this.sid = sid;
57  	}
58  	/** Get the index into the list of rules that is this rule. 
59  	 * @return Returns the index.
60  	 */
61  	public int getIndex() {
62  		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  		this.index = index;
71  	}
72  	/** Is this rule a MetaSet.NAME or a MetaSet.OPERATOR
73  	 * @return Returns the type.
74  	 */
75  	public int getType() {
76  		return type;
77  	}
78  	/**
79  	 * @param type The type to set.
80  	 */
81  	public void setType(int type) {
82  		this.type = type;
83  	}
84  	/**
85  	 * @return Returns the value.
86  	 */
87  	public String getValue() {
88  		if (this.type == MetaSet.OPERATOR) {
89  	   		if (this.operator == MetaSet.NONE)
90  				return(MetaSet.s_NONE);
91  			else if (this.operator == MetaSet.AND)
92  				return(MetaSet.s_AND);
93  			else if (this.operator == MetaSet.OR)
94  				return(MetaSet.s_OR);
95  			else if (this.operator == MetaSet.NOT)
96  				return(MetaSet.s_NOT);
97  			return(MetaSet.s_UNKNOWN);
98  		}
99  		return value;
100 	}
101 	/**
102 	 * @param value The value to set.
103 	 */
104 	public void setValue(String value) {
105 		this.value = value;
106 		if (this.type == MetaSet.OPERATOR) {
107 	   		if (value.equals(MetaSet.s_NONE))
108 				this.setOperator(MetaSet.NONE);
109 			else if (value.equals(MetaSet.s_AND))
110 				this.setOperator(MetaSet.AND);
111 			else if (value.equals(MetaSet.s_OR))
112 				this.setOperator(MetaSet.OR);
113 			else if (value.equals(MetaSet.s_NOT))
114 				this.setOperator(MetaSet.NOT);
115 		}
116 	}
117 	/**
118 	 * @return Returns the operator.
119 	 */
120 	public int getOperator() {
121 		return operator;
122 	}
123 	/**
124 	 * @param operator The operator to set.
125 	 */
126 	public void setOperator(int operator) {
127 		this.operator = operator;
128 	}
129 
130 	/**
131 	 * @return the rateOp
132 	 */
133 	public int getRateOp() {
134 		return rateOp;
135 	}
136 
137 	/**
138 	 * @param rateOp the rateOp to set
139 	 */
140 	public void setRateOp(int rateOp) {
141 		this.rateOp = rateOp;
142 	}
143 
144 	/**
145 	 * @return the rateVal
146 	 */
147 	public int getRateVal() {
148 		return rateVal;
149 	}
150 
151 	/**
152 	 * @param rateVal the rateVal to set
153 	 */
154 	public void setRateVal(int rateVal) {
155 		this.rateVal = rateVal;
156 	}
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 		return(rateVal);
163 	}
164 	
165 	public void setFunc(int func) {
166 		this.rateVal = func;
167 	}
168 
169 }