Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

comparable on a generic class java

    public class DoubleKey<K extends Comparable<K>, J extends Comparable<J>>
        implements Comparable<DoubleKey<K, J>> {

    private K key1;
    private J key2;

    public DoubleKey(K key1, J key2) {
        this.key1 = key1;
        this.key2 = key2;
    }

    public K getFirstKey() {
        return this.key1;
    }

    public J getSecondKey() {
        return this.key2;
    }

    public int compareTo(DoubleKey<K, J> that) {

        int cmp = this.getFirstKey().compareTo(that.getFirstKey());
        if (cmp == 0)
            cmp = this.getSecondKey().compareTo(that.getSecondKey());
        return cmp;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: map interation in java 
Java :: Exception in thread "main" java.util.zip.ZipException: error 
Java :: split string 2 characters java 
Java :: how to get the average from a list in java 
Java :: factorial program in java 
Java :: how to use random bound on doubles java 
Java :: string to byte array java 
Java :: start new activity android 
Java :: java convert to roman numerals 
Java :: try block in java 
Java :: java singleton implementation 
Java :: java thread class sleep 
Java :: java list distinct by attribute 
Java :: decode base64 to file java 
Java :: json to hashmap java stream 
Java :: string to char in java 
Java :: java spring boot json deserialize date inaccurate 
Java :: check if sqlexception is duplicate entry java 
Java :: java declare array 
Java :: how to convert char to uppercase java 
Java :: Printing array list through for loop in java 
Java :: android remove focus from an element 
Java :: numbers of digits java 
Java :: Simple gui in java 
Java :: PathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: sort a string array java 
Java :: formatting an integer in java 
Java :: addall java 
Java :: dropdown menu with spinner dropdown icon color change in android 
Java :: queue in java 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =