Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: joelib/math/symmetry/SymAxesComparator.java


1   ///////////////////////////////////////////////////////////////////////////////
2   //  Filename: $RCSfile: SymAxesComparator.java,v $
3   //  Purpose:  Atom representation.
4   //  Language: Java
5   //  Compiler: JDK 1.4
6   //  Authors:  Joerg K. Wegner
7   //  Version:  $Revision: 1.3 $
8   //            $Date: 2003/08/22 15:56:19 $
9   //            $Author: wegner $
10  //  Original Author: ???, OpenEye Scientific Software
11  //  Original Version: babel 2.0a1
12  //
13  //  Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
14  //
15  //  This program is free software; you can redistribute it and/or modify
16  //  it under the terms of the GNU General Public License as published by
17  //  the Free Software Foundation version 2 of the License.
18  //
19  //  This program is distributed in the hope that it will be useful,
20  //  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  //  GNU General Public License for more details.
23  ///////////////////////////////////////////////////////////////////////////////
24  package joelib.math.symmetry;
25  
26  
27  /*==========================================================================*
28   * IMPORTS
29   *========================================================================== */
30  import java.util.Comparator;
31  
32  
33  /*==========================================================================*
34   * CLASS DECLARATION
35   *========================================================================== */
36  
37  /**
38   *  <tt>Comparator</tt> for ring size.
39   *
40   * @author     wegnerj
41   * @license GPL
42   * @cvsversion    $Revision: 1.3 $, $Date: 2003/08/22 15:56:19 $
43   * @see        Comparator
44   * @see        java.util.Arrays#sort(Object[], Comparator)
45   * @see        joelib.sort.InsertSort
46   * @see        joelib.sort.QuickInsertSort
47   */
48  public class SymAxesComparator implements Comparator
49  {
50      //~ Constructors ///////////////////////////////////////////////////////////
51  
52      /*-------------------------------------------------------------------------*
53       * constructor
54       *------------------------------------------------------------------------- */
55  
56      /**
57       *  Initializes the <tt>SymAxesComparator</tt>-<tt>Comparator</tt>.
58       */
59      public SymAxesComparator()
60      {
61      }
62  
63      //~ Methods ////////////////////////////////////////////////////////////////
64  
65      /*-------------------------------------------------------------------------*
66       * public methods
67       *------------------------------------------------------------------------- */
68  
69      /**
70       *  Compares two objects.
71       *
72       * @param  o1                   the first object to be compared.
73       * @param  o2                   the second object to be compared.
74       * @return                      a negative integer, zero, or a positive
75       *      integer as the first argument is less than, equal to, or greater than
76       *      the second.
77       * @throws  ClassCastException  if the arguments' types prevent them from
78       *      being compared by this Comparator.
79       */
80      public int compare(Object o1, Object o2)
81      {
82          if ((o1 == null) || (o2 == null))
83          {
84              //throw new NullPointerException("Object to compare is 'null'");
85              return 1;
86          }
87  
88          if (o1 instanceof SymmetryElement && o2 instanceof SymmetryElement)
89          {
90              SymmetryElement axis_a = (SymmetryElement) o1;
91              SymmetryElement axis_b = (SymmetryElement) o2;
92              int i;
93              int order_a;
94              int order_b;
95  
96              order_a = axis_a.order;
97  
98              if (order_a == 0)
99              {
100                 order_a = 10000;
101             }
102 
103             order_b = axis_b.order;
104 
105             if (order_b == 0)
106             {
107                 order_b = 10000;
108             }
109 
110             if ((i = order_b - order_a) != 0)
111             {
112                 return i;
113             }
114 
115             if (axis_a.maxdev > axis_b.maxdev)
116             {
117                 return -1;
118             }
119 
120             if (axis_a.maxdev < axis_b.maxdev)
121             {
122                 return 1;
123             }
124 
125             return 0;
126         }
127         else
128         {
129             throw new ClassCastException(
130                 "Objects must be of type SymmetryElement");
131         }
132     }
133 
134     /**
135      *  Indicates whether some other object is &quot;equal to&quot; this
136      *  Comparator. This method must obey the general contract of <tt>
137      *  Object.equals(Object)</tt> . Additionally, this method can return <tt>true
138      *  </tt> <i>only</i> if the specified Object is also a comparator and it
139      *  imposes the same ordering as this comparator. Thus, <tt>comp1.equals(comp2)</tt>
140      *  implies that <tt>sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2))
141      *  </tt> for every object reference <tt>o1</tt> and <tt>o2</tt> .<p>
142      *
143      *  Note that it is <i>always</i> safe <i>not</i> to override <tt>
144      *  Object.equals(Object)</tt> . However, overriding this method may, in some
145      *  cases, improve performance by allowing programs to determine that two
146      *  distinct Comparators impose the same order.
147      *
148      * @param  obj  the reference object with which to compare.
149      * @return      <tt>true</tt> only if the specified object is also a
150      *      comparator and it imposes the same ordering as this comparator.
151      * @see         java.lang.Object#equals(java.lang.Object)
152      * @see         java.lang.Object#hashCode()
153      */
154     public boolean equals(Object obj)
155     {
156         if (obj instanceof SymAxesComparator)
157         {
158             return true;
159         }
160 
161         return false;
162     }
163 }
164 ///////////////////////////////////////////////////////////////////////////////
165 //  END OF FILE.
166 ///////////////////////////////////////////////////////////////////////////////