|
@@ -25,7 +25,8 @@ import org.apache.hadoop.examples.pi.math.Summation;
|
|
import org.apache.hadoop.io.Writable;
|
|
import org.apache.hadoop.io.Writable;
|
|
|
|
|
|
/** A class for map task results or reduce task results. */
|
|
/** A class for map task results or reduce task results. */
|
|
-public class TaskResult implements Container<Summation>, Combinable<TaskResult>, Writable {
|
|
|
|
|
|
+public class TaskResult implements Container<Summation>,
|
|
|
|
+ Combinable<TaskResult>, Writable {
|
|
private Summation sigma;
|
|
private Summation sigma;
|
|
private long duration;
|
|
private long duration;
|
|
|
|
|
|
@@ -38,10 +39,14 @@ public class TaskResult implements Container<Summation>, Combinable<TaskResult>,
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
@Override
|
|
- public Summation getElement() {return sigma;}
|
|
|
|
|
|
+ public Summation getElement() {
|
|
|
|
+ return sigma;
|
|
|
|
+ }
|
|
|
|
|
|
/** @return The time duration used */
|
|
/** @return The time duration used */
|
|
- long getDuration() {return duration;}
|
|
|
|
|
|
+ long getDuration() {
|
|
|
|
+ return duration;
|
|
|
|
+ }
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
@Override
|
|
@@ -54,7 +59,7 @@ public class TaskResult implements Container<Summation>, Combinable<TaskResult>,
|
|
public boolean equals(Object obj) {
|
|
public boolean equals(Object obj) {
|
|
if (this == obj)
|
|
if (this == obj)
|
|
return true;
|
|
return true;
|
|
- else if (obj != null && obj instanceof TaskResult) {
|
|
|
|
|
|
+ else if (obj instanceof TaskResult) {
|
|
final TaskResult that = (TaskResult)obj;
|
|
final TaskResult that = (TaskResult)obj;
|
|
return this.compareTo(that) == 0;
|
|
return this.compareTo(that) == 0;
|
|
}
|
|
}
|
|
@@ -62,7 +67,7 @@ public class TaskResult implements Container<Summation>, Combinable<TaskResult>,
|
|
"obj.getClass()=" + obj.getClass());
|
|
"obj.getClass()=" + obj.getClass());
|
|
}
|
|
}
|
|
|
|
|
|
- /** Not supported */
|
|
|
|
|
|
+ /** Not supported. */
|
|
@Override
|
|
@Override
|
|
public int hashCode() {
|
|
public int hashCode() {
|
|
throw new UnsupportedOperationException();
|
|
throw new UnsupportedOperationException();
|
|
@@ -72,7 +77,7 @@ public class TaskResult implements Container<Summation>, Combinable<TaskResult>,
|
|
@Override
|
|
@Override
|
|
public TaskResult combine(TaskResult that) {
|
|
public TaskResult combine(TaskResult that) {
|
|
final Summation s = sigma.combine(that.sigma);
|
|
final Summation s = sigma.combine(that.sigma);
|
|
- return s == null? null: new TaskResult(s, this.duration + that.duration);
|
|
|
|
|
|
+ return s == null ? null : new TaskResult(s, this.duration + that.duration);
|
|
}
|
|
}
|
|
|
|
|
|
/** {@inheritDoc} */
|
|
/** {@inheritDoc} */
|
|
@@ -92,22 +97,27 @@ public class TaskResult implements Container<Summation>, Combinable<TaskResult>,
|
|
/** {@inheritDoc} */
|
|
/** {@inheritDoc} */
|
|
@Override
|
|
@Override
|
|
public String toString() {
|
|
public String toString() {
|
|
- return "sigma=" + sigma + ", duration=" + duration + "(" + Util.millis2String(duration) + ")";
|
|
|
|
|
|
+ return "sigma=" + sigma + ", duration=" + duration + "(" +
|
|
|
|
+ Util.millis2String(duration) + ")";
|
|
}
|
|
}
|
|
|
|
|
|
- /** Covert a String to a TaskResult */
|
|
|
|
|
|
+ /** Covert a String to a TaskResult. */
|
|
public static TaskResult valueOf(String s) {
|
|
public static TaskResult valueOf(String s) {
|
|
int i = 0;
|
|
int i = 0;
|
|
int j = s.indexOf(", duration=");
|
|
int j = s.indexOf(", duration=");
|
|
if (j < 0)
|
|
if (j < 0)
|
|
- throw new IllegalArgumentException("i=" + i + ", j=" + j + " < 0, s=" + s);
|
|
|
|
- final Summation sigma = Summation.valueOf(Util.parseStringVariable("sigma", s.substring(i, j)));
|
|
|
|
|
|
+ throw new IllegalArgumentException("i=" + i + ", j=" + j +
|
|
|
|
+ " < 0, s=" + s);
|
|
|
|
+ final Summation sigma =
|
|
|
|
+ Summation.valueOf(Util.parseStringVariable("sigma", s.substring(i, j)));
|
|
|
|
|
|
i = j + 2;
|
|
i = j + 2;
|
|
j = s.indexOf("(", i);
|
|
j = s.indexOf("(", i);
|
|
if (j < 0)
|
|
if (j < 0)
|
|
- throw new IllegalArgumentException("i=" + i + ", j=" + j + " < 0, s=" + s);
|
|
|
|
- final long duration = Util.parseLongVariable("duration", s.substring(i, j));
|
|
|
|
|
|
+ throw new IllegalArgumentException("i=" + i + ", j=" + j +
|
|
|
|
+ " < 0, s=" + s);
|
|
|
|
+ final long duration =
|
|
|
|
+ Util.parseLongVariable("duration", s.substring(i, j));
|
|
|
|
|
|
return new TaskResult(sigma, duration);
|
|
return new TaskResult(sigma, duration);
|
|
}
|
|
}
|