package ru.javaops.webapp; import ru.javaops.webapp.model.Resume; import ru.javaops.webapp.storage.SortedArrayStorage; import ru.javaops.webapp.storage.Storage; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; /** * Interactive test for ru.javaops.webapp.storage.ArrayStorage implementation * (just run, no need to understand) */ public class MainArray { // private final static Storage ARRAY_STORAGE = new ArrayStorage(); private final static Storage ARRAY_STORAGE = new SortedArrayStorage(); public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); Resume r; while (true) { System.out.print("Введите одну из команд - (list | save fullName | delete uuid | get uuid | update uuid fullName | clear | exit): "); String[] params = reader.readLine().trim().toLowerCase().split(" "); if (params.length < 1 || params.length > 3) { System.out.println("Неверная команда."); continue; } String param = null; if (params.length > 1) { param = params[1].intern(); } switch (params[0]) { case "list": printAll(); break; case "size": System.out.println(ARRAY_STORAGE.size()); break; case "save": r = new Resume(param); ARRAY_STORAGE.save(r); printAll(); break; case "update": r = new Resume(param, params[2]); ARRAY_STORAGE.update(r); printAll(); break; case "delete": ARRAY_STORAGE.delete(param); printAll(); break; case "get": System.out.println(ARRAY_STORAGE.get(param)); break; case "clear": ARRAY_STORAGE.clear(); printAll(); break; case "exit": return; default: System.out.println("Неверная команда."); break; } } } static void printAll() { List all = ARRAY_STORAGE.getAllSorted(); System.out.println("----------------------------"); if (all.size() == 0) { System.out.println("Empty"); } else { for (Resume r : all) { System.out.println(r); } } System.out.println("----------------------------"); } }