Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/com/urise/webapp/MainTestArrayStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) {
printAll();
ARRAY_STORAGE.delete(r1.getUuid());
printAll();
ARRAY_STORAGE.update("uuid2", "uuid0");
ARRAY_STORAGE.update(r2);
printAll();
ARRAY_STORAGE.clear();
printAll();
Expand Down
44 changes: 19 additions & 25 deletions src/com/urise/webapp/storage/ArrayStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,49 @@
*/

public class ArrayStorage {
private Resume[] storage = new Resume[10000];
private final Resume[] storage = new Resume[10000];
private int size = 0;

public void clear() {
Arrays.fill(storage, 0, size, null);
size = 0;
}

public void update(String prevUuid, String newUuid) {
int indexOfResumeByUuid = getIndex(prevUuid);
int indexOfResumeByNewUuid = getIndex(newUuid);
if (indexOfResumeByUuid == -1) {
System.out.println("Resume is not present");
} else if (indexOfResumeByNewUuid != -1) {
System.out.println("Resume with such uuid is already exist");
public void update(Resume r) {
int index = getIndex(r.getUuid());
if (index == -1) {
System.out.println("Resume " + r.getUuid() + " is not exist");
} else {
storage[indexOfResumeByUuid].setUuid(newUuid);
storage[index] = r;
}
}

public void save(Resume r) {
if (getIndex(r.getUuid()) != -1) {
System.out.println("Resume is already present");
System.out.println("Resume " + r.getUuid() + " is already exist");
} else if (size == storage.length) {
System.out.println("Storage is overflown");
} else {
if (size < storage.length) {
storage[size] = r;
size++;
} else {
System.out.println("Storage is overflown");
}
storage[size] = r;
size++;
}
}

public Resume get(String uuid) {
int indexOfResumeByUuid = getIndex(uuid);
if (indexOfResumeByUuid == -1) {
System.out.println("Resume is not present");
int index = getIndex(uuid);
if (index == -1) {
System.out.println("Resume " + uuid + " is not present");
return null;
} else {
return storage[indexOfResumeByUuid];
}
return storage[index];
}

public void delete(String uuid) {
int indexOfResumeByUuid = getIndex(uuid);
if (indexOfResumeByUuid == -1) {
System.out.println("Resume is not present");
int index = getIndex(uuid);
if (index == -1) {
System.out.println("Resume " + uuid + " is not present");
} else {
storage[indexOfResumeByUuid] = storage[size - 1];
storage[index] = storage[size - 1];
storage[size - 1] = null;
size--;
}
Expand Down