View Javadoc

1   /*
2    * Copyright 2004-2009 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  package org.seasar.cubby.action;
17  
18  /**
19   * HTML フォーム中のフィールドを表します。
20   * 
21   * @author baba
22   */
23  public class FieldInfo {
24  
25  	/** フィールド名。 */
26  	private final String name;
27  
28  	/** インデックス。 */
29  	private final Integer index;
30  
31  	/**
32  	 * 指定されたフィールド名のフィールドの情報をインスタンス化します。
33  	 * 
34  	 * @param name
35  	 *            フィールド名
36  	 */
37  	public FieldInfo(final String name) {
38  		this(name, null);
39  	}
40  
41  	/**
42  	 * 指定されたフィールド名とインデックスのフィールドの情報をインスタンス化します。
43  	 * 
44  	 * @param name
45  	 *            フィールド名
46  	 * @param index
47  	 *            インデックス
48  	 */
49  	public FieldInfo(final String name, final Integer index) {
50  		this.name = name;
51  		this.index = index;
52  	}
53  
54  	/**
55  	 * フィールド名を取得します。
56  	 * 
57  	 * @return フィールド名
58  	 */
59  	public String getName() {
60  		return name;
61  	}
62  
63  	/**
64  	 * インデックスを取得します。
65  	 * <p>
66  	 * コンストラクタでインデックスを指定しなかった場合は <code>null</code> を返します。
67  	 * </p>
68  	 * 
69  	 * @return インデックス
70  	 */
71  	public Integer getIndex() {
72  		return index;
73  	}
74  
75  	/**
76  	 * {@inheritDoc}
77  	 */
78  	@Override
79  	public int hashCode() {
80  		final int prime = 31;
81  		int result = 1;
82  		result = prime * result + ((index == null) ? 0 : index.hashCode());
83  		result = prime * result + ((name == null) ? 0 : name.hashCode());
84  		return result;
85  	}
86  
87  	/**
88  	 * {@inheritDoc}
89  	 */
90  	@Override
91  	public boolean equals(final Object obj) {
92  		if (this == obj) {
93  			return true;
94  		}
95  		if (obj == null) {
96  			return false;
97  		}
98  		if (getClass() != obj.getClass()) {
99  			return false;
100 		}
101 		final FieldInfo other = (FieldInfo) obj;
102 		if (index == null) {
103 			if (other.index != null) {
104 				return false;
105 			}
106 		} else if (!index.equals(other.index)) {
107 			return false;
108 		}
109 		if (name == null) {
110 			if (other.name != null) {
111 				return false;
112 			}
113 		} else if (!name.equals(other.name)) {
114 			return false;
115 		}
116 		return true;
117 	}
118 
119 }