From 5c88e81a0159ee2c476b254a429efcbdbf206aa5 Mon Sep 17 00:00:00 2001 From: Sergii Nosachenko <54940595+sergii-nosachenko@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:56:40 +0300 Subject: [PATCH 1/5] Update.yml --- .github/workflows/ci.yml | 2 +- src/main/java/core/basesyntax/Storage.java | 3 ++ .../core/basesyntax/impl/StorageImpl.java | 37 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc27966a7..bcedab668 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: uses: actions/setup-java@v4 with: java-version: '17' - distribution: adopt + distribution: 'temurin' cache: maven - name: Build with Maven run: mvn --batch-mode --update-snapshots verify diff --git a/src/main/java/core/basesyntax/Storage.java b/src/main/java/core/basesyntax/Storage.java index 214ca6a15..f17e70e56 100644 --- a/src/main/java/core/basesyntax/Storage.java +++ b/src/main/java/core/basesyntax/Storage.java @@ -6,4 +6,7 @@ public interface Storage { V get(K key); int size(); + + + } diff --git a/src/main/java/core/basesyntax/impl/StorageImpl.java b/src/main/java/core/basesyntax/impl/StorageImpl.java index 455a7b080..dcbe75fcb 100644 --- a/src/main/java/core/basesyntax/impl/StorageImpl.java +++ b/src/main/java/core/basesyntax/impl/StorageImpl.java @@ -3,17 +3,52 @@ import core.basesyntax.Storage; public class StorageImpl implements Storage { + + private static final int MAX_ITEMS_NUMBER = 10; + private Object[] items; + + private K[] keys; + private V[] values; + private int size; + + public StorageImpl() { + keys = (K[]) new Object[MAX_ITEMS_NUMBER]; + values = (V[]) new Object[MAX_ITEMS_NUMBER]; + size = 0; + } + @Override public void put(K key, V value) { + + for (int i = 0; i < size; i++) { + if (keys[i].equals(key)) { + values[i] = value; + return; + } + } + + if (size == MAX_ITEMS_NUMBER) { + throw new RuntimeException("Storage is full"); + } + + keys[size] = key; + values[size] = value; + size++; } @Override public V get(K key) { + for (int i = 0; i < size; i++) { + if (keys[i].equals(key)) { + return values[i]; + } + } + return null; } @Override public int size() { - return -1; + return size; } } From 1cdee46ffdfb63827e0870d813dc21b2808ac483 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 25 Feb 2026 22:01:33 +0100 Subject: [PATCH 2/5] Update1.yml --- src/main/java/core/basesyntax/Storage.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/core/basesyntax/Storage.java b/src/main/java/core/basesyntax/Storage.java index f17e70e56..b8e434f56 100644 --- a/src/main/java/core/basesyntax/Storage.java +++ b/src/main/java/core/basesyntax/Storage.java @@ -7,6 +7,4 @@ public interface Storage { int size(); - - } From 3c4aa4a74f9ed1038e8df0ca8c2662d59cddcd1d Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 25 Feb 2026 22:01:33 +0100 Subject: [PATCH 3/5] Update1.yml --- src/main/java/core/basesyntax/Storage.java | 3 -- .../core/basesyntax/impl/StorageImpl.java | 31 ++++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/core/basesyntax/Storage.java b/src/main/java/core/basesyntax/Storage.java index f17e70e56..214ca6a15 100644 --- a/src/main/java/core/basesyntax/Storage.java +++ b/src/main/java/core/basesyntax/Storage.java @@ -6,7 +6,4 @@ public interface Storage { V get(K key); int size(); - - - } diff --git a/src/main/java/core/basesyntax/impl/StorageImpl.java b/src/main/java/core/basesyntax/impl/StorageImpl.java index dcbe75fcb..a84289ef8 100644 --- a/src/main/java/core/basesyntax/impl/StorageImpl.java +++ b/src/main/java/core/basesyntax/impl/StorageImpl.java @@ -5,8 +5,6 @@ public class StorageImpl implements Storage { private static final int MAX_ITEMS_NUMBER = 10; - private Object[] items; - private K[] keys; private V[] values; private int size; @@ -17,20 +15,27 @@ public StorageImpl() { size = 0; } - @Override - public void put(K key, V value) { - + private int findIndexByKey(K key) { for (int i = 0; i < size; i++) { - if (keys[i].equals(key)) { - values[i] = value; - return; + if ((keys[i] == null && key == null) + || (keys[i] != null && keys[i].equals(key))) { + return i; } } + return -1; + } + @Override + public void put(K key, V value) { + int index = findIndexByKey(key); + + if (index != -1) { + values[index] = value; + return; + } if (size == MAX_ITEMS_NUMBER) { throw new RuntimeException("Storage is full"); } - keys[size] = key; values[size] = value; size++; @@ -38,12 +43,10 @@ public void put(K key, V value) { @Override public V get(K key) { - for (int i = 0; i < size; i++) { - if (keys[i].equals(key)) { - return values[i]; - } + int index = findIndexByKey(key); + if (index != -1) { + return values[index]; } - return null; } From dd20acf1d0415460a22cd663475fa6be5e06b858 Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 23 Mar 2026 22:01:10 +0100 Subject: [PATCH 4/5] Update 2 --- src/main/java/core/basesyntax/Storage.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/core/basesyntax/Storage.java b/src/main/java/core/basesyntax/Storage.java index f17e70e56..b8e434f56 100644 --- a/src/main/java/core/basesyntax/Storage.java +++ b/src/main/java/core/basesyntax/Storage.java @@ -7,6 +7,4 @@ public interface Storage { int size(); - - } From ff99c1fb4b49a5631144ca074aaae1b8832846da Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 23 Mar 2026 22:09:27 +0100 Subject: [PATCH 5/5] Update5.yml --- .../java/core/basesyntax/impl/StorageImpl.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/core/basesyntax/impl/StorageImpl.java b/src/main/java/core/basesyntax/impl/StorageImpl.java index a84289ef8..aac25f91a 100644 --- a/src/main/java/core/basesyntax/impl/StorageImpl.java +++ b/src/main/java/core/basesyntax/impl/StorageImpl.java @@ -7,16 +7,16 @@ public class StorageImpl implements Storage { private static final int MAX_ITEMS_NUMBER = 10; private K[] keys; private V[] values; - private int size; + private int siize; public StorageImpl() { keys = (K[]) new Object[MAX_ITEMS_NUMBER]; values = (V[]) new Object[MAX_ITEMS_NUMBER]; - size = 0; + siize = 0; } private int findIndexByKey(K key) { - for (int i = 0; i < size; i++) { + for (int i = 0; i < siize; i++) { if ((keys[i] == null && key == null) || (keys[i] != null && keys[i].equals(key))) { return i; @@ -33,12 +33,12 @@ public void put(K key, V value) { values[index] = value; return; } - if (size == MAX_ITEMS_NUMBER) { + if (siize == MAX_ITEMS_NUMBER) { throw new RuntimeException("Storage is full"); } - keys[size] = key; - values[size] = value; - size++; + keys[siize] = key; + values[siize] = value; + siize++; } @Override @@ -52,6 +52,6 @@ public V get(K key) { @Override public int size() { - return size; + return siize; } }