-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
first solution #1682
base: master
Are you sure you want to change the base?
first solution #1682
Conversation
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.
Good job on implementing this task, please review my comments.
private int index; | ||
|
||
public StorageImpl() { | ||
int maxArrSize = 10; |
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.
Replace this local variable with constant field: private static final int MAX_SIZE = 10;
.
|
||
public class StorageImpl<K, V> implements Storage<K, V> { | ||
private Object[] keys; | ||
private Object[] values; | ||
private int index; |
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.
Rename this variable, so the name will better suit it's purpose.
private int index; | |
private int size; |
keys[index] = key; | ||
values[index] = value; | ||
index++; |
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.
Add check to ensure that maximum capacity is not exceeded.
keys[index] = key; | |
values[index] = value; | |
index++; | |
if (size < MAX_SIZE) { | |
keys[size] = key; | |
values[size] = value; | |
size++; | |
} else { | |
throw new IllegalStateException("Storage is full. Maximum capacity is " + MAX_SIZE); | |
} |
No description provided.