Skip to content

Instantly share code, notes, and snippets.

@hackmajoris
Created September 5, 2016 11:30
Show Gist options
  • Save hackmajoris/8814a287f438026850f9ff89dec0fb66 to your computer and use it in GitHub Desktop.
Save hackmajoris/8814a287f438026850f9ff89dec0fb66 to your computer and use it in GitHub Desktop.
Comparable interface implementation
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