11package ru .javawebinar .basejava .storage ;
22
3+ import ru .javawebinar .basejava .exception .ExistStorageException ;
4+ import ru .javawebinar .basejava .exception .NotExistStorageException ;
5+ import ru .javawebinar .basejava .exception .StorageException ;
36import ru .javawebinar .basejava .model .Resume ;
47
58import java .util .Arrays ;
@@ -21,11 +24,9 @@ public final void save(Resume resume) {
2124 int index = getIndex (resume .getUuid ());
2225
2326 if (STORAGE_LIMIT <= size ) {
24- System .out .println ("Storage overflow!" );
25- return ;
27+ throw new StorageException ("Storage overflow!" , resume .getUuid ());
2628 } else if (index >= 0 ) {
27- System .out .println ("Данный ID:" + resume .getUuid () + " уже существует!" );
28- return ;
29+ throw new ExistStorageException (resume .getUuid ());
2930 }
3031 size ++;
3132 putResume (resume , index );
@@ -38,15 +39,14 @@ public final void update(Resume resume) {
3839 storage [index ] = resume ;
3940 System .out .println ("Резюме успешно обновлено ID:" + resume .getUuid ());
4041 } else {
41- System . out . println ( "Такое резюме не найдено в массиве ID: " + resume .getUuid ());
42+ throw new NotExistStorageException ( resume .getUuid ());
4243 }
4344 }
4445
4546 public final Resume get (String uuid ) {
4647 int index = getIndex (uuid );
4748 if (index < 0 ) {
48- System .out .println ("Не найден данный ID: " + uuid );
49- return null ;
49+ throw new NotExistStorageException (uuid );
5050 }
5151 return storage [index ];
5252 }
@@ -55,18 +55,21 @@ public final void delete(String uuid) {
5555 int index = getIndex (uuid );
5656
5757 if (index < 0 ) {
58- System .out .println ("Не найдено резюме ID:" + uuid );
59- return ;
58+ throw new NotExistStorageException (uuid );
6059 }
6160 shrinkArray (index );
6261 size --;
6362 System .out .println ("Резюме удалено! ID:" + uuid );
6463 }
6564
6665 public void clear () {
67- Arrays .fill (storage , 0 , size - 1 , null );
68- size = 0 ;
69- System .out .println ("Массив полностью очищен!" );
66+
67+ if (size > 0 ){
68+ Arrays .fill (storage , 0 , size - 1 , null );
69+ size = 0 ;
70+ System .out .println ("Массив полностью очищен!" );
71+ }
72+
7073 }
7174
7275 protected abstract int getIndex (String uuid );
0 commit comments