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
7 changes: 6 additions & 1 deletion src/com/urise/webapp/model/Resume.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Initial resume class
*/
public class Resume {
public class Resume implements Comparable<Resume> {

// Unique identifier
private String uuid;
Expand Down Expand Up @@ -39,4 +39,9 @@ public int hashCode() {
public String toString() {
return uuid;
}

@Override
public int compareTo(Resume o) {
return this.uuid.compareTo(o.uuid);
}
}
26 changes: 26 additions & 0 deletions src/com/urise/webapp/storage/AbstractArrayStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.urise.webapp.storage;

import com.urise.webapp.model.Resume;
import java.util.Arrays;

public abstract class AbstractArrayStorage implements Storage {
protected static final int STORAGE_LIMIT = 10000;
protected Resume[] storage = new Resume[STORAGE_LIMIT];
protected int storageSize;

public int size() {
return storageSize;
}

public Resume get(String uuid) {
int index = getIndex(uuid);
if (index >= 0) {
return storage[index];
} else {
System.out.println("Resume " + uuid + " isn't exists!");
return null;
}
}

protected abstract int getIndex(String uuid);
}
12 changes: 2 additions & 10 deletions src/com/urise/webapp/storage/ArrayStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
/**
* Array based storage for Resumes
*/
public class ArrayStorage implements Storage {

private static final int STORAGE_LIMIT = 10000;
private Resume[] storage = new Resume[STORAGE_LIMIT];
private int storageSize;
public class ArrayStorage extends AbstractArrayStorage {

public void clear() {
Arrays.fill(storage,0, storageSize, null);
Expand Down Expand Up @@ -68,11 +64,7 @@ public Resume[] getAll() {
return Arrays.copyOf(storage, storageSize);
}

public int size() {
return storageSize;
}

private int getIndex(String uuid) {
protected int getIndex(String uuid) {
for (int i = 0; i < storageSize; i++) {
if (uuid.equals(storage[i].getUuid())) {
return i;
Expand Down
39 changes: 39 additions & 0 deletions src/com/urise/webapp/storage/SortedArrayStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.urise.webapp.storage;

import com.urise.webapp.model.Resume;
import java.util.Arrays;

public class SortedArrayStorage extends AbstractArrayStorage {

@Override
public void clear() {

}

@Override
public void update(Resume r) {

}

@Override
public void save(Resume r) {

}

@Override
public void delete(String uuid) {

}

@Override
public Resume[] getAll() {
return new Resume[0];
}

@Override
protected int getIndex(String uuid) {
Resume searchKey = new Resume();
searchKey.setUuid(uuid);
return Arrays.binarySearch(storage, 0, storageSize, searchKey);
}
}