001 /*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016 package org.opengion.hayabusa.report;
017
018 import org.opengion.fukurou.util.LogWriter;
019
020 /**
021 * 雛形EXCELの {@カラãƒ? 解析情報 を管ç�?�™るローカルクラスですã?
022 *
023 * こã?クラスはã€?››形EXCELより取得したã?{@カラãƒ? および、{@カラãƒ?枝番}より
024 * カラãƒ??行番号、å?番号、枝番を取りå?しã?セルと?‘対?‘で管ç�?�™る為のクラスですã?
025 * 枝番が付かなã�?‚«ラãƒ??、ã?ãƒ?ƒ€ーæƒ??になる為、枝番をã??�ï¼?で設定しますã?
026 * シート単位に呼び出すå¿?¦�がありますã?
027 *
028 * ?¢注意:このクラスは、equals とä¸??しなã�??然なé ?º�を持ってã�?�¾すã??£
029 *
030 * @og.group 帳票シスãƒ?ƒ
031 *
032 * @version 4.0
033 * @author Kazuhiko Hasegawa
034 * @since JDK5.0,
035 */
036 public class ExcelLayoutData implements Comparable<ExcelLayoutData> {
037 private final int edbn ;
038 private final String key ;
039 private final String clm ;
040 private final int rowNo ;
041 private final short colNo ;
042
043 private final String uniqKey ;
044 private final int hashcode ;
045
046 /**
047 * コンストラクター
048 *
049 * 雛形EXCELの{@カラãƒ?を含ã‚?‚»ルの値と、行å?番号を設定しますã?
050 * 整合æ?チェãƒ?‚¯の条件は、å?頭ã�?"{@" で、最後がã€?}" で、文字å?の途中にã€?
051 * "{@" が含まれてã�?�ªã�??合ã?みとしますã?
052 *
053 * å†?ƒ¨で、カラãƒ?�¨枝番にåˆ?§£しますã?
054 *
055 * @param inkey 処ç�?‚«ラãƒ?{@カラãƒ?形å¼?
056 * @param rowNo 行番号
057 * @param colNo 列番号
058 */
059 public ExcelLayoutData( final String inkey , final int rowNo ,final short colNo ) {
060 this.key = inkey.trim();
061 this.rowNo = rowNo;
062 this.colNo = colNo;
063
064 if( ! key.startsWith( "{@" ) || !key.endsWith( "}" ) ) {
065 String errMsg = "æŒ?®šã?セルのカラãƒ?®š義が不正ですã?"
066 + "row,col=[" + rowNo + "," + colNo + "] , key=[" + key + "]" ;
067 throw new IllegalArgumentException( errMsg );
068 }
069
070 String tempClm = key.substring( 2,key.length()-1 ); // {@AAA_X} ã‚?AAA_X に変換するã€?
071 int idx = tempClm.lastIndexOf( '_' );
072 int tempEdbn = -1;
073
074 if( idx > 0 ) {
075 try {
076 tempEdbn = Integer.parseInt( tempClm.substring( idx+1 ) );
077 tempClm = tempClm.substring( 0,idx );
078 }
079 catch (NumberFormatException e) { // ヘッãƒ??にアンãƒ??バã?が使用されてã�?‚‹ケース
080 String errMsg2 = "ヘッãƒ??にアンãƒ??バã?が使用されてã�?�¾すã?[" + tempClm + "]" ;
081 LogWriter.log( errMsg2 );
082 }
083 }
084
085 edbn = tempEdbn;
086 clm = tempClm;
087
088 if( edbn < 0 ) {
089 uniqKey = clm + ":[" + rowNo + "," + colNo + "]" ;
090 }
091 else {
092 uniqKey = clm + "_" + edbn + ":[" + rowNo + "," + colNo + "]" ;
093 }
094 hashcode = uniqKey.hashCode() ;
095 }
096
097 /**
098 * å†?ƒ¨コンストラクター
099 *
100 * 雛形EXCELの{@カラãƒ?を含ã‚?‚»ルの値と、行å?番号を設定しますã?
101 * å†?ƒ¨で、カラãƒ?�¨枝番にåˆ?§£しますã?
102 *
103 * @param other ExcelLayoutDataオブジェクãƒ?
104 * @param newRowNo 行番号
105 * @param newEdbn 列番号
106 */
107 private ExcelLayoutData( final ExcelLayoutData other , final int newRowNo, final int newEdbn ) {
108 key = other.key;
109 rowNo = newRowNo;
110 colNo = other.colNo;
111
112 edbn = newEdbn;
113 clm = other.clm;
114
115 if( edbn < 0 ) {
116 uniqKey = clm + ":[" + rowNo + "," + colNo + "]" ;
117 }
118 else {
119 uniqKey = clm + "_" + edbn + ":[" + rowNo + "," + colNo + "]" ;
120 }
121 hashcode = uniqKey.hashCode() ;
122 }
123
124 /**
125 * 枝番を取得しますã?
126 *
127 * @return ハッシュコーãƒ?
128 */
129 public int getEdbn() { return edbn ; }
130
131 /**
132 * カラãƒ?��を取得しますã?
133 *
134 * @return カラãƒ?��
135 */
136 public String getClm() { return clm ; }
137
138 /**
139 * 行番号を取得しますã?
140 *
141 * @return 行番号
142 */
143 public int getRowNo() { return rowNo ; }
144
145 /**
146 * 列番号を取得しますã?
147 *
148 * @return 列番号
149 */
150 public short getColNo() { return colNo ; }
151
152 /**
153 * 登録時ã?オリジナルのキー({@カラãƒ?枝番})を取得しますã?
154 *
155 * @return オリジナルのキー
156 */
157 public String getKey() { return key ; }
158
159 /**
160 * 行番号と枝番が異なる新しい ExcelLayoutData を返しますã?
161 *
162 * @param newRowNo 行番号
163 * @param newEdbn 枝番
164 *
165 * @return 新しいExcelLayoutData
166 */
167 public ExcelLayoutData copy( final int newRowNo, final int newEdbn ) {
168 return new ExcelLayoutData( this,newRowNo,newEdbn );
169 }
170
171 /**
172 * こã?オブジェクトã?ハッシュコードを取得しますã?
173 * å†?ƒ¨æ–?—å?(uniqKey)のハッシュコードと同じ値ですã?
174 *
175 * @return ハッシュコーãƒ?
176 */
177 @Override
178 public int hashCode() { return hashcode ; }
179
180 /**
181 * こã?æ–?—å?とæŒ?®šされたオブジェクトを比è¼?�—ますã?
182 *
183 * 引数ã�?null でなくã?こã?オブジェクトと同じå†?ƒ¨æ–?—å?(uniqKey)を持つ
184 * ExcelLayoutData オブジェクトである場合にã�?�‘、結果は true になりますã?
185 *
186 * @param object 比è¼?�™るオブジェクãƒ?
187 *
188 * @return Objectが等しã�??合ã? true、そã�?�§なã�??合ã? false
189 */
190 @Override
191 public boolean equals( final Object object ) {
192 if( object instanceof ExcelLayoutData ) {
193 return uniqKey.equals( ((ExcelLayoutData)object).uniqKey ) ;
194 }
195 return false ;
196 }
197
198 /**
199 * 自然比è¼?ƒ¡ソãƒ?ƒ‰
200 * インタフェース Comparable の 実è£?�§すã?
201 * edbn 、clm 、rowNo 、colNo のé ?�§比è¼?�—ますã?
202 *
203 * @param other 比è¼?¯¾象のObject
204 *
205 * @return こã?オブジェクトがæŒ?®šされたオブジェクトより小さã�??合ã?è²??整数、等しã�??合ã?ゼロ、大きい場合ã?正の整数
206 */
207 // public int compareTo( final Object object ) {
208 @Override
209 public int compareTo( final ExcelLayoutData other ) {
210 if( uniqKey.equals( other.uniqKey ) ) { return 0; }
211
212 // if( object instanceof ExcelLayoutData ) {
213 // ExcelLayoutData other = (ExcelLayoutData)object ;
214 if( edbn != other.edbn ) { return edbn - other.edbn; }
215 if( ! clm.equals( other.clm ) ) { return clm.compareTo( other.clm ); }
216 if( rowNo != other.rowNo ) { return rowNo - other.rowNo; }
217 return colNo - other.colNo;
218 // }
219 // throw new ClassCastException();
220 }
221
222 /**
223 * こã?クラスのæ–?—å?表現を返しますã?
224 *
225 * å†?ƒ¨æ–?—å?(uniqKey)と同じ値ですã?
226 * ヘッãƒ???šclm + ":[" + rowNo + "," + colNo + "]"
227 * 明細 ?šclm + "_" + edbn + ":[" + rowNo + "," + colNo + "]"
228 *
229 * @return æ–?—å?表現
230 */
231 @Override
232 public String toString() {
233 return uniqKey;
234 }
235 }