1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public class Exemple {
public enum Orientation {
PORTRAIT,
PAYSAGE
}
private final Orientation orientation;
public Exemple(Orientation orientation) {
if ( orientation==null ) {
throw new NullPointerException("L'orientation doit avoir une valeur");
}
this.orientation=orientation;
}
public Dimension getTaille() {
switch( orientation ) {
case PORTRAIT:
return new Dimension(100, 200);
case PAYSAGE:
return new Dimension(200, 100);
default:
assert false : "Orientation impossible : "+orientation;
}
return new Dimension(0,0);
}
} |