Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 pcomparator;
import pcard.Card;
import pcard.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 o the first @link Card to compare.
@param o 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#compareObject Object
@Override
public int compareCard o Card o
return crash; TODO: H a remove if implemented
package pcomparator;
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 #compareObject 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 CountingComparatorComparator delegate
this.delegate delegate;
Resets the number of comparisons made by the @link #compareObject Object method to
public void reset
crash; TODO: H b remove if implemented
Compares its two arguments for order using the delegate @link Comparator given in the constructor.
@param o the first object to be compared.
@param o 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#compareObject Object
@Override
public int compareT o T o
return crash; TODO: H b remove if implemented
Returns the number of comparisons made by the @link #compareObject 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 #compareObject Object method got called.
@return the number of comparisons made.
public int getComparisonsCount
return crash; TODO: H b remove if implemented
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started