00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.branchnbound.core;
00032
00033 import java.io.IOException;
00034 import java.io.ObjectInputStream;
00035 import java.io.ObjectOutputStream;
00036 import java.io.Serializable;
00037
00038 import org.objectweb.proactive.branchnbound.core.exception.NoResultsException;
00039
00040
00048 public class Result implements Serializable {
00049 private Object theSolution = null;
00050 private Exception exception = null;
00051
00055 public Result() {
00056 }
00057
00062 public Result(Object theSolution) {
00063 assert theSolution instanceof Comparable;
00064 this.theSolution = theSolution;
00065 }
00066
00072 public Result(Exception e) {
00073 this.exception = e;
00074 }
00075
00080 public Object getSolution() {
00081 return this.theSolution;
00082 }
00083
00087 public Exception getException() {
00088 return this.exception;
00089 }
00090
00095 public void setSolution(Object theSolution) {
00096 assert theSolution instanceof Comparable;
00097 this.theSolution = theSolution;
00098 }
00099
00106 public Result returnTheBest(Result other) {
00107 if (((Comparable) this.theSolution).compareTo(other.getSolution()) <= 0) {
00108 return this;
00109 }
00110 return other;
00111 }
00112
00116 public String toString() {
00117 return this.theSolution.toString();
00118 }
00119
00125 public boolean isBetterThan(Result other) {
00126 if (((Comparable) this.theSolution).compareTo(other.theSolution) < 0) {
00127 return true;
00128 }
00129 return false;
00130 }
00131
00135 public boolean isAnException() {
00136 return this.exception != null;
00137 }
00138
00139
00140 private static final String NORESULT = "--No result--";
00141
00142 private void writeObject(ObjectOutputStream out) throws IOException {
00143 if (this.theSolution instanceof NoResultsException) {
00144 out.write(NORESULT.getBytes());
00145 } else {
00146 out.writeObject(this.theSolution);
00147 }
00148 }
00149
00150 private void readObject(ObjectInputStream in)
00151 throws IOException, ClassNotFoundException {
00152 Object readObject = in.readObject();
00153 if (readObject instanceof String &&
00154 (((String) readObject).compareTo(NORESULT) == 0)) {
00155 this.theSolution = new NoResultsException();
00156 } else {
00157 this.theSolution = readObject;
00158 }
00159 }
00160 }