View Javadoc
1   /******************************************************************************
2    * MetaSet.java - Define a MetaSet, a set of rules to determine a set
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  import java.util.LinkedList;
11  import java.util.List;
12  
13  /** Define a MetaSet, a set of rules to determine a set.
14   * This is primarily a List of {@link MetaSetRule}.
15   * The methods of actually determining the pics in a MetaSet reside in {@link com.buckosoft.PicMan.db.logic.MetaSetFilter}. 
16   * @author Dick Balaska
17   * @since 20060704
18   * @see MetaSetRule
19   * @see com.buckosoft.PicMan.db.logic.MetaSetFilter
20   */
21  public class MetaSet {
22  	public final static int	NAME		= 0;
23  	public final static int	OPERATOR	= 1;
24  	public final static int	FUNCTION	= 2;
25  	
26  	public final static int	NONE		= 0;
27  	public final static int	AND			= 1;
28  	public final static int	OR			= 2;
29  	public final static int	NOT			= 3;
30  	
31  	public final static String	s_NONE		= "NONE";
32  	public final static String	s_AND		= "AND";
33  	public final static String	s_OR		= "OR";
34  	public final static String	s_NOT		= "NOT";
35  	public final static String	s_UNKNOWN	= "UNKNOWN";
36  
37  	//     final static int	NONE	= 0;
38  	public final static int	LT		= 1;
39  	public final static int	GT		= 2;
40  	public final static int	EQ		= 3;
41  	public final static int	NE		= 4;
42  	
43  	public final static String	s_LT		= "<";
44  	public final static String	s_GT		= ">";
45  	public final static String	s_EQ		= "=";
46  	public final static String	s_NE		= "!=";
47  	
48  	public final static String[] rateOps = { "", s_LT, s_GT, s_EQ, s_NE };
49  	
50  	/** editing jsp needs an upper limit */
51  	public static final int MAX_RULES = 51;
52  	
53  	private	int	sid = -1;
54  	private	LinkedList<MetaSetRule>	list = new LinkedList<MetaSetRule>();
55  
56  	/** Get the Set ID
57  	 * @return the sid
58  	 */
59  	public int getSid() {
60  		return sid;
61  	}
62  	/** Set the Set ID 
63  	 * @param sid the sid to set
64  	 */
65  	public void setSid(int sid) {
66  		this.sid = sid;
67  	}
68  	/** Get the number of rules in this MetaSet
69  	 * @return The 
70  	 */
71  	public int getRuleCount() {
72  		return(list.size());
73  	}
74  	
75  	/** Get the list of rules in this MetaSet
76  	 * @return The list of {@link MetaSetRule}s.
77  	 */
78  	public	List<MetaSetRule>	getRules() {
79  		return(list);
80  	}
81  
82  	/** Get one rule from the list of rules.
83  	 * @param index The index into the list that we want to return (0 based).
84  	 * @return A MetaSetRule or null if the index is out of range.
85  	 */
86  	public	MetaSetRule getRule(int index) {
87  		if (index < this.getRuleCount())
88  			return((MetaSetRule)list.get(index));
89  		return(null);
90  	}
91  	
92  	/** Add a rule to this MetaSet
93  	 * @param rule The MetaSetRule to add
94  	 */
95  	public	void	addRule(MetaSetRule rule) {
96  		if (rule.getIndex() == -1)
97  			this.list.add(rule);
98  		else
99  			this.list.add(rule.getIndex(), rule);
100 	}
101 }