Created
June 3, 2014 17:11
-
-
Save jmarkovic/6ca03a6c4df623fffc83 to your computer and use it in GitHub Desktop.
Sortiranje evenata po minuti silazno
This file contains 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
@Override | |
public int compareTo(LiveEvent another) { | |
int thisMinute = 0; | |
int thisSecondaryMinute = 0; | |
int anotherMinute = 0; | |
int anotherSecondaryMinute = 0; | |
try { | |
if (this.getMinute().contains("+")) { | |
String[] minutes = this.getMinute().split("\\+"); | |
if (minutes.length >= 2) { | |
thisMinute += Integer.parseInt(minutes[0]); | |
thisSecondaryMinute += Integer.parseInt(minutes[1]); | |
} | |
} else { | |
thisMinute = Integer.parseInt(this.getMinute()); | |
} | |
if (another.getMinute().contains("+")) { | |
String[] minutes = another.getMinute().split("\\+"); | |
if (minutes.length >= 2) { | |
anotherMinute += Integer.parseInt(minutes[0]); | |
anotherSecondaryMinute += Integer.parseInt(minutes[1]); | |
} | |
} else { | |
anotherMinute = Integer.parseInt(another.getMinute()); | |
} | |
} catch (Exception e) { | |
Log.d(this.getClass().getSimpleName(), "Error parsing " + | |
"String to integer: " + e.getMessage()); | |
} | |
//comparing | |
if (thisMinute > anotherMinute) { | |
return -1; | |
} else if (thisMinute < anotherMinute) { | |
return 1; | |
} else { | |
if (thisSecondaryMinute > anotherSecondaryMinute) { | |
return -1; | |
} else if (thisSecondaryMinute < anotherSecondaryMinute) { | |
return 1; | |
} else { | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment