-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Jv storage #1916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Jv storage #1916
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package core.basesyntax.impl; | ||
|
|
||
| import core.basesyntax.Storage; | ||
|
|
||
| public class Main extends StorageImpl { | ||
| public static void main(String[] args) { | ||
|
|
||
| Storage<Integer, String> storage = new StorageImpl<>(); | ||
| storage.put(1991, "Independence of Ukraine"); | ||
|
|
||
| String value = storage.get(1991); | ||
| int size = storage.size(); | ||
|
|
||
| System.out.println("Value: " + value); | ||
| System.out.println("Size: " + size); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,47 @@ | |
| import core.basesyntax.Storage; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line before class declaration. Remove according to checklist requirements. |
||
| public class StorageImpl<K, V> implements Storage<K, V> { | ||
| public static final int MAX_Keys_And_Values = 10; | ||
| protected final K[] keys; | ||
| protected final V[] values; | ||
| private int size = 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All non-constant fields should be initialized in the constructor. Move |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line before method implementation. Remove according to checklist. |
||
| public StorageImpl() { | ||
| this.keys = (K[]) new Object[MAX_Keys_And_Values]; | ||
| this.values = (V[]) new Object[MAX_Keys_And_Values]; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line before method implementation. Remove according to checklist. |
||
| @Override | ||
| public void put(K key, V value) { | ||
| for (int i = 0; i < size; i++) { | ||
| if (keys[i] == null && key == null) { | ||
| values[i] = value; | ||
| return; | ||
| } | ||
| if (keys[i] != null && keys[i].equals(key)) { | ||
| values[i] = value; | ||
| return; | ||
| } | ||
| } | ||
| keys[size] = key; | ||
| values[size] = value; | ||
| size++; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line before method implementation. Remove according to checklist. |
||
| @Override | ||
| public V get(K key) { | ||
| for (int i = 0; i < keys.length; i++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logical inconsistency: |
||
| if (keys[i] == null && key == null) { | ||
| return values[i]; | ||
| } else if (keys[i] != null && keys[i].equals(key)) { | ||
| return values[i]; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Empty line before method implementation. Remove according to checklist. |
||
| @Override | ||
| public int size() { | ||
| return -1; | ||
| return this.size; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checklist item #3 violation: Constant name should follow UPPER_SNAKE_CASE naming convention (e.g., MAX_ELEMENTS_CAPACITY) and could be more informative about its purpose.