📄 reversecomparator.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Fri Aug 23 13:18:19 EDT 2002 --><TITLE>: Class ReverseComparator</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><a href=../copyright.html target=_top>© 1998-2002 McGraw-Hill</a></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../structure/RedBlackTree.html"><B>PREV CLASS</B></A> <A HREF="../structure/SetList.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="ReverseComparator.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">structure</FONT><BR>Class ReverseComparator</H2><PRE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">java.lang.Object</A> | +--<B>structure.ReverseComparator</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html">Comparator</A></DD></DL><HR><DL><DT>public class <B>ReverseComparator</B><DT>extends <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html">Object</A><DT>implements <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html">Comparator</A></DL><P>Implementation of the <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html"><CODE>Comparator</CODE></A> interface that provides a <A HREF="../structure/ReverseComparator.html#compare(java.lang.Object, java.lang.Object)"><CODE>compare(Object,Object)</CODE></A> method that compares two objects using those objects default compareTo methods. Reverse comparator however, reverses the natural comparison as follows: <P> Were we to call compare(a,b), ReverseComparator would return the following: <pre> >0 if a < b 0 if a = b <0 if a > b </pre> <P> Example usage: <P> To print out the equality relationship between two randomly generated integers we could use the following: <pre> public static void main(String[] argv){ Random rand = new Random(); Comparator c = new <A HREF="../structure/ReverseComparator.html#ReverseComparator()"><CODE>ReverseComparator()</CODE></A>; //generate two random Integers Integer a = new Integer(rand.nextInt(100)); Integer b = new Integer(rand.nextInt(100)); //print out the proper equality relationship between these integers if(c.<A HREF="../structure/ReverseComparator.html#compare(java.lang.Object, java.lang.Object)"><CODE>compare(a,b)</CODE></A> > 0) System.out.println("A:" + a + " > B:" + b); else if (c.<A HREF="../structure/ReverseComparator.html#compare(java.lang.Object, java.lang.Object)"><CODE>compare(a,b) < 0) System.out.println("A:" + a + " < B:" + b); else System.out.println("A:" + a + " = B:" + b); </CODE></A> </pre><P><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>protected <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html">Comparator</A></CODE></FONT></TD><TD><CODE><B><A HREF="../structure/ReverseComparator.html#base">base</A></B></CODE><BR> </TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/ReverseComparator.html#ReverseComparator()">ReverseComparator</A></B>()</CODE><BR> Construct a comparator that generates reverse natural comparison</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../structure/ReverseComparator.html#ReverseComparator(java.util.Comparator)">ReverseComparator</A></B>(<A HREF="http://java.sun.com/j2se/1.3/docs/api/java/util/Comparator.html">Comparator</A> base)</CODE><BR> Construct a comparator that generates reverse of another comparator</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -