Example usage for java.lang Comparable equals

List of usage examples for java.lang Comparable equals

Introduction

In this page you can find the example usage for java.lang Comparable equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:Main.java

@SuppressWarnings("unchecked")
static public LinkedHashMap<Object, Comparable> sortHashMapByValues(HashMap<Object, Comparable> passedMap) {
    ArrayList mapKeys = new ArrayList(passedMap.keySet());
    ArrayList mapValues = new ArrayList(passedMap.values());
    Collections.sort(mapValues);/*from www  .  java2 s .  com*/
    Collections.sort(mapKeys);

    LinkedHashMap<Object, Comparable> sortedMap = new LinkedHashMap<Object, Comparable>();

    Iterator<Comparable> valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Comparable val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();

        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            Comparable comp = passedMap.get(key);

            if (comp.equals(val)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put(key, val);
                break;
            }

        }
    }
    return sortedMap;
}

From source file:edu.ucla.stat.SOCR.chart.gui.CustomPieSectionLabelGenerator.java

/**
 * Generates a label for a pie section./*from w  ww .j  a  v  a  2  s .com*/
 * 
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param key  the section key (<code>null</code> not permitted).
 * 
 * @return the label (possibly <code>null</code>).
 */
public String generateSectionLabel(PieDataset dataset, Comparable key) {
    String result = null;
    if (dataset != null) {
        if (!key.equals("PHP")) {
            result = key.toString();
        }
    }
    return result;
}

From source file:org.jfree.data.KeyToGroupMap.java

/**
 * Maps a key to a group.//from  w  ww .  j  a  v  a 2s . com
 *
 * @param key  the key (<code>null</code> not permitted).
 * @param group  the group (<code>null</code> permitted, clears any
 *               existing mapping).
 */
public void mapKeyToGroup(Comparable key, Comparable group) {
    ParamChecks.nullNotPermitted(key, "key");
    Comparable currentGroup = getGroup(key);
    if (!currentGroup.equals(this.defaultGroup)) {
        if (!currentGroup.equals(group)) {
            int count = getKeyCount(currentGroup);
            if (count == 1) {
                this.groups.remove(currentGroup);
            }
        }
    }
    if (group == null) {
        this.keyToGroupMap.remove(key);
    } else {
        if (!this.groups.contains(group)) {
            if (!this.defaultGroup.equals(group)) {
                this.groups.add(group);
            }
        }
        this.keyToGroupMap.put(key, group);
    }
}

From source file:net.sf.jdmf.algorithms.classification.util.AttributeValuePartitioner.java

protected void mergePartitionsWithIdenticalAttributeValue(List<AttributeValuePair> breakpoints,
        Comparable lastPartitionAttributeValue) {
    for (int i = 0; i < breakpoints.size() - 1; ++i) {
        Comparable currentAttributeValue = breakpoints.get(i).getSecondValue();
        Comparable nextAttributeValue = breakpoints.get(i + 1).getSecondValue();

        if (currentAttributeValue.equals(nextAttributeValue)) {
            breakpoints.remove(i);//from   ww w. j a va2  s. c  om
        }
    }

    if ((breakpoints.size() == 1) && breakpoints.get(0).getSecondValue().equals(lastPartitionAttributeValue)) {
        breakpoints.remove(0);
    }
}

From source file:org.jfree.data.category.CategoryToPieDataset.java

/**
 * Tests this dataset for equality with an arbitrary object, returning
 * <code>true</code> if <code>obj</code> is a dataset containing the same
 * keys and values in the same order as this dataset.
 *
 * @param obj  the object to test (<code>null</code> permitted).
 *
 * @return A boolean.//from  w  w w . jav a  2 s  .c  o m
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof PieDataset)) {
        return false;
    }
    PieDataset that = (PieDataset) obj;
    int count = getItemCount();
    if (that.getItemCount() != count) {
        return false;
    }
    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }

        Number v1 = getValue(i);
        Number v2 = that.getValue(i);
        if (v1 == null) {
            if (v2 != null) {
                return false;
            }
        } else {
            if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;
}

From source file:org.apache.falcon.predicate.Predicate.java

private boolean matches(String lhs, Comparable<? extends Serializable> rhs) {
    if (clauses.containsKey(lhs) && clauses.get(lhs) != null && rhs != null) {
        if (clauses.get(lhs).equals(ANY) || rhs.equals(ANY)) {
            return true;
        } else {/*from  w  ww  .  j a  v  a  2s . c om*/
            return clauses.get(lhs).compareTo(rhs) == 0;
        }
    }
    return false;
}

From source file:org.jfree.data.KeyedObjects.java

/**
 * Tests this object for equality with an arbitrary object.
 *
 * @param obj  the object (<code>null</code> permitted).
 *
 * @return A boolean./*from  w  w w  .  j ava2  s  .  c om*/
 */
@Override
public boolean equals(Object obj) {

    if (obj == this) {
        return true;
    }
    if (!(obj instanceof KeyedObjects)) {
        return false;
    }
    KeyedObjects that = (KeyedObjects) obj;
    int count = getItemCount();
    if (count != that.getItemCount()) {
        return false;
    }

    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }
        Object o1 = getObject(i);
        Object o2 = that.getObject(i);
        if (o1 == null) {
            if (o2 != null) {
                return false;
            }
        } else {
            if (!o1.equals(o2)) {
                return false;
            }
        }
    }
    return true;

}

From source file:org.jfree.data.general.DefaultPieDataset.java

/**
 * Tests if this object is equal to another.
 *
 * @param obj  the other object.//  ww  w.jav  a 2  s .c o  m
 *
 * @return A boolean.
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }

    if (!(obj instanceof PieDataset)) {
        return false;
    }
    PieDataset that = (PieDataset) obj;
    int count = getItemCount();
    if (that.getItemCount() != count) {
        return false;
    }

    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }

        Number v1 = getValue(i);
        Number v2 = that.getValue(i);
        if (v1 == null) {
            if (v2 != null) {
                return false;
            }
        } else {
            if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;

}

From source file:org.jfree.data.pie.DefaultPieDataset.java

/**
 * Tests if this object is equal to another.
 *
 * @param obj  the other object./*from w w w  . j ava  2 s. co  m*/
 *
 * @return A boolean.
 */
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }

    if (!(obj instanceof PieDataset)) {
        return false;
    }
    PieDataset that = (PieDataset) obj;
    int count = getItemCount();
    if (that.getItemCount() != count) {
        return false;
    }

    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }

        Number v1 = getValue(i);
        Number v2 = that.getValue(i);
        if (v1 == null) {
            if (v2 != null) {
                return false;
            }
        } else {
            if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;

}

From source file:org.jfree.data.DefaultKeyedValues.java

/**
 * Tests if this object is equal to another.
 *
 * @param obj  the object (<code>null</code> permitted).
 *
 * @return A boolean.//  w w w. j a v a 2 s.c  o  m
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }

    if (!(obj instanceof KeyedValues)) {
        return false;
    }

    KeyedValues that = (KeyedValues) obj;
    int count = getItemCount();
    if (count != that.getItemCount()) {
        return false;
    }

    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }
        Number v1 = getValue(i);
        Number v2 = that.getValue(i);
        if (v1 == null) {
            if (v2 != null) {
                return false;
            }
        } else {
            if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;
}