View Javadoc

1   /***
2    * DoubleOrderFilter.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2002 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.filters;
27  
28  import java.io.Serializable;
29  import java.util.Comparator;
30  
31  /***
32   * A specialized OrderFilter that uses a double Comparator and only accepts
33   * Double objects as referent objects.
34   * 
35   * @author $Author: dbregeon $
36   * @version $Revision: 1.3 $
37   */
38  public class DoubleOrderFilter extends OrderFilter {
39  	static final long serialVersionUID = 4202117958954106612L;
40  
41  	/***
42  	 * A Comparator that compares Double objects.
43  	 */
44  	protected static class DoubleComparator implements Comparator, Serializable {
45  		static final long serialVersionUID = 8354049336842279148L;
46  
47  		/***
48  		 * Compares the passed in parameters if they are both Double objects.
49  		 * 
50  		 * @param obj1
51  		 *            The first object to be used for comparison.
52  		 * @param obj2
53  		 *            The second object to be used for comparison.
54  		 * @return -2 if any of the passed in objects is not a Double object. 0,
55  		 *         -1 or 1 respectively if the first number is respectively
56  		 *         equal to, lesser than or greater than the second one.
57  		 */
58  		public int compare(final Object obj1, final Object obj2) {
59  			int result = -2;
60  			if ((obj1 == null) || (obj2 == null)) {
61  				new IllegalArgumentException("Null is not a valid value.")
62  						.printStackTrace();
63  			} else {
64  				result = ((Double) obj1).compareTo(obj2);
65  			}
66  			return result;
67  		}
68  	}
69  
70  	/***
71  	 * The double comparator used by every DoubleOrderFilter object.
72  	 */
73  	private transient static final Comparator doubleComparator = new DoubleComparator();
74  
75  	/***
76  	 * Creates new DoubleOrderFilter
77  	 * 
78  	 * @param op
79  	 *            The OrderComparisonOperator to be used.
80  	 * @param number
81  	 *            The Double object to be used as the referent object.
82  	 * @throws IllegalArgumentException
83  	 *             In case any of the passed in parameters is null, which is not
84  	 *             wanted here.
85  	 */
86  	public DoubleOrderFilter(OrderComparisonOperator op, Double number)
87  			throws IllegalArgumentException {
88  		// Simply call super.
89  		super(op, doubleComparator, number);
90  	}
91  }