View Javadoc
1   package de.fhdw.wtf.walker.tasks.util;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.concurrent.ExecutionException;
6   
7   import de.fhdw.wtf.common.ast.Model;
8   import de.fhdw.wtf.common.task.TaskExecutor;
9   import de.fhdw.wtf.common.task.TaskExecutorFixed;
10  import de.fhdw.wtf.common.task.result.ExceptionalTaskResult;
11  import de.fhdw.wtf.common.task.result.OKTaskResult;
12  import de.fhdw.wtf.common.task.result.TaskResult;
13  import de.fhdw.wtf.common.task.result.visitor.TaskResultVisitor;
14  import de.fhdw.wtf.walker.tasks.TypeReferencer;
15  
16  /**
17   * Contains all values of the execution of referencer: Collection<OKTaskResult> okResult;
18   * Collection<ExceptionalTaskResult> failResult; Collection<TaskResult> results;.
19   */
20  public class TypeReferencerTestReturnValue {
21  	
22  	/**
23  	 * Contains all positive results of task execution.
24  	 */
25  	private final Collection<OKTaskResult> okResult;
26  	
27  	/**
28  	 * Contains all negative results of task execution.
29  	 */
30  	private final Collection<ExceptionalTaskResult> failResult;
31  	
32  	/**
33  	 * The referencer which is executed to get the return values.
34  	 */
35  	private final TypeReferencer referencer;
36  	
37  	/**
38  	 * Constructor. Executes the referencing of the given model.
39  	 * 
40  	 * @param model
41  	 *            - model for type referencing.
42  	 * @throws InterruptedException
43  	 *             - {@link InterruptedException}
44  	 * @throws ExecutionException
45  	 *             - {@link ExecutionException}.
46  	 */
47  	public TypeReferencerTestReturnValue(final Model model) throws InterruptedException, ExecutionException {
48  		
49  		final TaskExecutor taskManager = TaskExecutorFixed.create();
50  		this.referencer = TypeReferencer.create(model, taskManager);
51  		taskManager.startAllKnownTasks();
52  		this.okResult = new ArrayList<>();
53  		this.failResult = new ArrayList<>();
54  		final Collection<TaskResult> results = taskManager.getResultsAndShutdown();
55  		
56  		for (final TaskResult current : results) {
57  			current.accept(new TaskResultVisitor() {
58  				
59  				@Override
60  				public void handleOkTaskResult(final OKTaskResult result) {
61  					TypeReferencerTestReturnValue.this.okResult.add(result);
62  				}
63  				
64  				@Override
65  				public void handleExceptionalTaskResult(final ExceptionalTaskResult result) {
66  					TypeReferencerTestReturnValue.this.failResult.add(result);
67  				}
68  			});
69  		}
70  	}
71  	
72  	/**
73  	 * Returns the collection of positive results of the task execution.
74  	 * 
75  	 * @return Collection of positive results.
76  	 */
77  	public Collection<OKTaskResult> getOkResult() {
78  		return this.okResult;
79  	}
80  	
81  	/**
82  	 * Returns the collection of negative results of the task execution.
83  	 * 
84  	 * @return Collection of negative results.
85  	 */
86  	public Collection<ExceptionalTaskResult> getFailResult() {
87  		return this.failResult;
88  	}
89  	
90  	/**
91  	 * Returns the referencer which is used for referencing the given model.
92  	 * 
93  	 * @return used {@link TypeReferencer}.
94  	 */
95  	public TypeReferencer getTypeReferencer() {
96  		return this.referencer;
97  	}
98  }