Skip to content
Open
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
36 changes: 35 additions & 1 deletion src/main/java/core/basesyntax/impl/StorageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,51 @@
import core.basesyntax.Storage;

public class StorageImpl<K, V> implements Storage<K, V> {
private static final int MAX_STORAGE_CAPACITY = 10;
private final Object[] keys;
private final Object[] values;
private int size;

public StorageImpl() {
keys = new Object[MAX_STORAGE_CAPACITY];
values = new Object[MAX_STORAGE_CAPACITY];
size = 0;
}

@Override
public void put(K key, V value) {
for (int i = 0; i < size; i++) {

if (keys[i] == null ? key == null : keys[i].equals(key)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHECKLIST VIOLATION #4: This null-safe equality check is duplicated in get() method at line 39. Extract this logic into a private helper method (e.g., areKeysEqual(Object storedKey, K searchKey)) to follow the DRY principle.


values[i] = value;
return;
}
}

keys[size] = key;
values[size] = value;

size++;

}

@Override
public V get(K key) {
Comment on lines 35 to 36
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line at start of method implementation - remove redundant empty line.

for (int i = 0; i < size; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces existing key's value - uses Objects.equals which is not allowed per checklist requirements.

if (keys[i] == null ? key == null : keys[i].equals(key)) {

return (V) values[i];
}

}
return null;

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line at start of method implementation - remove redundant empty line.


@Override
public int size() {
return -1;
return size;
}
}
Loading