Created
September 5, 2016 11:30
-
-
Save hackmajoris/8814a287f438026850f9ff89dec0fb66 to your computer and use it in GitHub Desktop.
Comparable interface implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.ilies; | |
/** | |
* Created by iliesa on 05.09.2016. | |
*/ | |
public class Apple implements Comparable<Apple> { | |
private String variety; | |
private String color; | |
private int weight; | |
@Override | |
public int compareTo(Apple o) { | |
int result = this.variety.compareTo(o.variety); | |
if (result != 0){ | |
return result; | |
} | |
if(result == 0){ | |
result = this.color.compareTo(o.color); | |
} | |
if(result != 0){ | |
return result; | |
} | |
if( result == 0){ | |
result = Integer.compare(this.weight, o.weight); | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment