Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

first solution #1682

wants to merge 1 commit into from

Conversation

anpiet
Copy link

@anpiet anpiet commented Jan 31, 2025

No description provided.

Copy link

@slade13 slade13 left a 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;
Copy link

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;
Copy link

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.

Suggested change
private int index;
private int size;

Comment on lines +28 to +30
keys[index] = key;
values[index] = value;
index++;
Copy link

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.

Suggested change
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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants