Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -200,3 +200,4 @@
## Ресурсы в сети
- [EduTools плагин от JetBrains для изучения Kotlin, Java, Python, Scala и других языков](http://javaops.ru/view/story/story21#edutools)
- [JetBrains Academy — интерактивный учебный курс по Java](https://www.jetbrains.com/ru-ru/academy/)
"# basejava"
40 changes: 38 additions & 2 deletions src/ArrayStorage.java
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,66 @@
import java.util.Arrays;

/**
* Array based storage for Resumes
*/
public class ArrayStorage{
Resume[] storage = new Resume[10000];

private static int size = 0;

void clear(){
for (int i = 0; i < size; i++){
storage[i] = null;
}
size = 0;
}

void save(Resume r){
if (r == null) throw new IllegalArgumentException("resume not null");
if (size == 0) storage[0] = r;
else storage[size] = r;
size++;
}


Resume get(String uuid){
for (int i = 0; i < size; i++){
if (this.storage[i].uuid == uuid)
return storage[i];
}
return null;
}

void delete(String uuid){
for (int i = 0; i < size; i++){
if (storage[i].uuid.equals(uuid)){
// storage[i] = null;
storage[i] = storage[size - 1];
storage[size - 1] = null;
size--;
}
}

}

/**
* @return array, contains only Resumes in storage (without null)
*/
Resume[] getAll(){
return new Resume[0];
Resume[] resumes = new Resume[size];
for (int i = 0; i < size; i++){
resumes[i] = storage[i];
}
return resumes;
}

int size(){
return 0;
return size;
}

@Override
public String toString(){
return "ArrayStorage{" +
"storage=" + Arrays.toString(storage);
}
}
2 changes: 2 additions & 0 deletions src/MainTestArrayStorage.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,14 @@ public static void main(String[] args){
ARRAY_STORAGE.save(r2);
ARRAY_STORAGE.save(r3);


System.out.println("Get r1: " + ARRAY_STORAGE.get(r1.uuid));
System.out.println("Size: " + ARRAY_STORAGE.size());

System.out.println("Get dummy: " + ARRAY_STORAGE.get("dummy"));

printAll();
System.out.println();
ARRAY_STORAGE.delete(r1.uuid);
printAll();
ARRAY_STORAGE.clear();
Expand Down