001package org.andromda.utils.beans.comparators;
002
003import java.io.Serializable;
004import java.util.Comparator;
005
006/**
007 * Used to sort Number values
008 *
009 * @author Chad Brandon
010 */
011class NumberComparator
012    implements Comparator,
013        Serializable
014{
015    private static final long serialVersionUID = 34L;
016
017    /**
018     * Used to sort Number values, both objects are assumed
019     * to be Number instances.
020     * @param objectA
021     * @param objectB
022     * @return compare result
023     */
024    public int compare(
025        final Object objectA,
026        final Object objectB)
027    {
028        final Number aAsNumber = (Number)objectA;
029        final Number bAsNumber = (Number)objectB;
030        int result = 0;
031        if (aAsNumber.doubleValue() > bAsNumber.doubleValue())
032        {
033            result = 1;
034        }
035        else if (aAsNumber.doubleValue() < bAsNumber.doubleValue())
036        {
037            result = -1;
038        }
039        return result;
040    }
041}