added a new method getColorByIndex(int) and next() method to the enum 'Color'
This commit is contained in:
@@ -26,16 +26,33 @@ public enum Color {
|
|||||||
*/
|
*/
|
||||||
NONE;
|
NONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be used to return a Color enumeration depending on the given index parameter.
|
||||||
|
*
|
||||||
|
* @param index as the index of the color inside the values as an Integer.
|
||||||
|
* @return a Color enumeration.
|
||||||
|
*/
|
||||||
|
public static Color getColorByIndex(int index) {
|
||||||
|
if (index < 0 || index >= values().length) {
|
||||||
|
throw new IllegalArgumentException("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return values()[index];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used to calculate the next color inside the sequence.
|
* This method will be used to calculate the next color inside the sequence.
|
||||||
*
|
*
|
||||||
* @return color as a Color Enumeration.
|
* @return color as a Color Enumeration.
|
||||||
*/
|
*/
|
||||||
public Color next() {
|
public Color next() {
|
||||||
if (this.next() == NONE) {
|
Color[] colors = values();
|
||||||
return AIRFORCE;
|
int nextIndex = (this.ordinal() + 1) % colors.length;
|
||||||
|
|
||||||
|
if (colors[nextIndex] == NONE) {
|
||||||
|
nextIndex = (nextIndex + 1) % colors.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return values()[(ordinal() + 1) % values().length];
|
return colors[nextIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user