View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: ModelColumn.java
13   * Created: 2007-12-13
14   * Author: entrop, bmilos
15   * $Id: ModelColumn.java 2361 2009-01-18 20:03:25Z awos $
16   */
17  
18  package pl.edu.agh.cast.model;
19  
20  import java.util.Arrays;
21  
22  /**
23   * The class which represents model column which is chosen in template wizard during column mapping.
24   *
25   * @author AGH CAST Team
26   *
27   */
28  public class ModelColumn {
29  
30      private String id;
31  
32      private String name;
33  
34      private int modelIndex;
35  
36      private String type;
37  
38      private boolean required;
39  
40      private String defaultValue;
41  
42      private ModelColumnParameter[] parameters;
43  
44      /**
45       * Constructor.
46       *
47       * The following fields are read from column element in extension point pl.edu.agh.cast.model
48       *
49       * @param id
50       *            column id
51       * @param name
52       *            column user-friendly name
53       * @param modelIndex
54       *            index in model indicating column meaning
55       * @param type
56       *            defines type of cells in column
57       * @param required
58       *            indicates if column is required - if user has to choose during column mapping
59       * @param defaultValue
60       *            default value for column cells, if column has no default value the parameter is null
61       */
62      public ModelColumn(String id, String name, int modelIndex, String type, boolean required, String defaultValue) {
63          this.id = id;
64          this.name = name;
65          this.modelIndex = modelIndex;
66          this.type = type;
67          this.required = required;
68          this.defaultValue = defaultValue;
69      }
70  
71      /**
72       *
73       * {@inheritDoc}
74       *
75       * @see java.lang.Object#equals(java.lang.Object)
76       */
77      @Override
78      public boolean equals(Object obj) {
79          if (this == obj) { // the same object
80              return true;
81          }
82  
83          if (!(obj instanceof ModelColumn)) {
84              return false;
85          }
86          ModelColumn other = (ModelColumn)obj;
87  
88          if (id == null) {
89              if (other.id != null) {
90                  return false;
91              }
92          } else if (!id.equals(other.id)) {
93              return false;
94          }
95          if (name == null) {
96              if (other.name != null) {
97                  return false;
98              }
99          } else if (!name.equals(other.name)) {
100             return false;
101         }
102         if (modelIndex != other.modelIndex) {
103             return false;
104         }
105         if (type == null) {
106             if (other.type != null) {
107                 return false;
108             }
109         } else if (!type.equals(other.type)) {
110             return false;
111         }
112         if (required != other.required) {
113             return false;
114         }
115         if (defaultValue == null) {
116             if (other.defaultValue != null) {
117                 return false;
118             }
119         } else if (!defaultValue.equals(other.defaultValue)) {
120             return false;
121         }
122         if (!Arrays.equals(parameters, other.parameters)) {
123             return false;
124         }
125 
126         return true;
127     }
128 
129     /**
130      *
131      * {@inheritDoc}
132      *
133      * @see java.lang.Object#hashCode()
134      */
135     @Override
136     public int hashCode() {
137         StringBuilder hash = new StringBuilder();
138         if (id != null) {
139             hash.append(id);
140         }
141         if (name != null) {
142             hash.append(name);
143         }
144         if (modelIndex != -1) {
145             hash.append(modelIndex);
146         }
147         if (type != null) {
148             hash.append(type);
149         }
150         hash.append(required);
151         if (defaultValue != null) {
152             hash.append(defaultValue);
153         }
154         hash.append(Arrays.hashCode(parameters));
155         return hash.toString().hashCode();
156     }
157 
158     public void setParameters(ModelColumnParameter[] newParameters) {
159         parameters = newParameters;
160     }
161 
162     public String getId() {
163         return id;
164     }
165 
166     public String getName() {
167         return name;
168     }
169 
170     public int getModelIndex() {
171         return modelIndex;
172     }
173 
174     public String getType() {
175         return type;
176     }
177 
178     public boolean isRequired() {
179         return required;
180     }
181 
182     public String getDefaultValue() {
183         return defaultValue;
184     }
185 
186     public ModelColumnParameter[] getParameters() {
187         return parameters;
188     }
189 
190 }