Search in sources :

Example 1 with Dragon

use of data.Dragon in project lab5 by batiskavo3.

the class CollectionManager method maxByCreationDateCommand.

@Override
public void maxByCreationDateCommand() {
    long maxdatemls = 0;
    Integer key = null;
    for (Map.Entry<Integer, Dragon> entry : dragonsCollection.entrySet()) {
        if (entry.getValue().getCreationDate().getTime() > maxdatemls) {
            maxdatemls = entry.getValue().getCreationDate().getTime();
            key = entry.getKey();
        }
    }
    System.out.println(dragonsCollection.get(key));
    System.out.println("------------------------");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Dragon(data.Dragon)

Example 2 with Dragon

use of data.Dragon 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 3 with Dragon

use of data.Dragon in project lab5 by batiskavo3.

the class CollectionManager method insertNullCommand.

@Override
public void insertNullCommand(Integer key) {
    try {
        Dragon a = new Dragon(asker.askName(), asker.askCoordinates(), new Date(), asker.askAge(), asker.askColor(), asker.askDragonType(), asker.askDragonCharacter(), asker.askDragonHead());
        dragonsCollection.put(key, a);
    } catch (NoSuchElementException e) {
        System.out.println("Collection is empty");
    } catch (NumberFormatException e) {
        System.out.println("Invalid value");
    }
    if (history.size() == 16) {
        history.removeLast();
        history.addFirst("insert null");
    } else {
        history.addFirst("insert null");
    }
}
Also used : Dragon(data.Dragon)

Example 4 with Dragon

use of data.Dragon in project lab5 by batiskavo3.

the class CollectionManager method updateIDCommand.

@Override
public void updateIDCommand(Integer id) {
    // ** need Exception
    for (Map.Entry<Integer, Dragon> entry : dragonsCollection.entrySet()) {
        if (entry.getValue().getId().equals(id)) {
            System.out.println("Update element:");
            dragonsCollection.put(entry.getKey(), new Dragon(asker.askName(), asker.askCoordinates(), new Date(), asker.askAge(), asker.askColor(), asker.askDragonType(), asker.askDragonCharacter(), asker.askDragonHead()));
        }
    }
    if (history.size() == 16) {
        history.removeLast();
        history.addFirst("update_id ");
    } else {
        history.addFirst("update_id");
    }
    System.out.println("------------------------");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Dragon(data.Dragon)

Example 5 with Dragon

use of data.Dragon in project lab5 by batiskavo3.

the class CollectionManager method showCommand.

@Override
public void showCommand() {
    System.out.println("Date collection: " + date);
    List<Dragon> needSort = new ArrayList<Dragon>(dragonsCollection.values());
    Collections.sort(needSort);
    for (Dragon i : needSort) {
        System.out.println(i);
    }
    if (history.size() == 16) {
        history.removeLast();
        history.addFirst("show");
    } else {
        history.addFirst("show");
    }
    System.out.println("------------------------");
}
Also used : Dragon(data.Dragon)

Aggregations

Dragon (data.Dragon)7 ExecutionException (exceptions.ExecutionException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InvalidObjectFieldException (exceptions.InvalidObjectFieldException)1