View Javadoc

1   /*
2    * Copyright 2004-2010 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  
17  package org.seasar.cubby.action;
18  
19  /**
20   * HTML フォーム中のフィールドを表します。
21   * 
22   * @author baba
23   */
24  public class FieldInfo {
25  
26  	/** フィールド名。 */
27  	private final String name;
28  
29  	/** インデックス。 */
30  	private final Integer index;
31  
32  	/**
33  	 * 指定されたフィールド名のフィールドの情報をインスタンス化します。
34  	 * 
35  	 * @param name
36  	 *            フィールド名
37  	 */
38  	public FieldInfo(final String name) {
39  		this(name, null);
40  	}
41  
42  	/**
43  	 * 指定されたフィールド名とインデックスのフィールドの情報をインスタンス化します。
44  	 * 
45  	 * @param name
46  	 *            フィールド名
47  	 * @param index
48  	 *            インデックス
49  	 */
50  	public FieldInfo(final String name, final Integer index) {
51  		this.name = name;
52  		this.index = index;
53  	}
54  
55  	/**
56  	 * フィールド名を取得します。
57  	 * 
58  	 * @return フィールド名
59  	 */
60  	public String getName() {
61  		return name;
62  	}
63  
64  	/**
65  	 * インデックスを取得します。
66  	 * <p>
67  	 * コンストラクタでインデックスを指定しなかった場合は <code>null</code> を返します。
68  	 * </p>
69  	 * 
70  	 * @return インデックス
71  	 */
72  	public Integer getIndex() {
73  		return index;
74  	}
75  
76  	/**
77  	 * {@inheritDoc}
78  	 */
79  	@Override
80  	public int hashCode() {
81  		final int prime = 31;
82  		int result = 1;
83  		result = prime * result + ((index == null) ? 0 : index.hashCode());
84  		result = prime * result + ((name == null) ? 0 : name.hashCode());
85  		return result;
86  	}
87  
88  	/**
89  	 * {@inheritDoc}
90  	 */
91  	@Override
92  	public boolean equals(final Object obj) {
93  		if (this == obj) {
94  			return true;
95  		}
96  		if (obj == null) {
97  			return false;
98  		}
99  		if (getClass() != obj.getClass()) {
100 			return false;
101 		}
102 		final FieldInfo other = (FieldInfo) obj;
103 		if (index == null) {
104 			if (other.index != null) {
105 				return false;
106 			}
107 		} else if (!index.equals(other.index)) {
108 			return false;
109 		}
110 		if (name == null) {
111 			if (other.name != null) {
112 				return false;
113 			}
114 		} else if (!name.equals(other.name)) {
115 			return false;
116 		}
117 		return true;
118 	}
119 
120 }