Last active
August 29, 2015 14:14
-
-
Save mbcrawfo/b8cefc23af73a0252e5c to your computer and use it in GitHub Desktop.
Alek is a lazy bastard
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
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