use of exceptions.InvalidObjectFieldException in project Lab5 by Arslanka.
the class AddCommand method execute.
@Override
public boolean execute(Object... args) throws ExistingIdException {
try {
Dragon dragon = (Dragon) args[0];
collection.add(dragon);
printer.println("The item was successfully added to the collection", HELP);
printer.println(SEPARATOR, ERROR);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ExecutionException("You have not entered an item to add to the collection.");
} catch (InvalidObjectFieldException e) {
throw new ExecutionException("Error executing the add command\n" + e.getMessage());
}
return true;
}
use of exceptions.InvalidObjectFieldException in project Lab5 by Arslanka.
the class Collection method updateId.
public void updateId(Integer id, Dragon dragon) {
dragonHashSet.remove(idMap.get(id));
dragon.setId(id);
try {
if (dragon.validated() != null) {
dragonHashSet.add(dragon);
idMap.put(id, dragon);
}
} catch (InvalidObjectFieldException e) {
throw new ExecutionException("You have entered incorrect fields for the dragon object", e);
}
}
use of exceptions.InvalidObjectFieldException in project Lab5 by Arslanka.
the class Collection method add.
public void add(Dragon dragon) throws ExistingIdException, ExecutionException {
Integer dragonId = dragon.getId();
try {
if (dragon.validated() != null)
if (idMap.containsKey(dragonId))
if (idMap.containsKey(dragonId))
throw new ExistingIdException(String.format("%s %d %s", "There is already an object with id ", dragonId, "in the collection"));
idMap.put(dragonId, dragon);
dragonHashSet.add(dragon);
} catch (InvalidObjectFieldException e) {
throw new ExecutionException("You have entered incorrect fields for the dragon object\n" + e.getMessage(), e);
}
}
Aggregations