Skip to content

Hw1 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
54cb720
HW1
YaDokaYa Oct 17, 2024
1aba60b
HW1
YaDokaYa Oct 17, 2024
4e444d6
HW1:fix delete null, rename storageAll->resumes, corrected delete()
YaDokaYa Oct 22, 2024
09b08b7
HW2: sorted by packages
YaDokaYa Nov 22, 2024
de07681
HW2: update
YaDokaYa Nov 26, 2024
5592ef7
HW2: clear, save, get, delete, getAll,desiredIndex
YaDokaYa Nov 26, 2024
d416a6b
HW2: finally
YaDokaYa Nov 29, 2024
b092f4a
HW2: finally with static class members
YaDokaYa Dec 3, 2024
e5c08b7
HW3: introduce interface
YaDokaYa Dec 3, 2024
ee84f2a
HW3: abstract storage & sorted storage
YaDokaYa Dec 3, 2024
e06f72b
HW3: abstract storage & sorted storage & array storage
YaDokaYa Dec 5, 2024
ed69d01
HW3: templateMethod & save
YaDokaYa Dec 7, 2024
7934f8d
HW3: increaseSize() & protected void reductionSize()
YaDokaYa Dec 12, 2024
83fedb6
HW3: template method
YaDokaYa Dec 12, 2024
00efee7
HW3: finally with removeLastElement()
YaDokaYa Dec 16, 2024
e8aa68f
HW4: exception
YaDokaYa Jan 21, 2025
4db0eba
HW4: begin test
YaDokaYa Jan 21, 2025
e90cd9d
HW4: method get()
YaDokaYa Jan 21, 2025
8e7013e
HW4: method toString through reflection
YaDokaYa Jan 23, 2025
800f91c
HW4: tests
YaDokaYa Jan 23, 2025
b701371
HW4: correction of methods
YaDokaYa Jan 28, 2025
ed0b2cb
HW4: error testStorageOverflow
YaDokaYa Jan 30, 2025
d6963a3
HW4: testStorageOverflow
YaDokaYa Feb 7, 2025
081e3ba
HW4: MainReflection_HW
YaDokaYa Feb 7, 2025
828d01f
HW4: finally
YaDokaYa Feb 7, 2025
2abe819
HW5: begin
YaDokaYa Feb 11, 2025
c9519ee
HW5: static initializer block
YaDokaYa Feb 11, 2025
7770e8c
HW5: final Storage storage
YaDokaYa Feb 11, 2025
a7b68f4
HW5: class AbstractStorage
YaDokaYa Feb 18, 2025
3f05c40
HW5: method exist()&&doUpdate()
YaDokaYa Feb 18, 2025
cbdb919
HW5: method doSave()&&save()
YaDokaYa Feb 18, 2025
0d26281
HW5: method doGet()&&get()
YaDokaYa Feb 18, 2025
a8d41c7
HW5: method doDelete()&&delete()
YaDokaYa Feb 18, 2025
16b70f0
HW5: delete clear(), getAll(), size()
YaDokaYa Feb 21, 2025
643a355
HW5: getSearchKey()&&isExisting()
YaDokaYa Feb 25, 2025
5fb2322
HW5: getExistingSearchKey()
YaDokaYa Feb 25, 2025
54d23ba
HW5: delete save() from AbstractArrayStorage && SortedArrayStorage
YaDokaYa Feb 25, 2025
85982b7
HW5: MapStorage && MapStorageTest
YaDokaYa Feb 27, 2025
1890dfd
HW5: isExisting in AbstractStorage
YaDokaYa Mar 13, 2025
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
12 changes: 6 additions & 6 deletions lesson/lesson1.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

![Screenshot_5](https://user-images.githubusercontent.com/29703461/199550057-fce7cf3c-7040-422f-b490-7b85b47ae952.png)

- Реализуйте методы `save, get, delete, clear, getAll, size` в классе `ArrayStorage`, организовав хранение резюме в массиве
- Реализуйте методы `save, get, delete, clear, getAll, size` в классе `com.urise.webapp.storage.ArrayStorage`, организовав хранение резюме в массиве
- Храните все резюме в начале `storage` (без пустот в виде `null`), чтобы не перебирать каждый раз все 10_000 элементов
- При реализации метода `delete` учитывайте, что после удаления резюме между оставшимися резюме не должно быть пустых ячеек, заполненных null
```
Expand All @@ -77,7 +77,7 @@ r1, r2, r3,..., rn, null, null,..., null
<----- size ----->
<------- storage.length (10000) ------->
```
- Проверьте вашу реализацию с помощью классов `MainArray.main()` и `MainTestArrayStorage.main()`
- Проверьте вашу реализацию с помощью классов `com.urise.webapp.MainArray.main()` и `com.urise.webapp.MainTestArrayStorage.main()`
- Изучите дополнительные материалы по IntelliJ IDEA:
- [Idea Wiki](https://github.com/JavaOPs/topjava/wiki/IDEA)
- [Отладка Java кода в IDEA. Основные возможности отладчика](https://youtu.be/Z1BQsf0A4xY)
Expand All @@ -96,11 +96,11 @@ r1, r2, r3,..., rn, null, null,..., null
1. Перед каждым коммитом не забывайте пользоваться сочетанием клавиш `Ctrl + Alt + L` (автоматическое форматирование кода)
1. Удаляйте в классах неиспользуемые импорты (`Ctrl + Alt + O`)
1. Не игнорируй подсказки IDEA (подсвечивает)
1. В методе `clear()` обнуление массива предполагает обнуление (null) ячеек, где хранятся Resume, а не создание нового или присваивание ему null
1. В методе `clear()` обнуление массива предполагает обнуление (null) ячеек, где хранятся com.urise.webapp.model.Resume, а не создание нового или присваивание ему null
1. При реализации методов не используйте коллекции
1. Не меняйте сигнатуры методов в `ArrayStorage`
1. Не добавляйте в `Resume` новые поля
1. Resume r — давайте переменным осмысленные имена, например resume. r допустимо в коротких циклах и лямбда-выражениях
1. Не меняйте сигнатуры методов в `com.urise.webapp.storage.ArrayStorage`
1. Не добавляйте в `com.urise.webapp.model.Resume` новые поля
1. com.urise.webapp.model.Resume r — давайте переменным осмысленные имена, например resume. r допустимо в коротких циклах и лямбда-выражениях

## ![video](https://cloud.githubusercontent.com/assets/13649199/13672715/06dbc6ce-e6e7-11e5-81a9-04fbddb9e488.png) 5. [Вебинар "Быть программистом: от детства к зрелости"](https://www.youtube.com/watch?v=D5Hej0TyLaU)
- [Слайды вебинара](https://docs.google.com/presentation/d/1YwtCCZsaGMdl-V15kTDHiJxiS52IAl-qqheNPpiNr54/)
Expand Down
30 changes: 0 additions & 30 deletions src/ArrayStorage.java

This file was deleted.

39 changes: 0 additions & 39 deletions src/MainTestArrayStorage.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/Resume.java

This file was deleted.

17 changes: 13 additions & 4 deletions src/MainArray.java → src/com/urise/webapp/MainArray.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.urise.webapp;

import com.urise.webapp.model.Resume;
import com.urise.webapp.storage.ArrayStorage;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* Interactive test for ArrayStorage implementation
* Interactive test for com.urise.webapp.storage.ArrayStorage implementation
* (just run, no need to understand)
*/
public class MainArray {
Expand All @@ -13,7 +18,7 @@ public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Resume r;
while (true) {
System.out.print("Введите одну из команд - (list | size | save uuid | delete uuid | get uuid | clear | exit): ");
System.out.print("Введите одну из команд - (list | size | save uuid | delete uuid | get uuid | clear | update | exit): ");
String[] params = reader.readLine().trim().toLowerCase().split(" ");
if (params.length < 1 || params.length > 2) {
System.out.println("Неверная команда.");
Expand All @@ -31,8 +36,7 @@ public static void main(String[] args) throws IOException {
System.out.println(ARRAY_STORAGE.size());
break;
case "save":
r = new Resume();
r.uuid = uuid;
r = new Resume(uuid);
ARRAY_STORAGE.save(r);
printAll();
break;
Expand All @@ -47,8 +51,13 @@ public static void main(String[] args) throws IOException {
ARRAY_STORAGE.clear();
printAll();
break;
case "update":
r = new Resume(uuid);
ARRAY_STORAGE.update(r);
break;
case "exit":
return;

default:
System.out.println("Неверная команда.");
break;
Expand Down
108 changes: 108 additions & 0 deletions src/com/urise/webapp/MainCollections.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.urise.webapp;

import com.urise.webapp.model.Resume;
import com.urise.webapp.storage.AbstractStorage;
import com.urise.webapp.storage.MapStorage;

import java.util.*;

public class MainCollections {
private static final String UUID_1 = "uuid1";
private static final Resume RESUME_1 = new Resume(UUID_1);

private static final String UUID_2 = "uuid2";
private static final Resume RESUME_2 = new Resume(UUID_2);

private static final String UUID_3 = "uuid3";
private static final Resume RESUME_3 = new Resume(UUID_3);

private static final String UUID_4 = "uuid4";
private static final Resume RESUME_4 = new Resume(UUID_4);
// private static final Resume UUID_NOT_EXIST = new Resume("dummy");
// private static final AbstractStorage ABSTRACT_STORAGE = new ListStorage();
private static final AbstractStorage ABSTRACT_STORAGE = new MapStorage();

public static void main(String[] args) {
ABSTRACT_STORAGE.save(RESUME_1);
ABSTRACT_STORAGE.save(RESUME_2);
ABSTRACT_STORAGE.save(RESUME_3);
ABSTRACT_STORAGE.getAll();
printAll();

System.out.println("Get r1: " + ABSTRACT_STORAGE.get(RESUME_1.getUuid()));
System.out.println("Size: " + ABSTRACT_STORAGE.size());

// System.out.println("Get dummy: " + ABSTRACT_STORAGE.get(UUID_NOT_EXIST.getUuid()));

ABSTRACT_STORAGE.update(RESUME_2);
System.out.println("ok update");
printAll();
System.out.println("--------");

ABSTRACT_STORAGE.save(RESUME_4);
System.out.println("ok save");
printAll();
System.out.println("--------");

ABSTRACT_STORAGE.delete(RESUME_3.getUuid());
System.out.println("ok delete");
printAll();
System.out.println("--------");

ABSTRACT_STORAGE.clear();
System.out.println("ok clear");
printAll();
System.out.println("--------");

System.out.println("Size: " + ABSTRACT_STORAGE.size());
ABSTRACT_STORAGE.size();


System.out.println("Collection");
Collection<Resume> collection = new ArrayList<>();
collection.add(RESUME_1);
collection.add(RESUME_2);
collection.add(RESUME_3);

for (Resume r : collection) {
System.out.println(r);
if (Objects.equals(r.getUuid(), UUID_1)) {
// collection.remove(r);
}
}

Iterator<Resume> iterator = collection.iterator();
while (iterator.hasNext()) {
Resume r = iterator.next();
System.out.println(r);
if (Objects.equals(r.getUuid(), UUID_1)) {
iterator.remove();
}
}
System.out.println(collection.toString());


Map<String, Resume> map = new HashMap<>();
map.put(UUID_1, RESUME_1);
map.put(UUID_2, RESUME_2);
map.put(UUID_3, RESUME_3);

// Bad!
for (String uuid : map.keySet()) {
System.out.println(map.get(uuid));
}

for (Map.Entry<String, Resume> entry : map.entrySet()) {
System.out.println(entry.getValue());
}
}

static void printAll() {
System.out.println("\nGet All");
for (Resume r : ABSTRACT_STORAGE.getAll()) {
System.out.println(r);
}
}
}


23 changes: 23 additions & 0 deletions src/com/urise/webapp/MainReflection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.urise.webapp;

import com.urise.webapp.model.Resume;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MainReflection {
public static void main(String[] args) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Resume r = new Resume();
Class <? extends Resume> resumeClass = r.getClass();
Field field = resumeClass.getDeclaredFields()[0];
field.setAccessible(true);
System.out.println(field.getName());
System.out.println(field.get(r));
field.set(r, "new_uuid");
System.out.println(r);
Method method = resumeClass.getMethod("toString");
Object result = method.invoke(r);
System.out.println(result);
}
}
48 changes: 48 additions & 0 deletions src/com/urise/webapp/MainTestArrayStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.urise.webapp;

import com.urise.webapp.model.Resume;
import com.urise.webapp.storage.AbstractArrayStorage;
import com.urise.webapp.storage.ArrayStorage;

/**
* Test for your com.urise.webapp.storage.ArrayStorage implementation
*/
public class MainTestArrayStorage {
private static final AbstractArrayStorage ARRAY_STORAGE = new ArrayStorage();
// private static final AbstractArrayStorage ARRAY_STORAGE = new SortedArrayStorage();

public static void main(String[] args) {
Resume r1 = new Resume("uuid4");
Resume r2 = new Resume("uuid2");
Resume r3 = new Resume("uuid1");
ARRAY_STORAGE.save(r1);
ARRAY_STORAGE.save(r2);
ARRAY_STORAGE.save(r3);
printAll();

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

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

Resume r = new Resume("uuid2");
ARRAY_STORAGE.update(r);
ARRAY_STORAGE.save(new Resume("dummy"));

printAll();
ARRAY_STORAGE.delete(r2.getUuid());
printAll();
ARRAY_STORAGE.clear();
printAll();

System.out.println("Size: " + ARRAY_STORAGE.size());
ARRAY_STORAGE.size();
}

static void printAll() {
System.out.println("\nGet All");
for (Resume r : ARRAY_STORAGE.getAll()) {
System.out.println(r);
}
}
}
7 changes: 7 additions & 0 deletions src/com/urise/webapp/exception/ExistStorageException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.urise.webapp.exception;

public class ExistStorageException extends StorageException {
public ExistStorageException(String uuid) {
super("Resume " + uuid + " already exist", uuid);
}
}
7 changes: 7 additions & 0 deletions src/com/urise/webapp/exception/NotExistStorageException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.urise.webapp.exception;

public class NotExistStorageException extends StorageException {
public NotExistStorageException(String uuid) {
super("Resume " + uuid + " not exist", uuid);
}
}
14 changes: 14 additions & 0 deletions src/com/urise/webapp/exception/StorageException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.urise.webapp.exception;

public class StorageException extends RuntimeException {
private final String uuid;

public StorageException(String message, String uuid) {
super(message);
this.uuid = uuid;
}

public String getUuid() {
return uuid;
}
}
Loading