Skip to content

Commit

Permalink
Update StorageImpl.java
Browse files Browse the repository at this point in the history
  • Loading branch information
OksanaEnko authored Jan 18, 2025
1 parent 7c49256 commit 9dbd131
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/main/java/core/basesyntax/impl/StorageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,41 @@ public class StorageImpl<K, V> implements Storage<K, V> {
private final K[] keys;
private final V[] values;
private int size;

@SuppressWarnings("unchecked")
public StorageImpl() {
keys = (K[]) new Object[MAX_CAPACITY];
values = (V[]) new Object[MAX_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] != null && keys[i].equals(key))) {
values[i] = value;
return;
}
}
if (size < MAX_CAPACITY) {
keys[size] = key;
values[size] = value;
size++;
}
}

@Override
public V get(K key) {
return null;
for (int i = 0; i < size; i++) {
if ((keys[i] == null && key == null) || (keys[i] != null && keys[i].equals(key))) {
return values[i];
}
}
return null;
}

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

0 comments on commit 9dbd131

Please sign in to comment.