Skip to content
Snippets Groups Projects
Commit 41a1c651 authored by Nicolas Fley's avatar Nicolas Fley
Browse files

command logic added

parent 54963256
No related branches found
No related tags found
No related merge requests found
package Cli;
import java.util.ArrayList;
import User.User;
public abstract class Command {
private String commandName;
private Token [] listOfArgs;
private User [] typeOfInstanceAllowed;
public Command(String _commandName, Token [] _listOfArgs, User [] _typeOfInstanceAllowed){
commandName = _commandName;
listOfArgs = _listOfArgs;
typeOfInstanceAllowed = _typeOfInstanceAllowed;
}
public boolean isOneWanted(String firstToken){
if(firstToken == commandName)
return true;
return false;
}
public boolean isGoodArgument(ArrayList<String> arguments, User typeOfUser){
if(arguments.size() != listOfArgs.length){
return false; // devrait throw une erreur disant que c'est pas le bon nombre de paramtre.
}
boolean goodUserType=false;
for (User typeUser : typeOfInstanceAllowed){
if(typeUser.getClass() == typeOfUser.getClass()){
goodUserType=true;
}
}
if(!goodUserType)
return false; // devrait throw une erreur
int i = 0;
for (String arg : arguments) {
listOfArgs[i].isTockenCorrect(arg); // throw une erreur, faut la catch au dessus !
i++;
}
// trow une erreur
return true;
}
public abstract String execute();
}
package Cli;
public class Token {
private TypeToken typeOfToken;
private String name;
private String value;
public Token(TypeToken _typeOfToken, String _name){
typeOfToken = _typeOfToken;
name = _name;
value = "";
}
public void setValue(String _value) throws errorWrongFormatValue{
if(isTockenCorrect(_value)){
value = _value;
}else{
throw new errorWrongFormatValue("Format de "+name+" incorrect !");
/* si incorrect, throw une erreur qui doit tre catch
par la fonction au dessus (et on doit annuler la commande */
}
}
public String getValue(){
return value;
}
public boolean isTockenCorrect(String _value){
switch(typeOfToken){
case date:
break;
case integer:
if(_value.matches("-?\\d+"))
return true;
break;
case decimal:
if(_value.matches("-?\\d+(\\.\\d+)?"))
return true;
break;
case str:
return true;
}
return false;
}
static enum TypeToken{
date,str,integer,decimal
}
}
package Cli;
public class errorWrongFormatValue extends Exception {
/**
*
*/
private static final long serialVersionUID = 7873997091472426895L;
public errorWrongFormatValue() {
// TODO Auto-generated constructor stub
}
public errorWrongFormatValue(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public errorWrongFormatValue(Throwable arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public errorWrongFormatValue(String arg0, Throwable arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
public errorWrongFormatValue(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
super(arg0, arg1, arg2, arg3);
// TODO Auto-generated constructor stub
}
}
...@@ -5,16 +5,13 @@ import User.User; ...@@ -5,16 +5,13 @@ import User.User;
public class ActiveUserContext { public class ActiveUserContext {
User activeUser; User activeUser;
public ActiveUserContext(MyFoodora foodora) { public ActiveUserContext(MyFoodora foodora) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public User getUser(){ public User getUser(){
return activeUser; return activeUser;
} }
public void setActiveUser(User u){ public void setActiveUser(User u){
activeUser = u; activeUser = u;
} }
} }
...@@ -52,7 +52,7 @@ public class MyFoodora { ...@@ -52,7 +52,7 @@ public class MyFoodora {
public MyFoodora() throws ExceptionUnknownStartegyType{ public MyFoodora() throws ExceptionUnknownStartegyType{
this.contextTargetProfitStrategy = new ContextTargetProfitStrategy("DeliveryCost"); this.contextTargetProfitStrategy = new ContextTargetProfitStrategy("DeliveryCost");
this.contextDeliveryPolicy = new ContextDeliveryStrategy("FairOccupation"); this.contextDeliveryPolicy = new ContextDeliveryStrategy("DeliveryCost");
this.listRestaurant = new ListUser<Restaurant>(); this.listRestaurant = new ListUser<Restaurant>();
this.listCustomer = new ListUser<Customer>(); this.listCustomer = new ListUser<Customer>();
this.listManager = new ListUser<Manager>(); this.listManager = new ListUser<Manager>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment