collections.sortable
Class SortableProduct
java.lang.Object
collections.sortable.SortableProduct
- All Implemented Interfaces:
- java.lang.Comparable
public class SortableProduct
- extends java.lang.Object
- implements java.lang.Comparable
Demonstrates how to make a class sortable, by implementing
the Comparable interface to make the class comparable, and by
using the Comparator interface to create explicit comparators.
- Author:
- Thomas Rowland
Constructor Summary |
SortableProduct(int _id,
java.lang.String _name,
java.lang.String _descr,
int _qty,
double _price)
|
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
PRICE_COMPARATOR
public static final java.util.Comparator PRICE_COMPARATOR
QTY_COMPARATOR
public static final java.util.Comparator QTY_COMPARATOR
SortableProduct
public SortableProduct(int _id,
java.lang.String _name,
java.lang.String _descr,
int _qty,
double _price)
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in class java.lang.Object
compareTo
public int compareTo(java.lang.Object o)
- Overridden method in the Comparator interface
makes the class comparable. Defines the Natural Ordering
and must be consistent with equals.
- Specified by:
compareTo
in interface java.lang.Comparable
isGreater
public boolean isGreater(java.lang.Object o)
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
getId
public int getId()
getName
public java.lang.String getName()
getDescr
public java.lang.String getDescr()
getQty
public int getQty()
getPriceEa
public double getPriceEa()
getPriceNet
public double getPriceNet()