public class OperationCounter
extends java.lang.Object
Constructor and Description |
---|
OperationCounter()
Default constructor
Creates an OperationCounter object with all counts set to 0
and the name of the other operation set to "No Other Op".
|
Modifier and Type | Method and Description |
---|---|
void |
display()
Displays the summary count of operations performed,
but only for non-zero counts.
|
void |
display(boolean complete)
Displays the summary count of operations performed,
optionally including zero counts.
|
java.lang.String |
getNameOfOther()
Gets the name of the other operation.
|
long |
getNumberOfAssignments()
Gets the number of assignments counted
|
long |
getNumberOfComparisons()
Gets the number of comparisons counted
|
long |
getNumberOfExchanges()
Gets the number of exchanges counted
|
long |
getNumberOfOther()
Gets the number of other operations counted
|
void |
incrementAssignments()
Adds 1 to the number of assignments.
|
void |
incrementAssignments(long numberOfTimes)
Adds a fixed positive integer amount to the number of
assignments.
|
void |
incrementComparisons()
Adds 1 to the number of comparisons.
|
void |
incrementComparisons(long numberOfTimes)
Adds a fixed positive integer amount to the number of
comparisons.
|
void |
incrementExchanges()
Adds 1 to the number of exchanges.
|
void |
incrementExchanges(long numberOfTimes)
Adds a fixed positive integer amount to the number of exchanges.
|
void |
incrementOther()
Adds 1 to the number of other operations.
|
void |
incrementOther(long numberOfTimes)
Adds a fixed positive integer amount to the number of "other"
operations.
|
static void |
main(java.lang.String[] args) |
void |
reset()
Resets all the counters of this OperationCounter to zero
and the name of the "other" operation to "No Other Op".
|
void |
setNameOfOther(java.lang.String name)
Sets the name of the other operation.
|
public OperationCounter()
public void reset()
public void incrementAssignments()
public void incrementAssignments(long numberOfTimes)
numberOfTimes
- Amount by which to increment the counter
Pre:
self has been declared and numberOfTimes contains a positive integer.
Post:
The number-of-assignments counter has been incremented numberOfTimes times.
public void incrementComparisons()
public void incrementComparisons(long numberOfTimes)
numberOfTimes
- Amount by which to increment the counter
Pre:
self has been declared and numberOfTimes contains a positive integer.
Post:
The number-of-comparisons counter has been incremented numberOfTimes times.
public void incrementExchanges()
public void incrementExchanges(long numberOfTimes)
numberOfTimes
- Amount by which to increment the counter
Pre:
self has been declared and numberOfTimes contains a positive integer.
Post:
The number-of-exchanges counter has been incremented numberOfTimes times.
public void incrementOther()
public void incrementOther(long numberOfTimes)
numberOfTimes
- Amount by which to increment the counter
Pre:
self has been declared and numberOfTimes contains a positive integer.
Post:
The number-of-"other"-operations counter has been incremented numberOfTimes times.
public long getNumberOfComparisons()
public long getNumberOfExchanges()
public long getNumberOfAssignments()
public long getNumberOfOther()
public void setNameOfOther(java.lang.String name)
name
- The name of the other operationpublic java.lang.String getNameOfOther()
public void display()
public void display(boolean complete)
complete
- Whether to include zero counts in the display
Pre:
self has been declared and complete has been initialized.
Post:
The numbers of comparisons, exchanges, assignments and/or the "other" operation (if applicable) recorded by counter are displayed in summary form as follows, provided "complete" is true. If complete is false (the default), only the non-zero counts are displayed. In either case the count for the "other" operation is displayed if the name of the operation is non-empty.
Summary Count of Operations Performed Comparisons = # Exchanges = # Assignments = # NameOfOther = #
If no counts have been recorded and "complete" is false, the following line appears under the summary table title:
No operations of any kind have been counted.
public static void main(java.lang.String[] args)