Skip to content
Open
Changes from 1 commit
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
@@ -1,19 +1,53 @@
package core.basesyntax.impl;

import java.util.Objects;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Uses java.util.Objects class which violates 'Don't use class Objects' requirement. Replace Objects.equals() with a manual null-safe comparison method.


import core.basesyntax.Storage;

public class StorageImpl<K, V> implements Storage<K, V> {

private final int MAX = 10;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MAX is declared as instance field instead of static constant. Should be 'private static final int MAX_STORAGE_CAPACITY = 10;'


Object[] keys = new Object[MAX];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-constant field 'keys' is initialized as field declaration. Per checklist: all non-constant fields should be initialized in the constructor.

Object[] values = new Object[MAX];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-constant field 'values' is initialized as field declaration. Per checklist: all non-constant fields should be initialized in the constructor.

int size = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-constant field 'size' is initialized as field declaration. Per checklist: all non-constant fields should be initialized in the constructor.


@Override
public void put(K key, V value) {

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++) {

if (Objects.equals(keys[i], 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.

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


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 (Objects.equals(keys[i], 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