Un enum plutôt complexe (java vers python)
periplasme
Messages postés
422
Statut
Membre
-
periplasme Messages postés 422 Statut Membre -
periplasme Messages postés 422 Statut Membre -
Bonjour la compagnies !
ayant fini un projet en java pour mon IUT, je souhaitais le retranscrire en python.
pour ce projet, on nous as fournit un code de base, à agrémenté et à complété; C'est ce code que je souhaite retranscrire dans un premier temps. le soucis étant que python n'as pas de type énuméré de base, j'ai du mal à concevoir comment réimplémenté ce gros bouzin :
vous me conseillez quoi ? j'ai commencer une petite classe, mais j'ai peur que cela ne conviennent pas ...
j'avoue que ça me perturbe un peu ...
ayant fini un projet en java pour mon IUT, je souhaitais le retranscrire en python.
pour ce projet, on nous as fournit un code de base, à agrémenté et à complété; C'est ce code que je souhaite retranscrire dans un premier temps. le soucis étant que python n'as pas de type énuméré de base, j'ai du mal à concevoir comment réimplémenté ce gros bouzin :
enum CommandWord {
GO("go"), QUIT("quit"), HELP("help");
private final static Map<String, CommandWord> COMMANDS;
private final static String ALL_COMMANDS;
static {
final Map<String, CommandWord> commands = new LinkedHashMap<String, CommandWord>();
final StringBuilder stb = new StringBuilder();
for (CommandWord cw : CommandWord.values()) {
commands.put(cw.stringDesc, cw);
stb.append(cw.stringDesc).append(' ');
}
COMMANDS = Collections.unmodifiableMap(commands);
ALL_COMMANDS = stb.toString();
}
private final String stringDesc;
private CommandWord(final String stringDesc) {
this.stringDesc = stringDesc;
}
/**
* Returns the CommandWord member matching the given String value, or null
* when the given String is either null or unknown.
*/
public static CommandWord command(final String aString) {
if (aString == null) {
return null;
}
return COMMANDS.get(aString);
}
/**
* Returns the list of all commands.
*/
public static String allCommands() {
return ALL_COMMANDS;
}
}
vous me conseillez quoi ? j'ai commencer une petite classe, mais j'ai peur que cela ne conviennent pas ...
j'avoue que ça me perturbe un peu ...
A voir également:
- Un enum plutôt complexe (java vers python)
- Jeux java itel - Télécharger - Jeux vidéo
- Waptrick java football - Télécharger - Jeux vidéo
- Waptrick java voiture - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Eclipse java - Télécharger - Langages