Taks 1 and 2 done.#2
Taks 1 and 2 done.#2yarikpavlin wants to merge 2 commits intoChangeRequest:masterfrom yarikpavlin:master
Conversation
xSAVIKx
left a comment
There was a problem hiding this comment.
Please check comments below, provide demo for Container implementation and try to solve last task.
| return true; | ||
| if(a == null || b == null) | ||
| return false; | ||
| if(a.getKey() == b.getKey() && a.getValue() == b.getValue()) |
There was a problem hiding this comment.
You should use equals method, cause == will check if objects point to the same part in memory
| int count = 0; | ||
| for(int i = 0; i < a.length; i++) | ||
| { | ||
| if(key.compareTo(a[i].getKey()) == -1) |
There was a problem hiding this comment.
CompareTo can return any negative number, not only -1
| */ | ||
| public class TestingApp { | ||
| public static void main(String[] args) { | ||
| Pair p1 = new Pair<>(1,"k1"); |
There was a problem hiding this comment.
Your pairs should be initialized with some Generics, you should not use raw notation, so please, use smth like:
Pair<Integer,String> p1 = new Pair<>(1,"k1");| Pair p2 = new Pair<>(2,"k2"); | ||
| Pair p4 = new Pair<>(3,"k3"); | ||
|
|
||
| Pair[] pA = new Pair[3]; |
There was a problem hiding this comment.
Same for array. you shouldn't use raw types.
|
|
||
| ContainerImpl() | ||
| { | ||
| this.array = (E[]) new Object[10]; |
There was a problem hiding this comment.
I'm not sure that such class cast will work. You cannot cast Object to Type E[].
Please provide Demo class for Container to check whether your implementation work correctly.
Provide demo for all operations for some 2 different Generic type, for example: String and Float.
| /** | ||
| * Created by Yaroslav Pavlinskiy on 22.12.2016. | ||
| */ | ||
| public class TestingApp { |
There was a problem hiding this comment.
Your Demo class should provide demo for all possible operations with 2 or 3 different pair types ( for example: <String,Integer>, <Double, Float>, <Integer, Container>)
|
|
||
| public static <K extends Comparable<K>,V> int compareTo(Pair<K,V> a,Pair<K,V> b) | ||
| { | ||
| return a.getKey().compareTo(b.getKey()); |
There was a problem hiding this comment.
What about NullPointerException checks ? (Please add them for all methods)
| this.key = key; | ||
| } | ||
|
|
||
| public boolean contains(K key) |
There was a problem hiding this comment.
This method is quite weird, cause it not really check whether given pair contains smth. It just check whether some key is exactly same object as key from the pair. (also, you should not use ==, but use equals instead).
| * Created by Yaroslav Pavlinskiy on 22.12.2016. | ||
| */ | ||
| public class Pair <K,V> { | ||
| protected V value; |
There was a problem hiding this comment.
Why do you need fields to be protected ?
3 task will be done soon