Conversation
| package school.lemon.changerequest.java.generics.Container; | ||
|
|
||
|
|
||
| public class Container<T> implements ContainerInterface { |
There was a problem hiding this comment.
The thing is, that you should implement generic interface, and it should looks like:
Container<T> implements ContainerInterface<T>
This will help you avoid casting to T.
| return arrayDouble; | ||
| } | ||
|
|
||
| public Double calcSumForDouble(Double[] array) { |
There was a problem hiding this comment.
Why do you need this method?
There was a problem hiding this comment.
It was a line what I missed to delete)
|
|
||
| public static <K, V> boolean equals(Pair<K, V> pair1, Pair<K, V> pair2) { | ||
| boolean flag = false; | ||
| if (pair1.getKey().equals(pair2.getKey()) && pair1.getValue().equals(pair2.getValue())) { |
There was a problem hiding this comment.
It can be much simpler:
return pair1.getKey().equals(pair2.getKey()) && pair1.getValue().equals(pair2.getValue());
| public static <K, V> boolean containsUniqueObjects(Pair<K, V>[] pairs) { | ||
| for (Pair<K, V> pair : pairs) { | ||
| int i = 1; | ||
| while (i < pairs.length) { |
There was a problem hiding this comment.
It's not working as expected.
It will always return false, because you are comparing pairs[1] with pairs[1].
| public void generateAndPrint() { | ||
| T[] arrayNumbers = numberGenerator.generateNumbers(); | ||
| if (numberGenerator instanceof IntegerGenerator) { | ||
| sum = (SumCalculator<T>) new IntegerSumCalculator(); |
There was a problem hiding this comment.
- It's better to move creation of SumCalculator to constructor.
- It's mot flexible, because there is no way to add new type of number generator.
I'd prefer to create additional method in NumberGenerator that will return specific SumCalculator.
|
|
||
| public abstract T[] generateNumbers(); | ||
|
|
||
| abstract SumCalculator getSumCalculator(); |
There was a problem hiding this comment.
protected or public is preferred.
| package school.lemon.changerequest.java.generics.Generator; | ||
|
|
||
| public class Printer<T extends Number> { | ||
| NumberGenerator<T> numberGenerator; |
|
|
||
| public Printer(NumberGenerator<T> numberGenerator) { | ||
| this.numberGenerator = numberGenerator; | ||
| if (numberGenerator instanceof IntegerGenerator) { |
There was a problem hiding this comment.
You should receive it from generator.
|
|
||
| public void generateAndPrint() { | ||
| T[] arrayNumbers = numberGenerator.generateNumbers(); | ||
| numberGenerator.getSumCalculator(); |
There was a problem hiding this comment.
Why do you call this method here? Move it to constructor.
| } | ||
|
|
||
| public static <K, V> boolean containsUniqueObjects(Pair<K, V>[] pairs) { | ||
| for (int a = 0; a < pairs.length; a++ ){ |
There was a problem hiding this comment.
- Please format your code.
- General names for loop variables are: i, j, k... Or just some other meaningful name like
outerCounter,innerCounter. But nota. - It's better to use
a < pairs.lenth - 1, but it's ok to do it like you.
No description provided.