Skip to content

Commit

Permalink
STORAGE: refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
kenu21 committed Oct 4, 2024
1 parent 5ec451c commit c0ade37
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/main/java/core/basesyntax/impl/StorageImpl.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package core.basesyntax.impl;

import core.basesyntax.Storage;
import java.util.Arrays;

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

private K[] keys = (K[]) new Object[10];
private V[] values = (V[]) new Object[10];
public static final int INITIAL_SIZE = 10;
public static final int LAST_INDEX_NUMBER = 9;

private K[] keys = (K[]) new Object[INITIAL_SIZE];
private V[] values = (V[]) new Object[INITIAL_SIZE];
private int index = 0;

@Override
public void put(K key, V value) {
if (index > 9) {
if (index > LAST_INDEX_NUMBER) {
throw new RuntimeException("Too many!");
}
for (int i = 0; i < keys.length; i++) {
Expand Down Expand Up @@ -53,26 +55,4 @@ public V get(K key) {
public int size() {
return index;
}

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}

StorageImpl<?, ?> storage = (StorageImpl<?, ?>) object;
return index == storage.index && Arrays.equals(keys, storage.keys)
&& Arrays.equals(values, storage.values);
}

@Override
public int hashCode() {
int result = Arrays.hashCode(keys);
result = 31 * result + Arrays.hashCode(values);
result = 31 * result + index;
return result;
}
}

0 comments on commit c0ade37

Please sign in to comment.