View Javadoc
1   /******************************************************************************
2    * Set.java - a set bean, define a group of pictures
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2005 - Dick Balaska
6    * 
7    */
8   package com.buckosoft.PicMan.domain;
9   
10  import java.io.Serializable;
11  import java.util.Comparator;
12  import java.util.Date;
13  
14  public class Set implements Serializable, Comparator<Set> {
15  	private static final long serialVersionUID = 1L;
16  	
17  	public final static String	FUNC_NAME_DATE	= "[date]";
18  	public final static int		FUNC_SID_DATE	= -2;
19  	public final static String	FUNC_NAME_ROOT	= "[root]";
20  	public final static int		FUNC_SID_ROOT	= -3;
21  
22  	
23  	private	int		sid;
24  	private	String	name;
25  	private	String	description;
26  	private	boolean	active = true;
27  	private	boolean	metaSet = false;
28  	private	boolean	microSet = false;
29  	private boolean nanoSet = false;
30  	private	Date	editDate = new Date();
31  
32  	/** Default constructor, create an empty set.
33  	 */
34  	public Set() {
35  	}
36  	
37  	/** Convienence constructor to preset some values.
38  	 * @param sid The set id to set
39  	 * @param name The name of this set
40  	 */
41  	public Set(int sid, String name) {
42  		this.sid = sid;
43  		this.name = name;
44  	}
45  
46  	/** Clone this set.
47  	 * @return A copy of this Set.
48  	 */
49  	public Set clone() {
50  		Set set = new Set();
51  		set.setSid(this.getSid());
52  		set.setName(this.getName());
53  		set.setDescription(this.getDescription());
54  		set.setActive(this.isActive());
55  		set.setMetaSet(this.isMetaSet());
56  		set.setMicroSet(this.isMicroSet());
57  		set.setNanoSet(this.isNanoSet());
58  		set.editDate.setTime(this.editDate.getTime());
59  		return(set);
60  	}
61  
62  	
63  	/* (non-Javadoc)
64  	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
65  	 */
66  	public int compare(Set set0, Set set1) {
67  		if (!set1.name.equals(set0.name))
68  			return(set1.name.compareTo(set0.name));
69  		if (!set1.description.equals(set0.description))
70  			return(set1.description.compareTo(set0.description));
71  		if (set0.sid != set1.sid)
72  			return(set1.sid - set0.sid);
73  		if (set0.active != set1.active)
74  			return(set1.active ? 1 : -1);
75  		if (set0.metaSet != set1.metaSet)
76  			return(set1.metaSet ? 1 : -1);
77  		if (set0.microSet != set1.microSet)
78  			return(set1.microSet ? 1 : -1);
79  		if (set0.nanoSet != set1.nanoSet)
80  			return(set1.nanoSet ? 1 : -1);
81  		if (set0.editDate.getTime() != set1.editDate.getTime())
82  			return((int)(set1.editDate.getTime() - set0.editDate.getTime()));
83  		return 0;
84  	}
85  
86  
87  	/** Fetch the PicMan unique Set id.
88  	 * @return Returns the set id.
89  	 */
90  	public int getSid() {
91  		return sid;
92  	}
93  	/**
94  	 * @param sid The set id to set.
95  	 */
96  	public void setSid(int sid) {
97  		this.sid = sid;
98  	}
99  	public	void	setName(String name) { this.name = name; }
100 	public	String	getName() { return(name); }
101 	
102 	/** Set the user's desciption of this set.
103 	 * @param description
104 	 */
105 	public void setDescription(String description) {
106 		this.description = description; 
107 	}
108 
109 	public	String	getDescription() { return(description); }
110 	/**
111 	 * @return Returns whether this Set is active.
112 	 */
113 	public boolean isActive() {
114 		return active;
115 	}
116 	/**
117 	 * @param active Set whether this Set is active.
118 	 */
119 	public void setActive(boolean active) {
120 		this.active = active;
121 	}
122 	/** Is this a metaSet?
123 	 * @return Returns the metaSet flag.
124 	 */
125 	public boolean isMetaSet() {
126 		return metaSet;
127 	}
128 	/**
129 	 * @param metaSet The metaSet to set.
130 	 */
131 	public void setMetaSet(boolean metaSet) {
132 		this.metaSet = metaSet;
133 	}
134 	/** Is this a microSet?
135 	 * @return the microSet
136 	 */
137 	public boolean isMicroSet() {
138 		return microSet;
139 	}
140 	/**
141 	 * @param microSet the microSet to set
142 	 */
143 	public void setMicroSet(boolean microSet) {
144 		this.microSet = microSet;
145 	}
146 	/** Is this a nanoSet?
147 	 * A pic in a nanoSet contains a boolean yes/no value.
148 	 * @return the nanoSet
149 	 */
150 	public boolean isNanoSet() {
151 		return nanoSet;
152 	}
153 	/**
154 	 * @param nanoSet the nanoSet to set
155 	 */
156 	public void setNanoSet(boolean nanoSet) {
157 		this.nanoSet = nanoSet;
158 	}
159 
160 	public boolean	isFuncSet() {
161 		return(this.sid < -1);
162 	}
163 
164 	/**
165 	 * @return the editDate
166 	 */
167 	public Date getEditDate() {
168 		return editDate;
169 	}
170 
171 	/**
172 	 * @param editDate the editDate to set
173 	 */
174 	public void setEditDate(Date editDate) {
175 		this.editDate = editDate;
176 	}
177 
178 	/** Set the time of this set's edit to be now.
179 	 */
180 	public void setEditDateNow() {
181 		this.editDate = new Date();
182 	}
183 }