public enum Planet {
MERCURY(false),
VENUS(false),
EARTH(false),
MARS(false),
JUPITER(false),
SATURN(false),
URANUS(false),
NEPTUNE(false);
}
public boolean isCurrent;
Planet(boolean isCurrent){
this.isCurrent = isCurrent;
}
public static void next(){
if(planet == VENUS){
VENUS.isCurrent = false;
EARTH.isCurrent = true;
MARS.isCurrent = false;
JUPITER.isCurrent = false;
SATURN.isCurrent = false;
URANUS.isCurrent = false;
NEPTUNE.isCurrent = false;
}
if(planet == EARTH){
VENUS.isCurrent = false;
EARTH.isCurrent = false;
MARS.isCurrent = true;
JUPITER.isCurrent = false;
SATURN.isCurrent = false;
URANUS.isCurrent = false;
NEPTUNE.isCurrent = false;
}
...
}
i found this solution,
private enum Planet { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE;
public Planet getNext() {
return this.ordinal() < Planet.values().length - 1
? Planet.values()[this.ordinal() + 1]
: null;
}
}
but i'm unable to use this cuz this enumeration is imported as static in other classes;
For now i use follow construction:
public static Planet setNewCurrent(){
for(Planet planet : Planet.values()){
if(planet == VENUS){
VENUS.isCurrent = false;
EARTH.isCurrent = true;
MARS.isCurrent = false;
JUPITER.isCurrent = false;
SATURN.isCurrent = false;
URANUS.isCurrent = false;
NEPTUNE.isCurrent = false;
}
if(planet == EARTH){
VENUS.isCurrent = false;
EARTH.isCurrent = false;
MARS.isCurrent = true;
JUPITER.isCurrent = false;
SATURN.isCurrent = false;
URANUS.isCurrent = false;
NEPTUNE.isCurrent = false;
}
...
}
}
Does anyone know some convenient way to getNextPlanet() like this
planet.getNext().isCurrent = true;