Java tutorial
/** * Copyright (C) 2008 University of Pittsburgh * * * This file is part of Open EpiCenter * * Open EpiCenter is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Open EpiCenter is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Open EpiCenter. If not, see <http://www.gnu.org/licenses/>. * * * */ package com.hmsinc.epicenter.webapp.util; import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; /** * Simple value class for sorting things in descending order. * * @author shade * @version $Id: SortableKeyValuePair.java 1328 2008-03-18 19:41:33Z steve.kondik $ */ public class SortableKeyValuePair implements Comparable<SortableKeyValuePair> { private final String key; private final double value; public SortableKeyValuePair(String key, double value) { super(); this.key = key; this.value = value; } /** * @return the key */ public String getKey() { return key; } /** * @return the value */ public double getValue() { return value; } /* * (non-Javadoc) * * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } /* * (non-Javadoc) * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { return EqualsBuilder.reflectionEquals(this, o); } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return ToStringBuilder.reflectionToString(this); } /* * (non-Javadoc) * * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(SortableKeyValuePair other) { return new CompareToBuilder().append(other.getValue(), value).append(key, other.getKey()).toComparison(); } }