001 /**
002 *
003 */
004 package edu.wwu.tobikley.acgc.algorithms;
005
006 import java.math.BigInteger;
007
008 /**
009 * Encapsulates the result of one iteration of a call of
010 * <code>CountingAlgorithm.algorithm()</code>.
011 * The following three pieces of information are included:
012 *
013 * <ul>
014 * <li>The type of the result (either "Overall" or "i. Iteration",
015 * <li>the result of the algorithm itself, and
016 * <li>the runtime it took the algorithm to compute the result.
017 * </ul>
018 *
019 * <code>CountingResult</code>s are sorted by the result value.
020 *
021 * @version 1.0
022 * @author Tobias Kley
023 */
024 public class CountingResult implements Comparable{
025
026 /** The type of the result. Allowed are either "Overall" or "i. Iteration". */
027 private String type = null;
028
029 /** The result itself. */
030 private BigInteger result = null;
031
032 /** The runtime it took the algorithm to compute the result. */
033 private long runTime = 0;
034
035 /**
036 * Creates a new instance of a counting result.
037 *
038 * @param type The type of the result.
039 * @param result he result itself.
040 * @param runTime The runtime it took the algorithm to compute the result.
041 */
042 public CountingResult(String type, BigInteger result, long runTime) {
043 this.type = type;
044 this.result = result;
045 this.runTime = runTime;
046 }
047
048 /**
049 * @return the type
050 */
051 public String getType() {
052 return type;
053 }
054
055 /**
056 * @return the result
057 */
058 public BigInteger getResult() {
059 return result;
060 }
061
062 /**
063 * @return the runTime
064 */
065 public long getRunTime() {
066 return runTime;
067 }
068
069 /**
070 * Returns <code>[type]</code>: <code>[result]</code> in <code>[runTime]</code>.
071 * @return String representation of the above form.
072 */
073 public String toString() {
074 return getType() + ": " + getResult() + " in " + getRunTime();
075 }
076 /**
077 * CountingResults are compared by the value of their <code>result</code>.
078 */
079 public int compareTo(Object o) {
080 CountingResult otherElement = (CountingResult) o;
081 return this.result.compareTo(otherElement.getResult());
082 }
083 }