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("------------------------");
}
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;
}
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");
}
}
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("------------------------");
}
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("------------------------");
}
Aggregations