11package ru .javawebinar .basejava .storage ;
22
3- import ru .javawebinar .basejava .exception .ExistStorageException ;
4- import ru .javawebinar .basejava .exception .NotExistStorageException ;
53import ru .javawebinar .basejava .exception .StorageException ;
64import ru .javawebinar .basejava .model .Resume ;
75
108/**
119 * Array based storage for Resumes
1210 */
13- public abstract class AbstractArrayStorage implements Storage {
11+ public abstract class AbstractArrayStorage extends AbstractStorage {
1412 protected static final int STORAGE_LIMIT = 10000 ;
1513
1614 protected Resume [] storage = new Resume [STORAGE_LIMIT ];
@@ -25,13 +23,9 @@ public void clear() {
2523 size = 0 ;
2624 }
2725
28- public void update (Resume r ) {
29- int index = getIndex (r .getUuid ());
30- if (index < 0 ) {
31- throw new NotExistStorageException (r .getUuid ());
32- } else {
33- storage [index ] = r ;
34- }
26+ @ Override
27+ protected void doUpdate (Resume r , Object index ) {
28+ storage [(Integer ) index ] = r ;
3529 }
3630
3731 /**
@@ -41,40 +35,35 @@ public Resume[] getAll() {
4135 return Arrays .copyOfRange (storage , 0 , size );
4236 }
4337
44- public void save (Resume r ) {
45- int index = getIndex (r .getUuid ());
46- if (index >= 0 ) {
47- throw new ExistStorageException (r .getUuid ());
48- } else if (size == STORAGE_LIMIT ) {
38+ @ Override
39+ protected void doSave (Resume r , Object index ) {
40+ if (size == STORAGE_LIMIT ) {
4941 throw new StorageException ("Storage overflow" , r .getUuid ());
5042 } else {
51- insertElement (r , index );
43+ insertElement (r , ( Integer ) index );
5244 size ++;
5345 }
5446 }
5547
56- public void delete (String uuid ) {
57- int index = getIndex (uuid );
58- if (index < 0 ) {
59- throw new NotExistStorageException (uuid );
60- } else {
61- fillDeletedElement (index );
62- storage [size - 1 ] = null ;
63- size --;
64- }
48+ @ Override
49+ public void doDelete (Object index ) {
50+ fillDeletedElement ((Integer ) index );
51+ storage [size - 1 ] = null ;
52+ size --;
6553 }
6654
67- public Resume get (String uuid ) {
68- int index = getIndex (uuid );
69- if (index < 0 ) {
70- throw new NotExistStorageException (uuid );
71- }
72- return storage [index ];
55+ public Resume doGet (Object index ) {
56+ return storage [(Integer ) index ];
57+ }
58+
59+ @ Override
60+ protected boolean isExist (Object index ) {
61+ return (Integer ) index >= 0 ;
7362 }
7463
7564 protected abstract void fillDeletedElement (int index );
7665
7766 protected abstract void insertElement (Resume r , int index );
7867
79- protected abstract int getIndex (String uuid );
68+ protected abstract Integer getSearchKey (String uuid );
8069}
0 commit comments