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
27 changes: 26 additions & 1 deletion src/main/java/core/basesyntax/impl/StorageImpl.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
package core.basesyntax.impl;

import core.basesyntax.Storage;
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.

This file imports and uses java.util.Objects which violates the checklist item: "Don't use class Objects". Replace Objects.equals(...) with a null-safe equality check (or a private helper) and remove this import.


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

public StorageImpl() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All non-constant fields must be initialized in the constructor per the checklist: "All non-constant fields should be initialized in the constructor". size is declared but not explicitly initialized in the constructor — add size = 0; (or set it explicitly) inside the constructor.

keys = new Object[MAX_SIZE];
values = new Object[MAX_SIZE];
}

@Override
public void put(K key, V value) {
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.

The equality check here duplicates the same logic used in get(). This violates the checklist item: "Don't create repeating code". Extract a private null-safe comparison method (for example private boolean keysEqual(Object a, Object b)) and call it from both put and get. Also avoid using Objects.equals as per the checklist.

values[i] = value;
return;
}
}
keys[size] = key;
values[size] = value;
size++;
}

@Override
public V get(K key) {
for (int i = 0; i < size; i++) {
if (Objects.equals(key, keys[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.

This equality check uses Objects.equals(...), which is disallowed by the checklist: "Don't use class Objects". Use the same private null-safe comparison helper suggested above instead of calling Objects.equals here.

return (V) values[i];
}
}
return null;
}

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