Search in sources :

Example 1 with ExistingIdException

use of exceptions.ExistingIdException 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)1 ExistingIdException (exceptions.ExistingIdException)1 InvalidObjectFieldException (exceptions.InvalidObjectFieldException)1