Skip to content

Instantly share code, notes, and snippets.

@mbcrawfo
Last active August 29, 2015 14:14
Show Gist options
  • Save mbcrawfo/b8cefc23af73a0252e5c to your computer and use it in GitHub Desktop.
Save mbcrawfo/b8cefc23af73a0252e5c to your computer and use it in GitHub Desktop.
Alek is a lazy bastard
class ColorComparator implements Comparator<Integer> {
private ColorEnumType color;
public ColorComparator(ColorEnumType color) {
this.color = color;
}
@Override
public int compare(Integer a, Integer b) {
int mask = 0xff;
switch (color) {
case ColorEnumType.Red:
mask <<= 16;
break;
case ColorEnumType.Blue:
mask <<= 8;
break;
// do nothing for green
}
a &= mask;
b &= mask;
if (a < b) {
return -1;
}
else if (a == b) {
return 0;
}
else {
return 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment