001: /*---------------------------------------------------------------------------*\
002: $Id: PlugInComparator.java 7041 2007-09-09 01:04:47Z bmc $
003: ---------------------------------------------------------------------------
004: This software is released under a BSD-style license:
005:
006: Copyright (c) 2004-2007 Brian M. Clapper. All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without
009: modification, are permitted provided that the following conditions are
010: met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. The end-user documentation included with the redistribution, if any,
016: must include the following acknowlegement:
017:
018: "This product includes software developed by Brian M. Clapper
019: (bmc@clapper.org, http://www.clapper.org/bmc/). That software is
020: copyright (c) 2004-2007 Brian M. Clapper."
021:
022: Alternately, this acknowlegement may appear in the software itself,
023: if wherever such third-party acknowlegements normally appear.
024:
025: 3. Neither the names "clapper.org", "curn", nor any of the names of the
026: project contributors may be used to endorse or promote products
027: derived from this software without prior written permission. For
028: written permission, please contact bmc@clapper.org.
029:
030: 4. Products derived from this software may not be called "curn", nor may
031: "clapper.org" appear in their names without prior written permission
032: of Brian M. Clapper.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
036: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
037: NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
038: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
039: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
040: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
041: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044: \*---------------------------------------------------------------------------*/
045:
046: package org.clapper.curn;
047:
048: import java.util.Comparator;
049:
050: /**
051: * Compares plug-in classes based on their declared sort keys.
052: *
053: * @version <tt>$Revision: 7041 $</tt>
054: */
055: public class PlugInComparator implements Comparator<PlugIn> {
056: /*----------------------------------------------------------------------*\
057: Private Constants
058: \*----------------------------------------------------------------------*/
059:
060: /*----------------------------------------------------------------------*\
061: Private Instance Data
062: \*----------------------------------------------------------------------*/
063:
064: /*----------------------------------------------------------------------*\
065: Constructor
066: \*----------------------------------------------------------------------*/
067:
068: /**
069: * Creates a new instance of <tt>PlugInComparator</tt>
070: */
071: PlugInComparator() {
072: }
073:
074: /*----------------------------------------------------------------------*\
075: Public Methods
076: \*----------------------------------------------------------------------*/
077:
078: /**
079: * Compare two plug-in classes, using their declared sort keys.
080: *
081: * @param plugIn1 first plug-in
082: * @param plugIn2 second plug-in
083: *
084: * @return < 0 if <tt>plugIn1</tt> is less than <tt>plugIn2</tt>,
085: * = 0 if both plug-ins have the same sort key,
086: * > 0 if <tt>plugIn1</tt> is greater than <tt>plugIn2</tt>
087: *
088: * @see PlugIn#getPlugInSortKey
089: */
090: public int compare(final PlugIn plugIn1, final PlugIn plugIn2) {
091: return plugIn1.getPlugInSortKey().compareToIgnoreCase(
092: plugIn2.getPlugInSortKey());
093: }
094:
095: /**
096: * Determine whether this comparator is equal to another object
097: *
098: * @param o the object to compare
099: *
100: * @return <tt>true</tt> if <tt>o</tt> is an instance of this class,
101: * <tt>false</tt> otherwise
102: */
103: @Override
104: public boolean equals(final Object o) {
105: return (o instanceof PlugInComparator);
106: }
107:
108: /**
109: * Get the hash code for this object.
110: *
111: * @return the hash code
112: */
113: @Override
114: public int hashCode() {
115: return super .hashCode();
116: }
117:
118: /*----------------------------------------------------------------------*\
119: Protected Methods
120: \*----------------------------------------------------------------------*/
121:
122: /*----------------------------------------------------------------------*\
123: Private Methods
124: \*----------------------------------------------------------------------*/
125: }
|