📄 comparablepairuos.java
字号:
package dslib.base;
/** A descendant of PairUos which defines comparison for two pairs whereby the
first items are compared first, and if they are equal, the second items are
compared. */
public class ComparablePairUos extends PairUos implements Comparable
{
/** Constructor of the class
Analysis: Time = O(1) */
public ComparablePairUos(Object o1, Object o2)
{
super(o1, o2);
}
/** Redefine compareTo method by comparing the key values
Analysis: Time = O(1) */
public int compareTo(Object other)
{
Comparable first = (Comparable)((ComparablePairUos)other).firstItem();
Comparable second = (Comparable)((ComparablePairUos)other).secondItem();
if(((Comparable)firstItem()).compareTo(first) == 0)
return ((Comparable)secondItem()).compareTo(second);
else
return ((Comparable)firstItem()).compareTo(first);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -