Search in sources :

Example 1 with InvalidObjectFieldException

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;
}
Also used : InvalidObjectFieldException(exceptions.InvalidObjectFieldException) ExecutionException(exceptions.ExecutionException) Dragon(data.Dragon)

Example 2 with InvalidObjectFieldException

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);
    }
}
Also used : InvalidObjectFieldException(exceptions.InvalidObjectFieldException) ExecutionException(exceptions.ExecutionException)

Example 3 with InvalidObjectFieldException

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);
    }
}
Also used : InvalidObjectFieldException(exceptions.InvalidObjectFieldException) ExecutionException(exceptions.ExecutionException) ExistingIdException(exceptions.ExistingIdException)

Aggregations

ExecutionException (exceptions.ExecutionException)3 InvalidObjectFieldException (exceptions.InvalidObjectFieldException)3 Dragon (data.Dragon)1 ExistingIdException (exceptions.ExistingIdException)1