View Javadoc

1   package cz.cuni.amis.pogamut.sposh.elements;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * This is a factory class that can be used to create various elements.
8    *
9    * @author HonzaH
10   */
11  public class LapElementsFactory {
12  
13      /**
14       * Name of action that will be used unless user specifies a name of action
15       * that should be used.
16       */
17      public static String DEFAULT_ACTION = "doNothing";
18      /**
19       * Name of trigger that will be used unless user specifies some other
20       * trigger in the arguments.
21       */
22      public static String DEFAULT_TRIGGER_SENSE = "succeed";
23  
24      /**
25       * Create a new competence with multiple choices. The choices have default
26       * action and trigger.
27       *
28       * @param name name of new competence
29       * @param choices unique sequence of choices for this competence
30       * @return created competence
31       */
32      public static Competence createCompetence(String name, String... choices) {
33          List<CompetenceElement> elements = new ArrayList<CompetenceElement>(choices.length);
34  
35          for (String choice : choices) {
36              elements.add(new CompetenceElement(choice, new Sense(DEFAULT_TRIGGER_SENSE), DEFAULT_ACTION, null));
37          }
38  
39          return new Competence(name, new FormalParameters(), elements);
40      }
41  
42      /**
43       * Create new drive with default trigger and action.
44       *
45       * @param driveName name of the drive
46       */
47      public static DriveElement createDriveElement(String driveName) {
48          return new DriveElement(driveName, new Triggers(new Sense(DEFAULT_TRIGGER_SENSE)), DEFAULT_ACTION, null);
49      }
50  
51      /**
52       * Create new drive with specified name and empty list of triggers and
53       * default action.
54       *
55       * @param name name of created drive element
56       */
57      public static DriveElement createDriveElementNoTriggers(String name) {
58          return new DriveElement(name, new Triggers(), DEFAULT_ACTION, null);
59      }
60  
61      /**
62       * Create new competence element with trigger of deafult sense and default action.
63       * @param name name of competence element
64       * @return created element
65       */
66      public static CompetenceElement createCompetenceElement(String name) {
67          return new CompetenceElement(name, new Sense(DEFAULT_TRIGGER_SENSE), DEFAULT_ACTION, null);
68      }
69  
70      /**
71       * Create new sense.
72       * @param name name of the sense
73       * @return created sense
74       */
75      public static Sense createSense(String name) {
76          return new Sense(name);
77      }
78  }