View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   package net.kwfgrid.gworkflowdl.structure;
8   
9   import java.util.ArrayList;
10  import java.util.Arrays;
11  
12  /***
13   * implementation class of OperationClass with Java ArrayList.
14   */
15  public final class ArrayListOperationClass extends ArrayListOwls implements OperationClass {
16  
17      private ArrayList<OperationCandidate> operationCandidates;
18      String operationClassName;
19  
20      public ArrayListOperationClass() {
21          super();
22          operationCandidates = (ArrayList<OperationCandidate>) OperationClass.DEFAULT_OPERATIONCANDIDATES;
23          operationClassName = OperationClass.DEFAULT_OPERATIONCLASSNAME;
24      }
25  
26      public int getOperationCount() {
27          if (operationCandidates == null) {
28              return 0;
29          } else {
30              return operationCandidates.size();
31          }
32      }
33  
34      /***
35       * Get the name of this operation class.
36       */
37      public String getName() {
38          return operationClassName;
39      }
40  
41      /***
42       * Set the name of this operation class.
43       */
44      public void setName(String name) {
45          this.operationClassName = name;
46      }
47  
48      /***
49       * Get the candidates of this operation class.
50       */
51      public OperationCandidate[] getOperationCandidates() {
52          if (operationCandidates == null) {
53              return null;
54          } else {
55              final OperationCandidate[] oc = new OperationCandidate[operationCandidates.size()];
56              for (int i = 0; i < oc.length; i++) {
57                  oc[i] = operationCandidates.get(i);
58              }
59              return oc;
60          }
61      }
62  
63      /***
64       * Add an additional concrete operation to the candidates.
65       *
66       * @param operation The concrete operation.
67       */
68      public void addOperationCandidate(OperationCandidate operationCandidate) {
69          if (operationCandidates == null) operationCandidates = new ArrayList<OperationCandidate>();
70          operationCandidates.add(operationCandidate);
71      }
72  
73      /***
74       * Remove the i-th concrete operation candidate from operations list.
75       *
76       * @param i The index of the concrete operation.
77       */
78      public void removeOperationCandidate(int i) {
79          operationCandidates.remove(i);
80          if (operationCandidates.size() == 0) {
81              operationCandidates = null;
82          }
83      }
84  
85      /***
86       * Set the candidates of this operation class.
87       * @param ocs
88       */
89      public void setOperationCandidates(final OperationCandidate[] ocs) {
90          if (ocs == null|| 0 == ocs.length) {
91              operationCandidates = (ArrayList<OperationCandidate>) OperationClass.DEFAULT_OPERATIONCANDIDATES;
92          } else {
93              operationCandidates = new ArrayList<OperationCandidate>();
94              operationCandidates.addAll(Arrays.asList(ocs));
95          }
96      }
97  
98      /***
99       * get abstraction degree of operation.
100      * @return  color
101      */
102     public int getAbstractionLevel() {
103         if (operationCandidates == null) {
104             return Operation.YELLOW;
105         } else {
106             int count = 0;
107             for (OperationCandidate operationCandidate : operationCandidates) {
108                 if (operationCandidate.getAbstractionLevel() == Operation.GREEN) {
109                     count++;
110                 }
111             }
112             return 1 == count ? Operation.GREEN : Operation.BLUE;
113         }
114     }
115 
116 }