View Javadoc

1   package org.apache.torque.generator.configuration.mergepoint;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.torque.generator.control.action.MergepointAction;
26  
27  /**
28   * A mapping between the name of an mergepoint and and the action which should
29   * be performed at this point.
30   */
31  public class MergepointMapping
32  {
33      /**
34       * The name of the mergepoint.
35       */
36      private String name;
37  
38      /**
39       * The list of actions whichare executed at the mergepoint.
40       */
41      private List<MergepointAction> actions = new ArrayList<MergepointAction>();
42  
43      /**
44       * Constructor.
45       *
46       * @param name the name of the mergepoint, not null.
47       *
48       * @throws IllegalArgumentException if name is null.
49       */
50      public MergepointMapping(String name)
51      {
52          if (name == null)
53          {
54              throw new IllegalArgumentException("name must not be null");
55          }
56          this.name = name;
57      }
58  
59      /**
60       * Constructor.
61       *
62       * @param name the name of the mergepoint, not null.
63       * @param actions the actions in this mergepoint.
64       *
65       * @throws IllegalArgumentException if name is null.
66       */
67      public MergepointMapping(String name, List<MergepointAction> actions)
68      {
69          this(name);
70          this.actions.addAll(actions);
71      }
72  
73      /**
74       * Returns the name of the mergepoint.
75       *
76       * @return the name of the mergepoint, not null.
77       */
78      public String getName()
79      {
80          return name;
81      }
82  
83      /**
84       * Returns the list of actions executed at the mergepoint.
85       *
86       * @return the list of actions. Not null, may be empty.
87       */
88      public List<MergepointAction> getActions()
89      {
90          return actions;
91      }
92  
93      /**
94       * Adds an action to this mergepont mapping at the end of the action list.
95       *
96       * @param action the action to add, not null.
97       *
98       * @throws NullPointerException if action is null.
99       */
100     public void addAction(MergepointAction action)
101     {
102         if (action == null)
103         {
104             throw new NullPointerException("action is null");
105         }
106         this.actions.add(action);
107     }
108 
109     @Override
110     public String toString()
111     {
112         StringBuffer result = new StringBuffer();
113         result.append("(name=").append(name)
114                 .append(",actions=").append(actions)
115                 .append(")");
116         return result.toString();
117     }
118 
119     @Override
120     public int hashCode()
121     {
122         final int prime = 31;
123         int result = 1;
124         result = prime * result + ((actions == null) ? 0 : actions.hashCode());
125         result = prime * result + ((name == null) ? 0 : name.hashCode());
126         return result;
127     }
128 
129     @Override
130     public boolean equals(Object obj)
131     {
132         if (this == obj)
133         {
134             return true;
135         }
136         if (obj == null)
137         {
138             return false;
139         }
140         if (getClass() != obj.getClass())
141         {
142             return false;
143         }
144         final MergepointMapping other = (MergepointMapping) obj;
145         if (actions == null)
146         {
147             if (other.actions != null)
148             {
149                 return false;
150             }
151         }
152         else if (!actions.equals(other.actions))
153         {
154             return false;
155         }
156         if (name == null)
157         {
158             if (other.name != null)
159             {
160                 return false;
161             }
162         }
163         else if (!name.equals(other.name))
164         {
165             return false;
166         }
167         return true;
168     }
169 }