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

STORAGE: implemented storage #1605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

kenu21
Copy link

@kenu21 kenu21 commented Oct 4, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! It looks like there are a few important areas that need a bit of work before we can give the green light. Specifically, be careful with unchecked casts and potential ClassCastExceptions, and make sure to check array bounds to prevent ArrayIndexOutOfBoundsExceptions. Also, it's a good idea to avoid redundant code and use constants instead of magic numbers to make your code clearer and easier to maintain. Keep at it, and with a few tweaks, your code will be in great shape! 🛠️👍

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! It looks like we've got a few kinks to iron out before we can give this PR the green light. 🛠️ There's a potential bug that could cause some key-value pairs to get overwritten, which is definitely something we want to avoid. Also, I noticed a little bit of repeated code that could be cleaned up for a more polished look. No worries, though! With a bit of tweaking and a couple of fixes, we'll be on track for approval. Keep up the good work, and let's make this code shine! 💪😄

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on submitting your Pull Request! 🌟 There are a few issues to address in the future: consider initializing 'index' in the constructor, use more specific exceptions with clear messages, refactor duplicated null key checks, replace magic numbers with array lengths, extract repeating logic to private methods, and initialize non-constant fields in the constructor. Keep up the good work and use these tips to enhance your code! 👍

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨


public static final int INITIAL_SIZE = 10;

private K[] keys = (K[]) new Object[INITIAL_SIZE];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-constant fields should be initialized in the constructor. Move the initialization of 'keys' and 'values' arrays to the constructor.

Comment on lines +19 to +27
if (key == null && keys[i] == null) {
if (values[i] == null) {
values[i] = value;
index++;
return;
} else {
values[i] = value;
return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't create repeating code. The logic for setting the value in 'values' array repeats. You can extract this logic to a private method to avoid duplication.

Comment on lines +15 to +16
if (index > INITIAL_SIZE - 1) {
throw new RuntimeException("Too many!");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using magic numbers directly in the code can be confusing. Consider using 'keys.length' instead of 'INITIAL_SIZE - 1' to check for the array bounds as it reflects the intent more clearly and is less error-prone.

Comment on lines +19 to +27
if (key == null && keys[i] == null) {
if (values[i] == null) {
values[i] = value;
index++;
return;
} else {
values[i] = value;
return;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for null key is duplicated in the 'put' and 'get' methods. Consider refactoring this into a private method to determine the index of a key, which can then be used in both 'put' and 'get' methods.

@Override
public void put(K key, V value) {
if (index > INITIAL_SIZE - 1) {
throw new RuntimeException("Too many!");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing a generic RuntimeException with a vague message is not very informative. It's better to create a custom exception or use a more specific exception type with a clear message indicating the storage is full.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'index' field is not a constant but it's not initialized in the constructor. Consider initializing 'index' in the constructor for consistency and to follow the best practices.

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