View Javadoc
1   /******************************************************************************
2    * ContactParams.java - Define how to make one contact sheet
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.text.DecimalFormat;
11  
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  
15  /** Define the rules to make one contact sheet.
16   * @author Dick Balaska
17   * @since 2005/08/07
18   * @see <a href="http://cvs.buckosoft.com/Projects/PicMan/PicMan/src/main/java/com/buckosoft/PicMan/domain/ContactParams.java">ContactParams.java</a>
19   */
20  public class ContactParams {
21  	private static final boolean DEBUG = false;
22  	protected final Log logger = LogFactory.getLog(getClass());
23  
24  	private	int		cid;
25  	private	String	setName;
26  	private	int		size;
27  	private	int		rankMin;
28  	private	int		rankMax;
29  	private	String	engineName;
30  	
31  	private	String	outputDirectory;
32  	private	int		contactNumber;
33  //	private	int		typeHint;
34  
35  	public ContactParams() {}
36  	
37  	public ContactParams(int cid, String setName, int size, int item) {
38  		this.cid = cid;
39  		this.setName = setName;
40  		this.size = size;
41  		this.contactNumber = item;
42  	}
43  	public ContactParams(SetSize setSize) {
44  		setSetSize(setSize);
45  	}
46  	
47  	/** Compare two ContactParams for equality.<br>
48  	 * Compare chain, setName, size, and contactNumber.<br>
49  	 * either size = -1 is a wildcard and will match (contactNumber is ignored in this case).<br>
50  	 * either contactNumber = -1 is a wildcard and will match.
51  	 * @param other The other ContactParams to compare to.
52  	 * @return equality
53  	 */
54  	public	boolean equals(ContactParams other) {
55  		if (DEBUG)
56  			logger.info("equals: " + this.setName + "/" + this.size + "/" + this.contactNumber + " : " + other.setName + "/" + other.size + "/" + other.contactNumber);
57  		if (this.cid != other.cid)
58  			return(false);
59  		if (!this.setName.equals(other.setName))
60  			return(false);
61  		if (this.size  == -1
62  		 || other.size == -1)
63  			return(true);
64  		if (this.size != other.size)
65  			return(false);
66  		if (this.contactNumber  == -1
67  		 || other.contactNumber == -1)
68  			return(true);
69  		if (this.contactNumber == other.contactNumber)
70  			return(true);
71  		return(false);
72  	}
73  
74  	/** Compare two ContactParams for equality.<br>
75  	 * Compare setName, size, min/max.<br>
76  	 * Basically, we are checking if these two ContactParams will select the same set of Pics.
77  	 * @param other The other ContactParams to compare to.
78  	 * @return equality
79  	 */
80  	public boolean equalsPics(ContactParams other) {
81  		if (DEBUG)
82  			logger.info("equals: " + this.setName + "/" + this.size + "/" + this.contactNumber + " : " + other.setName + "/" + other.size + "/" + other.contactNumber);
83  		if (!this.setName.equals(other.setName))
84  			return(false);
85  		if (this.size != other.size)
86  			return(false);
87  		if (this.rankMin != other.rankMin)
88  			return(false);
89  		if (this.rankMax != other.rankMax)
90  			return(false);
91  		return(true);
92  		
93  	}
94  
95  	/**
96  	 * @return Returns the cid.
97  	 */
98  	public int getCid() {
99  		return cid;
100 	}
101 
102 	/**
103 	 * @param cid The cid to set.
104 	 */
105 	public void setCid(int cid) {
106 		this.cid = cid;
107 	}
108 
109 	public void	setSetSize(SetSize setSize) {
110 		this.setName = setSize.getSetName();
111 		this.size	 = setSize.getSize();
112 	}
113 	
114 	public String getSetName() {
115 		return setName;
116 	}
117 	public void setSetName(String setName) {
118 		this.setName = setName;
119 	}
120 	
121 	/** Get the thumbnail size we should draw in
122 	 * @return most likely 75,100,150,200 or 300
123 	 */
124 	public int getSize() {
125 		return size;
126 	}
127 
128 	/** Set the thumbnail size we should draw in
129 	 * @param size most likely 75,100,150,200 or 300
130 	 */
131 	public void setSize(int size) {
132 		this.size = size;
133 	}
134 
135 	public String getOutputDirectory() {
136 		return outputDirectory;
137 	}
138 	public void setOutputDirectory(String outputDirectory) {
139 		this.outputDirectory = outputDirectory;
140 	}
141 	public int getContactNumber() {
142 		return contactNumber;
143 	}
144 	public void setContactNumber(int contactNumber) {
145 		this.contactNumber = contactNumber;
146 	}
147 
148 	private static DecimalFormat df2 = new DecimalFormat("00");
149 	private static DecimalFormat df3 = new DecimalFormat("000");
150 	/** Return a String which is the Uuid of a set/size/item combo 
151 	 * @return Something that looks like: mlb-075-001
152 	 */
153 	public	String	getUuid() {
154 		return(new String(getSetName() 
155 							+ "-" + df3.format(getSize()) 
156 							+ "-" + df2.format(getContactNumber())));
157 	}
158 
159 	/** Return a String which is the Uuid of a set/size combo.
160 	 *  Not so much a Uuid, per se. because the item is unknown,
161 	 *  so we call it a uid. */
162 	public	String	getUid() {
163 		DecimalFormat df3 = new DecimalFormat("000");
164 		return(new String(getSetName() 
165 							+ "-" + df3.format(getSize())));
166 	}
167 
168 	/**
169 	 * @return Returns the rankMax.
170 	 */
171 	public int getRankMax() {
172 		return rankMax;
173 	}
174 
175 	/**
176 	 * @param rankMax The rankMax to set.
177 	 */
178 	public void setRankMax(int rankMax) {
179 		this.rankMax = rankMax;
180 	}
181 
182 	/**
183 	 * @return Returns the rankMin.
184 	 */
185 	public int getRankMin() {
186 		return rankMin;
187 	}
188 
189 	/**
190 	 * @param rankMin The rankMin to set.
191 	 */
192 	public void setRankMin(int rankMin) {
193 		this.rankMin = rankMin;
194 	}
195 	
196 	/** Convienence method to set the min and max ratings in one call.
197 	 * 
198 	 * @param min
199 	 * @param max
200 	 */
201 	public void setRankMinMax(int min, int max) {
202 		this.rankMin = min;
203 		this.rankMax = max;
204 	}
205 
206 	/** Get the name of the engine that is to build these contacts
207 	 * @return the engineName
208 	 */
209 	public String getEngineName() {
210 		return engineName;
211 	}
212 
213 	/** Set the name of the engine that is to build these contacts
214 	 * @param engineName the engineName to set
215 	 */
216 	public void setEngineName(String engineName) {
217 		this.engineName = engineName;
218 	}
219 	
220 }