Answered step by step
Verified Expert Solution
Link Copied!

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 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
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago