Search in sources :

Example 1 with ExecutionException

use of exceptions.ExecutionException in project Lab5 by Arslanka.

the class AddIfMaxCommand method execute.

@Override
public boolean execute(Object... args) {
    try {
        Dragon dragon = (Dragon) args[0];
        collection.addIfMax(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.");
    }
    return true;
}
Also used : ExecutionException(exceptions.ExecutionException) Dragon(data.Dragon)

Example 2 with ExecutionException

use of exceptions.ExecutionException in project Lab5 by Arslanka.

the class CountGreaterThanKillerCommand method execute.

@Override
public boolean execute(Object... args) {
    try {
        Person person = (Person) args[0];
        collection.countGreaterThanKiller(person);
        printer.println(SEPARATOR, ERROR);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ExecutionException("You have not entered an item to add to the collection.");
    }
    return true;
}
Also used : ExecutionException(exceptions.ExecutionException) Person(data.Person)

Example 3 with ExecutionException

use of exceptions.ExecutionException in project Lab5 by Arslanka.

the class RemoveAllByWeight method execute.

@Override
public boolean execute(Object... args) {
    try {
        Float weight = (Float) args[0];
        collection.removeByWeight(weight);
        printer.println(String.format("%s %f %s", "Elements whose weight field value is equivalent to", weight, "the specified one have been successfully removed from the collection"), HELP);
        printer.println(SEPARATOR, ERROR);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ExecutionException("You have not entered an item to add to the collection.");
    }
    return true;
}
Also used : ExecutionException(exceptions.ExecutionException)

Example 4 with ExecutionException

use of exceptions.ExecutionException in project Lab5 by Arslanka.

the class RemoveGreaterCommand method execute.

@Override
public boolean execute(Object... args) {
    try {
        collection.removeGreater((Dragon) args[0]);
        printer.println("Elements whose value is greater than the specified value have been successfully removed from the collection", HELP);
        printer.println(SEPARATOR, ERROR);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new ExecutionException("You have not entered an element for comparison.");
    }
    return true;
}
Also used : ExecutionException(exceptions.ExecutionException)

Example 5 with ExecutionException

use of exceptions.ExecutionException in project Lab5 by Arslanka.

the class SaveCommand method execute.

@Override
public boolean execute(Object... args) {
    try {
        collection.save((JsonFile) args[0]);
        printer.println("The collection is saved to  " + args[0], HELP);
        printer.println(SEPARATOR, ERROR);
    } catch (InputOutputException | NullPointerException | ArrayIndexOutOfBoundsException e) {
        throw new ExecutionException("You have not entered an JsonFile.");
    }
    return true;
}
Also used : InputOutputException(exceptions.InputOutputException) ExecutionException(exceptions.ExecutionException)

Aggregations

ExecutionException (exceptions.ExecutionException)14 Dragon (data.Dragon)3 InvalidObjectFieldException (exceptions.InvalidObjectFieldException)3 InputOutputException (exceptions.InputOutputException)2 JsonParseException (com.google.gson.JsonParseException)1 commands (commands)1 Person (data.Person)1 ExistingIdException (exceptions.ExistingIdException)1 IncorrectIdException (exceptions.IncorrectIdException)1 RecursiveCallException (exceptions.RecursiveCallException)1 TextFile (file.TextFile)1 Printer (io.Printer)1 java.io (java.io)1 java.util (java.util)1 BiFunction (java.util.function.BiFunction)1 Supplier (java.util.function.Supplier)1