-
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
solution #1350
base: master
Are you sure you want to change the base?
solution #1350
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.
Before you create PR with your homework, you need to go through the checklist under the task and correct all the points described there. The mentor will not check the work until the checklist points are corrected
@Override | ||
public boolean equals(Object storageObject) { | ||
if (storageObject == this) { | ||
return true; | ||
} | ||
if (storageObject == null) { | ||
return false; | ||
} | ||
if (storageObject.getClass().equals(StorageObject.class)) { | ||
StorageObject current = (StorageObject) storageObject; | ||
boolean keyEquals = (this.key == null && current.key == null) | ||
|| (this.key != null && this.key.equals(current.key)); | ||
boolean valueEquals = (this.value == null && current.value == null) | ||
|| (this.value != null && this.value.equals(current.value)); | ||
return keyEquals && valueEquals; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = 17; | ||
result = 31 * result + (key == null ? 0 : key.hashCode()); | ||
result = 31 * result + (value == null ? 0 : value.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + "key=" |
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.
delete this
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.
delete this
why? what is the other solution?
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.
make it nested class
it uses only inside `Storage, so we don't need it public
|
||
public class StorageImpl<K, V> implements Storage<K, V> { | ||
|
||
private final StorageObject[] storage = new StorageObject[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.
|
||
private final StorageObject[] storage = new StorageObject[10]; | ||
|
||
private int size = 0; |
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.
private int size = 0; | |
private int size; |
@Override | ||
public boolean equals(Object storageObject) { | ||
if (storageObject == this) { | ||
return true; | ||
} | ||
if (storageObject == null) { | ||
return false; | ||
} | ||
if (storageObject.getClass().equals(StorageObject.class)) { | ||
StorageObject current = (StorageObject) storageObject; | ||
boolean keyEquals = (this.key == null && current.key == null) | ||
|| (this.key != null && this.key.equals(current.key)); | ||
boolean valueEquals = (this.value == null && current.value == null) | ||
|| (this.value != null && this.value.equals(current.value)); | ||
return keyEquals && valueEquals; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = 17; | ||
result = 31 * result + (key == null ? 0 : key.hashCode()); | ||
result = 31 * result + (value == null ? 0 : value.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + "key=" |
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.
make it nested class
it uses only inside `Storage, so we don't need it public
private static final int PRIMARY_SIZE = 0; | ||
private final StorageObject[] storage; | ||
private int size; | ||
|
||
public StorageImpl() { | ||
this.size = PRIMARY_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.
redundant, java set 0 as default for primitive
private static final int PRIMARY_SIZE = 0; | |
private final StorageObject[] storage; | |
private int size; | |
public StorageImpl() { | |
this.size = PRIMARY_SIZE; | |
private final StorageObject[] storage; | |
private int size; | |
public StorageImpl() { |
if (object == null) { | ||
break; | ||
} else if (object.getKey() == null && key == null) { | ||
return (V) object.getValue(); | ||
} else if (object.getKey() != null | ||
&& object.getKey().equals(key)) { | ||
return (V) object.getValue(); | ||
} |
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.
if statement could be simplified.
you have similar logic in each clause
storage[i] = storageToAdd; | ||
size++; | ||
break; | ||
} else if (storage[i].getKey() == null | ||
&& storageToAdd.getKey() == null) { | ||
storage[i] = storageToAdd; | ||
break; | ||
} else if (storage[i].getKey() != null | ||
&& storage[i].getKey().equals(storageToAdd.getKey())) { | ||
storage[i] = storageToAdd; | ||
break; | ||
} |
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.
simplify if-else
No description provided.