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.calcium.skeletons;
00032
00033 import java.util.Vector;
00034
00035 import org.objectweb.proactive.calcium.Task;
00036 import org.objectweb.proactive.calcium.interfaces.Condition;
00037 import org.objectweb.proactive.calcium.interfaces.Instruction;
00038 import org.objectweb.proactive.calcium.interfaces.Skeleton;
00039 import org.objectweb.proactive.calcium.statistics.Timer;
00040
00050 public class If<T> implements Skeleton<T>, Instruction<T> {
00051
00052 Condition<T> cond;
00053 Skeleton<T> ifChild, elseChild;
00054 public If(Condition<T> cond, Skeleton<T> ifChild, Skeleton<T> elseChild){
00055
00056 this.cond=cond;
00057 this.ifChild=ifChild;
00058 this.elseChild=elseChild;
00059 }
00060
00061 public Vector<Instruction<T>> getInstructionStack() {
00062
00063 Vector<Instruction<T>> v = new Vector<Instruction<T>>();
00064 v.add(this);
00065 return v;
00066 }
00067
00068
00069 public Task<T> compute(Task<T> t) throws Exception{
00070
00071 Vector<Instruction<T>> childStack;
00072 Timer timer = new Timer();
00073 boolean evalCondition= cond.evalCondition(t.getObject());
00074 timer.stop();
00075
00076 if(evalCondition){
00077 childStack= ifChild.getInstructionStack();
00078 }
00079 else{
00080 childStack= elseChild.getInstructionStack();
00081 }
00082
00083 Vector<Instruction<T>> taskStack = t.getStack();
00084 taskStack.addAll(childStack);
00085 t.setStack(taskStack);
00086 t.getStats().getWorkout().track(cond, timer);
00087
00088 return t;
00089 }
00090 }