Question: package p 1 . comparator; import p 1 . card.Card; import p 1 . card.CardColor; import java.util.Comparator; import static org.tudalgo.algoutils.student.Student.crash; / * * * Compares

package p1.comparator;
import p1.card.Card;
import p1.card.CardColor;
import java.util.Comparator;
import static org.tudalgo.algoutils.student.Student.crash;
/**
* Compares two {@linkplain Card Cards}.
*
* The cards are first compared by their value and then by their {@link CardColor}.
*
* @see Card
* @see CardColor
*/
public class CardComparator implements Comparator {
/**
* Compares two {@linkplain Card Cards}.
*
* The cards are first compared by their value and then by their {@link CardColor}.
*
* The value of the cards compared by the natural order of the {@link Integer} class.
*
* The color of the cards compared using the following order: {@link CardColor#CLUBS}>{@link CardColor#SPADES}>.{@link CardColor#HEARTS}>{@link CardColor#DIAMONDS}.
*
* @param o1 the first {@link Card} to compare.
* @param o2 the second {@link Card} to compare.
* @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
* @throws NullPointerException if either of the {@linkplain Card Cards} is null.
*
* @see Card
* @see CardColor
* @see Comparator#compare(Object, Object)
*/
@Override
public int compare(Card o1, Card o2){
return crash(); //TODO: H1 a)- remove if implemented
}
}
package p1.comparator;
import java.util.Comparator;
import static org.tudalgo.algoutils.student.Student.crash;
/**
* An {@link Comparator} that stores the number of comparisons made by the {@link #compare(Object, Object)} method.
*
* The number of comparisons can be reset using the {@link #reset()} method.
*
* The actual comparison is delegated to another {@link Comparator}.
*
* @param
*/
public class CountingComparator implements Comparator {
/**
* The {@link Comparator} that performs the actual comparison.
*/
private final Comparator delegate;
/**
* Creates a new {@link CountingComparator} that delegates the actual comparison to the given {@link Comparator}.
* @param delegate the {@link Comparator} that performs the actual comparison.
*/
public CountingComparator(Comparator delegate){
this.delegate = delegate;
}
/**
* Resets the number of comparisons made by the {@link #compare(Object, Object)} method to 0.
*/
public void reset(){
crash(); //TODO: H1 b)- remove if implemented
}
/**
* Compares its two arguments for order using the delegate {@link Comparator} given in the constructor.
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
*
* @see Comparator#compare(Object, Object)
*/
@Override
public int compare(T o1, T o2){
return crash(); //TODO: H1 b)- remove if implemented
}
/**
* Returns the number of comparisons made by the {@link #compare(Object, Object)} method since the last time {@link #reset()} got called.
* If the {@link #reset()} method did not get called yet, the number of comparisons made since the creation of this object will be returned.
*
* The number of comparisons is equal to the number of times the {@link #compare(Object, Object)} method got called.
*
* @return the number of comparisons made.
*/
public int getComparisonsCount(){
return crash(); //TODO: H1 b)- remove if implemented
}
}
 package p1.comparator; import p1.card.Card; import p1.card.CardColor; import java.util.Comparator; import static org.tudalgo.algoutils.student.Student.crash;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!