It's a pretty good Cobol editor.
Total Pageviews
2011/06/30
2011/06/28
Utilize Maven 2 JasperReports Plugin to Compile jrxml Automatically
Motivation
We would like to compile jrxml automatically as we build our web application.
We would like to compile jrxml automatically as we build our web application.
Mechanics
We use Maven 2 JasperReports Plugin to compiles JasperReports xml design files to Java source and .jasper serialized files.
We use Maven 2 JasperReports Plugin to compiles JasperReports xml design files to Java source and .jasper serialized files.
How to do it
1. edit nig-web/pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <dependencies> <dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>4.0.1</version> </dependency> </dependencies> <build> ... <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jasperreports-maven-plugin</artifactId> <version>1.0-beta-2</version> <executions> <execution> <goals> <goal>compile-reports</goal> </goals> <configuration> <!-- define where is your jrxml file --> <sourceDirectory>src\\main\\java\\gov\\fdc\\nig\\report\\templates</sourceDirectory> <sourceFileExt>.jrxml</sourceFileExt> <compiler>net.sf.jasperreports.compilers.JRGroovyCompiler</compiler> <!-- define where is the jasper file will be generated --> <outputDirectory>src\\main\\resources\\report\\jasper</outputDirectory> </configuration> </execution> </executions> <dependencies> <!--note this must be repeated here to pick up correct xml validation --> <dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>4.0.1</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>1.7.5</version> </dependency> </dependencies> </plugin> </plugins> </build> |
2. mvn install
3. check result
Benefits
1. Automate jrxml compilation process
2. We won't forget to compile jrxml file and lead to our program read old jasper file
Labels:
JasperReport,
Maven
2011/06/22
Refactoring: Decompose Conditional
Motivation
if-else條件判斷式,一直是程式看起來很複雜的地方。當功能更複雜,條件式就會更多,判斷式就會顯得又臭又長。無論是程式的可讀性,或是可維護性,都大大的降低。另外,在測試的時候(如code coverage test),也會增加測試時間。
Before Refactor
從上述code snippet可以看出有三段判斷式
為了讓if-else邏輯判斷增加可讀性,分別將此三的判斷式抽離成三個private method,並賦予有意義的名字,此三個method分別為:
if-else條件判斷式,一直是程式看起來很複雜的地方。當功能更複雜,條件式就會更多,判斷式就會顯得又臭又長。無論是程式的可讀性,或是可維護性,都大大的降低。另外,在測試的時候(如code coverage test),也會增加測試時間。
Mechanics
- 將condition 的部份extract到獨立的method.
- 將if-else的部份,extract到獨立的method.
Example
public List doPrint(String evdcCdStart, String evdcCdEnd) throws FDCDataAccessException {
List params = new ArrayList();
StringBuffer sql = new StringBuffer();
sql.append(" SELECT EVADE_CD, EVADE_NM FROM Nigt042 ");
String where = " WHERE ", and = " ";
if(StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd)){
sql.append(where).append(and).append(" EVADE_CD between ?1 and ?2 ");
params.add(evdcCdStart);
params.add(evdcCdEnd);
where = " ";
and = " AND ";
}else if(StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isEmpty(evdcCdEnd)){
sql.append(where).append(and).append(" EVADE_CD >= ?1 ");
params.add(evdcCdStart);
where = " ";
and = " AND ";
}else if(StringUtils.isEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd)){
sql.append(where).append(and).append(" EVADE_CD <= ?1 ");
params.add(evdcCdEnd);
where = " ";
and = " AND ";
}
sql.append(" ORDER BY EVADE_CD ");
return Nigt042Dao.queryNativeSQL(new Nigt042(), sql.toString(), params.toArray());
}
判斷式1: StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd)
判斷式2: StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isEmpty(evdcCdEnd)
判斷式3: StringUtils.isEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd)
before extract | after extract |
StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd) | hasStartAndEndCode |
StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isEmpty(evdcCdEnd) | onlyHasStartCode |
StringUtils.isEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd) | onlyHasEndCode |
After Refactor
public List doPrint(String evdcCdStart, String evdcCdEnd) throws FDCDataAccessException {
List params = new ArrayList();
StringBuffer sql = new StringBuffer();
sql.append(" SELECT EVDC_CD, EVDC_NM FROM NIGT042 ");
String where = " WHERE ", and = " ";
if(hasStartAndEndCode(evdcCdStart, evdcCdEnd)){
sql.append(where).append(and).append(" EVDC_CD between ?1 and ?2 ");
params.add(evdcCdStart);
params.add(evdcCdEnd);
where = " ";
and = " AND ";
}else if(onlyHasStartCode(evdcCdStart, evdcCdEnd)){
sql.append(where).append(and).append(" EVDC_CD >= ?1 ");
params.add(evdcCdStart);
where = " ";
and = " AND ";
}else if(onlyHasEndCode(evdcCdStart, evdcCdEnd)){
sql.append(where).append(and).append(" EVDC_CD <= ?1 ");
params.add(evdcCdEnd);
where = " ";
and = " AND ";
}
sql.append(" ORDER BY EVDC_CD ");
return nigt042Dao.queryNativeSQL(new Nigt042(), sql.toString(), params.toArray());
}
private boolean onlyHasEndCode(String evdcCdStart, String evdcCdEnd) {
return StringUtils.isEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd);
}
private boolean onlyHasStartCode(String evdcCdStart, String evdcCdEnd) {
return StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isEmpty(evdcCdEnd);
}
private boolean hasStartAndEndCode(String evdcCdStart, String evdcCdEnd) {
return StringUtils.isNotEmpty(evdcCdStart) && StringUtils.isNotEmpty(evdcCdEnd);
}
Labels:
Programming
2011/06/20
[Java] VarArgs 的應用
Varargs
varargs是JDK 1.5開始才提供的新功能,其定義如下:The varargs, or variable arguments, feature allows a developer to declare that a method can take a variable number of parameters for a given argument. The vararg must be the last argument in the formal argument list.
白話一點來說,varargs就是用來處理輸入參數數量無法預知的情形,以下是一個簡單的範例。
Scenario
為了因應客戶需求,將前端的刪除功能從單筆變成多筆,此時要從前端傳多筆資料的primary key給controller來進行資料刪除。
Class Diagram
由於多筆刪除是統一的作法,且每一個Controller都會繼承Abstract Controller,於是就把getPKList定義於AbstractController中,這樣每個controller都可以直接取用,如下圖:
Sequence Diagram
從Sequence diagram可以看出,當使用者選擇某幾筆資料,然後按下刪除按鈕,Controller會呼叫getPKList來取得從前端回傳回來的primary key,當接收到以後,再呼叫doDelete來刪除資料。
Sample Code
從以下的code snippet可以看出,getPKList有帶兩個參數,第二個參數就是varargs,由於每張table擁有的primary key的數量不一,有可能一個或一個以上,如NIGT036只有一個primary key, NIGT001則有四個
NIGT036
NIGT001
透過varargs,就可以一個method 滿足所有controller 的需求
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Get primary key list * * @param delArray delete array * @param keys primary keys * @return List of String */ public List getPKList(final String delArray, final String...keys) { List arr = JSONArray.fromObject(delArray); List pkList = new ArrayList(); for (Map map : arr) { //若有多個keys,就add多個primary key到pkLisk;若只有一個primary key,則只做一次 for(String str : keys){ pkList.add(map.get(str)); } } return pkList; } |
2011/06/15
net.sf.jasperreports.engine.JRException: Provider com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl not found
Problem
As I use iReport 4.0.2 to open jrxml file, but it show this error message:
1 2 3 4 5 6 7 8 9 10 11 12 | javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.SAXParserFactoryImpl not found at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:134) at org.netbeans.lib.uihandler.LogRecords.scan(LogRecords.java:127) at org.netbeans.modules.uihandler.Installer.getLogs(Installer.java:681) at org.netbeans.modules.uihandler.Installer$Submit.(Installer.java:1317) at org.netbeans.modules.uihandler.Installer$SubmitInteractive.(Installer.java:1771) at org.netbeans.modules.uihandler.Installer.doDisplaySummary(Installer.java:983) at org.netbeans.modules.uihandler.Installer.displaySummary(Installer.java:912) at org.netbeans.modules.uihandler.Installer.displaySummary(Installer.java:920) at org.netbeans.modules.uihandler.UIHandler.run(UIHandler.java:140) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:573) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1005) |
Solution
Change your JAVA_HOME to standard JDK instead of IBM JDK.
WHAT THE HELL!
Labels:
JasperReport
2011/06/14
ReportWrapper Class for JasperReport Implementation
在JasperReport開發,主要會分成五個部分:
- Get data source: 傳入List of value object,並建立JRBeanCollectionDataSource
- Read Jasper File: 讀取.jasper file
- Generate JasperPrint: 讀取report input stream並建立JasperPrint物件
- Set response content type and header: 根據user要輸出的格式,指定content type and header
- Export Report: 根據user要輸出的格式,用相對應的API進行報表輸出
其實每份報表都不外乎這五大步驟,這邊我建立一個ReportWrapper class,如下
package gov.fdc.nig.report;
import gov.fdc.nig.enumeration.ExportFormatEnum;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRCsvExporter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
/**
* Report Wrapper Class
*
* @author albert
*
*/
public class ReportWrapper {
private transient JRDataSource dataSource;
private final static String JASPER_CLASSPATH = "..\\..\\..\\..\\report\\templates\\";
private transient InputStream reportStream;
private transient JasperPrint print;
/**
* Set report data source
*
* @param data
* List of value object
*/
private void setDataSource(final List data) {
dataSource = new JRBeanCollectionDataSource(data);
}
/**
* Get report input stream
*/
private void getReportInputStream(final String fileName) {
reportStream = getClass().getResourceAsStream(
JASPER_CLASSPATH.concat(fileName.concat(".jasper")));
}
/**
* generate JasperPrint
*
* @param params parameters
* @throws JRException
*/
public void generateJasperPrint(final Map params)
throws JRException {
final JasperReport report = (JasperReport) JRLoader
.loadObject(reportStream);
print = JasperFillManager.fillReport(report, params, dataSource);
}
/**
* Set content type and header
*
* @param fileName is File name
* @param response is HttpServletResponse
* @param exportEnum is ExportFormatEnum
*/
public void setResponse(final String fileName,
final HttpServletResponse response,
final ExportFormatEnum exportEnum) {
response.setCharacterEncoding("UTF-8");
if ("pdf".equals(exportEnum.getValue())) {
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment;filename=\""
.concat(fileName).concat(".pdf\""));
} else if ("csv".equals(exportEnum.getValue())) {
response.setContentType("application/octet-stream;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="
.concat(fileName).concat(".csv"));
}
}
/**
* Export report
*
* @param exportEnum is ExportFormatEnum
* @param outputStream is OutputStream
* @throws JRException
* @throws IOException
*/
public void exportReport(final ExportFormatEnum exportEnum,
final OutputStream outputStream) throws JRException, IOException {
if ("pdf".equals(exportEnum.getValue())) {
final JRExporter pdfExporter = new JRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
pdfExporter.exportReport();
} else if ("csv".equals(exportEnum.getValue())) {
// byte-order marker (BOM)
final byte bomByteArr[] = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
// insert BOM byte array into outputStream
outputStream.write(bomByteArr);
final JRExporter csvExporter = new JRCsvExporter();
csvExporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
csvExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
csvExporter.exportReport();
}
outputStream.flush();
}
/**
* do export report based on the parameters
*
* @param data is List of VO
* @param fileName is file name
* @param params is parameters
* @param response is HttpServletResponse
* @param exportEnum is ExportFormatEnum
* @param outputStream is OutputStream
* @throws JRException
* @throws IOException
*/
public void execute(final List data, final String fileName,
final Map params,
final HttpServletResponse response,
final ExportFormatEnum exportEnum, final OutputStream outputStream)
throws JRException, IOException {
setDataSource(data);
getReportInputStream(fileName);
generateJasperPrint(params);
setResponse(fileName, response, exportEnum);
exportReport(exportEnum, outputStream);
if (reportStream != null) {
reportStream.close();
}
}
}
未來我們在Contoller的processF7Key,只要建立ReportWrapper class,並將相對應的參數給execute method即可,請參考底下的程式片段
/**
* Will be executed as user click Print button
*
* @param formBean
* NIG135DataBean
* @param session
* NIG135DataBean
* @return JSONObject
* @throws IllegalAccessException
* @throws InvocationTargetException
* @throws IOException
*/
private @ResponseBody
void processF7Key(final NIG135DataBean formBean,
final HttpServletResponse response, final HttpSession session)
throws IllegalAccessException, InvocationTargetException,
IOException {
String jasperXMLFileName = "NIG135P1";
OutputStream outputStream = response.getOutputStream();
try {
if ("135".equals(formBean.getReportOption())) {
Map params = new HashMap();
params.put("rejectPeriod", formBean.doPrintForNIG135P1(covertToNIG135P1ReportBean(formBean));
if ("1".equals(formBean.getReportType())) {
// export csv file
if (ExportFormatEnum.CSV.getValue().equals(
formBean.getExportFormat())) {
new ReportWrapper().execute(data,
jasperXMLFileName, params, response,
ExportFormatEnum.CSV, outputStream);
}
// export pdf file
else if (ExportFormatEnum.PDF.getValue().equals(
formBean.getExportFormat())) {
new ReportWrapper().execute(data,
jasperXMLFileName, params, response,
ExportFormatEnum.PDF, outputStream);
}
}
}
}catch(Exception e){
//............
}
}
nig.nig135w.js
function nig135wFormF7(){
$("#fn").val("7");
$("#nig135wForm").attr("target", "_self");
$("#nig135wForm").attr("action", "/nig/front/NIG135W");
$("#nig135wForm").submit();
}
Benefits
所有的報表程式,都透過這一支ReportWrapper class來處理。
我們只要專注於前端的business logic以及templates,後端如何去產生pdf, csv等格式,就交給ReportWrapper 處理就好。
Labels:
JasperReport
How to Access .jasper file from EAR File
Problem
根據標準組所提供的讀取.jasper的方式,是將.jasper的目錄寫死,此寫法未來會有很大的問題。如:
1. 若有多位開發人員同時進行開發,大家都存放於不同的地方,會導致某人的環境可以執行,其他人卻無法執行的狀況。
2. 若開發機、測試機、正式機所放置的目錄不一樣,這樣deploy到不同的機器,又忘記手動去更改目錄,會導致在測試機可以執行,正式機卻無法執行的窘境。
為了改善上述的潛在問題,以下是解決方式:
File Structure
My ReportWrapper class is under gov.fdc.nig.report
.japser files are under resources/report
After we build our application to ear file, the file structure looks like this:
Source Code
1 2 3 4 5 | private final static String JASPER_CLASSPATH = "..\\..\\..\\..\\report\\templates\\"; InputStream reportStream = getClass().getResourceAsStream(JASPER_CLASSPATH.concat(fileName.concat(".jasper"))); JasperReport report = (JasperReport) JRLoader.loadObject(reportStream); |
Benefit
透過上述的寫法,採相對路徑的方式來讀取.jasper file,避免上述的問題
Labels:
JasperReport
2011/06/11
Apply Template Method Pattern in Report Implementation
View more presentations from Guo Albert
Labels:
Design Pattern
2011/06/10
How to Write CSV Files as UTF-8 for Excel
Problem
As JasperReport export CSV file with UTF-8 encoding, Microsoft Excel wasn't displaying a CSV (comma separated values) file correctly.
The screenshot is as bellows:
But it can display correctly for notepad:
Root Cause
In the absence of any charset identification, Excel must guess about a file's content encoding. Therefore, Excel uses that default to read and display CSV files.
Solution
Use the byte-order marker (BOM) to identify the CSV file as a Unicode file. So I write an byte array into OutputStream, then Excel should uses UTF-8 read and display CSV files.
1 2 3 4 5 6 7 8 9 10 | //byte-order marker (BOM) byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF}; //insert BOM byte array into outputStream outputStream.write(b); JRExporter csvExporter = new JRCsvExporter(); csvExporter.setParameter(JRExporterParameter.JASPER_PRINT, print); csvExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream); csvExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, reportName.concat(".csv")); csvExporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); csvExporter.exportReport(); |
Labels:
JasperReport
利用Commons Lang API 來提升Code Coverage
Problem
目前參與的專案,對於code coverage有相當嚴苛的規定(at least 80%),在進行測試的時候,發現由Eclipse產生的equals()與hashCode()此二method是無法提升到80%以上的主因,因為裡頭太多的if-else statement,如下:
Solution
Benefits
目前參與的專案,對於code coverage有相當嚴苛的規定(at least 80%),在進行測試的時候,發現由Eclipse產生的equals()與hashCode()此二method是無法提升到80%以上的主因,因為裡頭太多的if-else statement,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 | @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((acsNo == null) ? 0 : acsNo.hashCode()); result = prime * result + ((addrHsnNm == null) ? 0 : addrHsnNm.hashCode()); result = prime * result + ((addrLin == null) ? 0 : addrLin.hashCode()); result = prime * result + ((addrMk == null) ? 0 : addrMk.hashCode()); result = prime * result + ((addrRoadNo == null) ? 0 : addrRoadNo.hashCode()); result = prime * result + ((addrTownNm == null) ? 0 : addrTownNm.hashCode()); result = prime * result + ((addrVillNm == null) ? 0 : addrVillNm.hashCode()); result = prime * result + ((admRmdDate == null) ? 0 : admRmdDate.hashCode()); result = prime * result + ((admRmdStus == null) ? 0 : admRmdStus.hashCode()); result = prime * result + ((adtSgstMk == null) ? 0 : adtSgstMk.hashCode()); result = prime * result + ((adtrAplTp == null) ? 0 : adtrAplTp.hashCode()); result = prime * result + ((adtrFnshDate == null) ? 0 : adtrFnshDate.hashCode()); result = prime * result + ((aplLimitYm == null) ? 0 : aplLimitYm.hashCode()); result = prime * result + ((arrgMtgTp == null) ? 0 : arrgMtgTp.hashCode()); result = prime * result + ((asgKey == null) ? 0 : asgKey.hashCode()); result = prime * result + ((asgMk == null) ? 0 : asgMk.hashCode()); result = prime * result + ((asst1 == null) ? 0 : asst1.hashCode()); result = prime * result + ((asst2 == null) ? 0 : asst2.hashCode()); result = prime * result + ((asst3 == null) ? 0 : asst3.hashCode()); result = prime * result + ((asstCdcChar1 == null) ? 0 : asstCdcChar1.hashCode()); result = prime * result + ((asstCdcChar2 == null) ? 0 : asstCdcChar2.hashCode()); result = prime * result + ((asstCdcChar3 == null) ? 0 : asstCdcChar3.hashCode()); result = prime * result + ((asstCdcDate1 == null) ? 0 : asstCdcDate1.hashCode()); result = prime * result + ((asstCdcDate2 == null) ? 0 : asstCdcDate2.hashCode()); result = prime * result + ((asstCdcDate3 == null) ? 0 : asstCdcDate3.hashCode()); result = prime * result + ((asstCdcNo1 == null) ? 0 : asstCdcNo1.hashCode()); result = prime * result + ((asstCdcNo2 == null) ? 0 : asstCdcNo2.hashCode()); result = prime * result + ((asstCdcNo3 == null) ? 0 : asstCdcNo3.hashCode()); result = prime * result + ((asstTp == null) ? 0 : asstTp.hashCode()); result = prime * result + ((authMk == null) ? 0 : authMk.hashCode()); result = prime * result + ((baTaxKey == null) ? 0 : baTaxKey.hashCode()); result = prime * result + ((baTaxMk == null) ? 0 : baTaxMk.hashCode()); result = prime * result + ((ban == null) ? 0 : ban.hashCode()); result = prime * result + ((behAmt == null) ? 0 : behAmt.hashCode()); result = prime * result + ((bhvAmt == null) ? 0 : bhvAmt.hashCode()); result = prime * result + ((bhvAmt1 == null) ? 0 : bhvAmt1.hashCode()); result = prime * result + ((bhvAmt2 == null) ? 0 : bhvAmt2.hashCode()); result = prime * result + ((bhvAmt3 == null) ? 0 : bhvAmt3.hashCode()); result = prime * result + ((bhvAmt4 == null) ? 0 : bhvAmt4.hashCode()); result = prime * result + ((bhvArtc1 == null) ? 0 : bhvArtc1.hashCode()); result = prime * result + ((bhvArtc2 == null) ? 0 : bhvArtc2.hashCode()); result = prime * result + ((bhvArtc3 == null) ? 0 : bhvArtc3.hashCode()); result = prime * result + ((bhvArtc4 == null) ? 0 : bhvArtc4.hashCode()); result = prime * result + ((billUnit == null) ? 0 : billUnit.hashCode()); result = prime * result + ((carryDate == null) ? 0 : carryDate.hashCode()); result = prime * result + ((carrySeqNo == null) ? 0 : carrySeqNo.hashCode()); result = prime * result + ((caseTp == null) ? 0 : caseTp.hashCode()); result = prime * result + ((chkUnit == null) ? 0 : chkUnit.hashCode()); result = prime * result + ((collUnit == null) ? 0 : collUnit.hashCode()); result = prime * result + ((cpt == null) ? 0 : cpt.hashCode()); result = prime * result + ((cptCdcChar == null) ? 0 : cptCdcChar.hashCode()); result = prime * result + ((cptCdcDate == null) ? 0 : cptCdcDate.hashCode()); result = prime * result + ((cptCdcNo == null) ? 0 : cptCdcNo.hashCode()); result = prime * result + ((createDate == null) ? 0 : createDate.hashCode()); result = prime * result + ((crmlArtc == null) ? 0 : crmlArtc.hashCode()); result = prime * result + ((crmlProcDate == null) ? 0 : crmlProcDate.hashCode()); result = prime * result + ((crmlStus == null) ? 0 : crmlStus.hashCode()); result = prime * result + ((evadeIncm == null) ? 0 : evadeIncm.hashCode()); result = prime * result + ((evadeTax == null) ? 0 : evadeTax.hashCode()); result = prime * result + ((evdAmt1 == null) ? 0 : evdAmt1.hashCode()); result = prime * result + ((evdAmt2 == null) ? 0 : evdAmt2.hashCode()); result = prime * result + ((evdAmt3 == null) ? 0 : evdAmt3.hashCode()); result = prime * result + ((evdAmt4 == null) ? 0 : evdAmt4.hashCode()); result = prime * result + ((evdArtc1 == null) ? 0 : evdArtc1.hashCode()); result = prime * result + ((evdArtc2 == null) ? 0 : evdArtc2.hashCode()); result = prime * result + ((evdArtc3 == null) ? 0 : evdArtc3.hashCode()); result = prime * result + ((evdArtc4 == null) ? 0 : evdArtc4.hashCode()); result = prime * result + ((extdReas == null) ? 0 : extdReas.hashCode()); result = prime * result + ((extdTms == null) ? 0 : extdTms.hashCode()); result = prime * result + ((fCnvtMk == null) ? 0 : fCnvtMk.hashCode()); result = prime * result + ((fineAmtTot == null) ? 0 : fineAmtTot.hashCode()); result = prime * result + ((fshAplTp == null) ? 0 : fshAplTp.hashCode()); result = prime * result + ((fshDate == null) ? 0 : fshDate.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((invs1 == null) ? 0 : invs1.hashCode()); result = prime * result + ((invs2 == null) ? 0 : invs2.hashCode()); result = prime * result + ((invsRatio1 == null) ? 0 : invsRatio1.hashCode()); result = prime * result + ((invsRatio2 == null) ? 0 : invsRatio2.hashCode()); result = prime * result + ((madtrCd == null) ? 0 : madtrCd.hashCode()); result = prime * result + ((manageCd == null) ? 0 : manageCd.hashCode()); result = prime * result + ((npnshCd == null) ? 0 : npnshCd.hashCode()); result = prime * result + ((npnshReas == null) ? 0 : npnshReas.hashCode()); result = prime * result + ((oAdtrCd == null) ? 0 : oAdtrCd.hashCode()); result = prime * result + ((oAsgDate == null) ? 0 : oAsgDate.hashCode()); result = prime * result + ((oShFshDate == null) ? 0 : oShFshDate.hashCode()); result = prime * result + ((ovpnshMk == null) ? 0 : ovpnshMk.hashCode()); result = prime * result + ((pnshPrMk == null) ? 0 : pnshPrMk.hashCode()); result = prime * result + ((pnshTp == null) ? 0 : pnshTp.hashCode()); result = prime * result + ((prstAdtrCd == null) ? 0 : prstAdtrCd.hashCode()); result = prime * result + ((prstAsgDate == null) ? 0 : prstAsgDate.hashCode()); result = prime * result + ((prstPrcdDate == null) ? 0 : prstPrcdDate.hashCode()); result = prime * result + ((prstPrcdStus == null) ? 0 : prstPrcdStus.hashCode()); result = prime * result + ((prstShFshDate == null) ? 0 : prstShFshDate.hashCode()); result = prime * result + ((reChkUnit == null) ? 0 : reChkUnit.hashCode()); result = prime * result + ((respIdn == null) ? 0 : respIdn.hashCode()); result = prime * result + ((respNm == null) ? 0 : respNm.hashCode()); result = prime * result + ((revoCd == null) ? 0 : revoCd.hashCode()); result = prime * result + ((seizeDate == null) ? 0 : seizeDate.hashCode()); result = prime * result + ((servArea == null) ? 0 : servArea.hashCode()); result = prime * result + ((subtaxCd == null) ? 0 : subtaxCd.hashCode()); result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode()); result = prime * result + ((townCd == null) ? 0 : townCd.hashCode()); result = prime * result + ((trstrCd == null) ? 0 : trstrCd.hashCode()); result = prime * result + ((updJdgfDate == null) ? 0 : updJdgfDate.hashCode()); result = prime * result + ((updJdgfStus == null) ? 0 : updJdgfStus.hashCode()); result = prime * result + ((updateDate == null) ? 0 : updateDate.hashCode()); result = prime * result + ((updateUserCd == null) ? 0 : updateUserCd.hashCode()); result = prime * result + ((urgtLmtDate == null) ? 0 : urgtLmtDate.hashCode()); result = prime * result + ((vioBDate == null) ? 0 : vioBDate.hashCode()); result = prime * result + ((vioEDate == null) ? 0 : vioEDate.hashCode()); result = prime * result + ((vioFactCd1 == null) ? 0 : vioFactCd1.hashCode()); result = prime * result + ((vioFactCd2 == null) ? 0 : vioFactCd2.hashCode()); result = prime * result + ((vioHostIdnBan == null) ? 0 : vioHostIdnBan.hashCode()); result = prime * result + ((vioHostNm == null) ? 0 : vioHostNm.hashCode()); result = prime * result + ((vioYr == null) ? 0 : vioYr.hashCode()); result = prime * result + ((ynArrgMtg == null) ? 0 : ynArrgMtg.hashCode()); result = prime * result + ((zipCd == null) ? 0 : zipCd.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; Nigt001 other = (Nigt001) obj; if (acsNo == null) { if (other.acsNo != null) return false; } else if (!acsNo.equals(other.acsNo)) return false; if (addrHsnNm == null) { if (other.addrHsnNm != null) return false; } else if (!addrHsnNm.equals(other.addrHsnNm)) return false; if (addrLin == null) { if (other.addrLin != null) return false; } else if (!addrLin.equals(other.addrLin)) return false; if (addrMk == null) { if (other.addrMk != null) return false; } else if (!addrMk.equals(other.addrMk)) return false; if (addrRoadNo == null) { if (other.addrRoadNo != null) return false; } else if (!addrRoadNo.equals(other.addrRoadNo)) return false; if (addrTownNm == null) { if (other.addrTownNm != null) return false; } else if (!addrTownNm.equals(other.addrTownNm)) return false; if (addrVillNm == null) { if (other.addrVillNm != null) return false; } else if (!addrVillNm.equals(other.addrVillNm)) return false; if (admRmdDate == null) { if (other.admRmdDate != null) return false; } else if (!admRmdDate.equals(other.admRmdDate)) return false; if (admRmdStus == null) { if (other.admRmdStus != null) return false; } else if (!admRmdStus.equals(other.admRmdStus)) return false; if (adtSgstMk == null) { if (other.adtSgstMk != null) return false; } else if (!adtSgstMk.equals(other.adtSgstMk)) return false; if (adtrAplTp == null) { if (other.adtrAplTp != null) return false; } else if (!adtrAplTp.equals(other.adtrAplTp)) return false; if (adtrFnshDate == null) { if (other.adtrFnshDate != null) return false; } else if (!adtrFnshDate.equals(other.adtrFnshDate)) return false; if (aplLimitYm == null) { if (other.aplLimitYm != null) return false; } else if (!aplLimitYm.equals(other.aplLimitYm)) return false; if (arrgMtgTp == null) { if (other.arrgMtgTp != null) return false; } else if (!arrgMtgTp.equals(other.arrgMtgTp)) return false; if (asgKey == null) { if (other.asgKey != null) return false; } else if (!asgKey.equals(other.asgKey)) return false; if (asgMk == null) { if (other.asgMk != null) return false; } else if (!asgMk.equals(other.asgMk)) return false; if (asst1 == null) { if (other.asst1 != null) return false; } else if (!asst1.equals(other.asst1)) return false; if (asst2 == null) { if (other.asst2 != null) return false; } else if (!asst2.equals(other.asst2)) return false; if (asst3 == null) { if (other.asst3 != null) return false; } else if (!asst3.equals(other.asst3)) return false; if (asstCdcChar1 == null) { if (other.asstCdcChar1 != null) return false; } else if (!asstCdcChar1.equals(other.asstCdcChar1)) return false; if (asstCdcChar2 == null) { if (other.asstCdcChar2 != null) return false; } else if (!asstCdcChar2.equals(other.asstCdcChar2)) return false; if (asstCdcChar3 == null) { if (other.asstCdcChar3 != null) return false; } else if (!asstCdcChar3.equals(other.asstCdcChar3)) return false; if (asstCdcDate1 == null) { if (other.asstCdcDate1 != null) return false; } else if (!asstCdcDate1.equals(other.asstCdcDate1)) return false; if (asstCdcDate2 == null) { if (other.asstCdcDate2 != null) return false; } else if (!asstCdcDate2.equals(other.asstCdcDate2)) return false; if (asstCdcDate3 == null) { if (other.asstCdcDate3 != null) return false; } else if (!asstCdcDate3.equals(other.asstCdcDate3)) return false; if (asstCdcNo1 == null) { if (other.asstCdcNo1 != null) return false; } else if (!asstCdcNo1.equals(other.asstCdcNo1)) return false; if (asstCdcNo2 == null) { if (other.asstCdcNo2 != null) return false; } else if (!asstCdcNo2.equals(other.asstCdcNo2)) return false; if (asstCdcNo3 == null) { if (other.asstCdcNo3 != null) return false; } else if (!asstCdcNo3.equals(other.asstCdcNo3)) return false; if (asstTp == null) { if (other.asstTp != null) return false; } else if (!asstTp.equals(other.asstTp)) return false; if (authMk == null) { if (other.authMk != null) return false; } else if (!authMk.equals(other.authMk)) return false; if (baTaxKey == null) { if (other.baTaxKey != null) return false; } else if (!baTaxKey.equals(other.baTaxKey)) return false; if (baTaxMk == null) { if (other.baTaxMk != null) return false; } else if (!baTaxMk.equals(other.baTaxMk)) return false; if (ban == null) { if (other.ban != null) return false; } else if (!ban.equals(other.ban)) return false; if (behAmt == null) { if (other.behAmt != null) return false; } else if (!behAmt.equals(other.behAmt)) return false; if (bhvAmt == null) { if (other.bhvAmt != null) return false; } else if (!bhvAmt.equals(other.bhvAmt)) return false; if (bhvAmt1 == null) { if (other.bhvAmt1 != null) return false; } else if (!bhvAmt1.equals(other.bhvAmt1)) return false; if (bhvAmt2 == null) { if (other.bhvAmt2 != null) return false; } else if (!bhvAmt2.equals(other.bhvAmt2)) return false; if (bhvAmt3 == null) { if (other.bhvAmt3 != null) return false; } else if (!bhvAmt3.equals(other.bhvAmt3)) return false; if (bhvAmt4 == null) { if (other.bhvAmt4 != null) return false; } else if (!bhvAmt4.equals(other.bhvAmt4)) return false; if (bhvArtc1 == null) { if (other.bhvArtc1 != null) return false; } else if (!bhvArtc1.equals(other.bhvArtc1)) return false; if (bhvArtc2 == null) { if (other.bhvArtc2 != null) return false; } else if (!bhvArtc2.equals(other.bhvArtc2)) return false; if (bhvArtc3 == null) { if (other.bhvArtc3 != null) return false; } else if (!bhvArtc3.equals(other.bhvArtc3)) return false; if (bhvArtc4 == null) { if (other.bhvArtc4 != null) return false; } else if (!bhvArtc4.equals(other.bhvArtc4)) return false; if (billUnit == null) { if (other.billUnit != null) return false; } else if (!billUnit.equals(other.billUnit)) return false; if (carryDate == null) { if (other.carryDate != null) return false; } else if (!carryDate.equals(other.carryDate)) return false; if (carrySeqNo == null) { if (other.carrySeqNo != null) return false; } else if (!carrySeqNo.equals(other.carrySeqNo)) return false; if (caseTp == null) { if (other.caseTp != null) return false; } else if (!caseTp.equals(other.caseTp)) return false; if (chkUnit == null) { if (other.chkUnit != null) return false; } else if (!chkUnit.equals(other.chkUnit)) return false; if (collUnit == null) { if (other.collUnit != null) return false; } else if (!collUnit.equals(other.collUnit)) return false; if (cpt == null) { if (other.cpt != null) return false; } else if (!cpt.equals(other.cpt)) return false; if (cptCdcChar == null) { if (other.cptCdcChar != null) return false; } else if (!cptCdcChar.equals(other.cptCdcChar)) return false; if (cptCdcDate == null) { if (other.cptCdcDate != null) return false; } else if (!cptCdcDate.equals(other.cptCdcDate)) return false; if (cptCdcNo == null) { if (other.cptCdcNo != null) return false; } else if (!cptCdcNo.equals(other.cptCdcNo)) return false; if (createDate == null) { if (other.createDate != null) return false; } else if (!createDate.equals(other.createDate)) return false; if (crmlArtc == null) { if (other.crmlArtc != null) return false; } else if (!crmlArtc.equals(other.crmlArtc)) return false; if (crmlProcDate == null) { if (other.crmlProcDate != null) return false; } else if (!crmlProcDate.equals(other.crmlProcDate)) return false; if (crmlStus == null) { if (other.crmlStus != null) return false; } else if (!crmlStus.equals(other.crmlStus)) return false; if (evadeIncm == null) { if (other.evadeIncm != null) return false; } else if (!evadeIncm.equals(other.evadeIncm)) return false; if (evadeTax == null) { if (other.evadeTax != null) return false; } else if (!evadeTax.equals(other.evadeTax)) return false; if (evdAmt1 == null) { if (other.evdAmt1 != null) return false; } else if (!evdAmt1.equals(other.evdAmt1)) return false; if (evdAmt2 == null) { if (other.evdAmt2 != null) return false; } else if (!evdAmt2.equals(other.evdAmt2)) return false; if (evdAmt3 == null) { if (other.evdAmt3 != null) return false; } else if (!evdAmt3.equals(other.evdAmt3)) return false; if (evdAmt4 == null) { if (other.evdAmt4 != null) return false; } else if (!evdAmt4.equals(other.evdAmt4)) return false; if (evdArtc1 == null) { if (other.evdArtc1 != null) return false; } else if (!evdArtc1.equals(other.evdArtc1)) return false; if (evdArtc2 == null) { if (other.evdArtc2 != null) return false; } else if (!evdArtc2.equals(other.evdArtc2)) return false; if (evdArtc3 == null) { if (other.evdArtc3 != null) return false; } else if (!evdArtc3.equals(other.evdArtc3)) return false; if (evdArtc4 == null) { if (other.evdArtc4 != null) return false; } else if (!evdArtc4.equals(other.evdArtc4)) return false; if (extdReas == null) { if (other.extdReas != null) return false; } else if (!extdReas.equals(other.extdReas)) return false; if (extdTms == null) { if (other.extdTms != null) return false; } else if (!extdTms.equals(other.extdTms)) return false; if (fCnvtMk == null) { if (other.fCnvtMk != null) return false; } else if (!fCnvtMk.equals(other.fCnvtMk)) return false; if (fineAmtTot == null) { if (other.fineAmtTot != null) return false; } else if (!fineAmtTot.equals(other.fineAmtTot)) return false; if (fshAplTp == null) { if (other.fshAplTp != null) return false; } else if (!fshAplTp.equals(other.fshAplTp)) return false; if (fshDate == null) { if (other.fshDate != null) return false; } else if (!fshDate.equals(other.fshDate)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (invs1 == null) { if (other.invs1 != null) return false; } else if (!invs1.equals(other.invs1)) return false; if (invs2 == null) { if (other.invs2 != null) return false; } else if (!invs2.equals(other.invs2)) return false; if (invsRatio1 == null) { if (other.invsRatio1 != null) return false; } else if (!invsRatio1.equals(other.invsRatio1)) return false; if (invsRatio2 == null) { if (other.invsRatio2 != null) return false; } else if (!invsRatio2.equals(other.invsRatio2)) return false; if (madtrCd == null) { if (other.madtrCd != null) return false; } else if (!madtrCd.equals(other.madtrCd)) return false; if (manageCd == null) { if (other.manageCd != null) return false; } else if (!manageCd.equals(other.manageCd)) return false; if (npnshCd == null) { if (other.npnshCd != null) return false; } else if (!npnshCd.equals(other.npnshCd)) return false; if (npnshReas == null) { if (other.npnshReas != null) return false; } else if (!npnshReas.equals(other.npnshReas)) return false; if (oAdtrCd == null) { if (other.oAdtrCd != null) return false; } else if (!oAdtrCd.equals(other.oAdtrCd)) return false; if (oAsgDate == null) { if (other.oAsgDate != null) return false; } else if (!oAsgDate.equals(other.oAsgDate)) return false; if (oShFshDate == null) { if (other.oShFshDate != null) return false; } else if (!oShFshDate.equals(other.oShFshDate)) return false; if (ovpnshMk == null) { if (other.ovpnshMk != null) return false; } else if (!ovpnshMk.equals(other.ovpnshMk)) return false; if (pnshPrMk == null) { if (other.pnshPrMk != null) return false; } else if (!pnshPrMk.equals(other.pnshPrMk)) return false; if (pnshTp == null) { if (other.pnshTp != null) return false; } else if (!pnshTp.equals(other.pnshTp)) return false; if (prstAdtrCd == null) { if (other.prstAdtrCd != null) return false; } else if (!prstAdtrCd.equals(other.prstAdtrCd)) return false; if (prstAsgDate == null) { if (other.prstAsgDate != null) return false; } else if (!prstAsgDate.equals(other.prstAsgDate)) return false; if (prstPrcdDate == null) { if (other.prstPrcdDate != null) return false; } else if (!prstPrcdDate.equals(other.prstPrcdDate)) return false; if (prstPrcdStus == null) { if (other.prstPrcdStus != null) return false; } else if (!prstPrcdStus.equals(other.prstPrcdStus)) return false; if (prstShFshDate == null) { if (other.prstShFshDate != null) return false; } else if (!prstShFshDate.equals(other.prstShFshDate)) return false; if (reChkUnit == null) { if (other.reChkUnit != null) return false; } else if (!reChkUnit.equals(other.reChkUnit)) return false; if (respIdn == null) { if (other.respIdn != null) return false; } else if (!respIdn.equals(other.respIdn)) return false; if (respNm == null) { if (other.respNm != null) return false; } else if (!respNm.equals(other.respNm)) return false; if (revoCd == null) { if (other.revoCd != null) return false; } else if (!revoCd.equals(other.revoCd)) return false; if (seizeDate == null) { if (other.seizeDate != null) return false; } else if (!seizeDate.equals(other.seizeDate)) return false; if (servArea == null) { if (other.servArea != null) return false; } else if (!servArea.equals(other.servArea)) return false; if (subtaxCd == null) { if (other.subtaxCd != null) return false; } else if (!subtaxCd.equals(other.subtaxCd)) return false; if (timeStamp == null) { if (other.timeStamp != null) return false; } else if (!timeStamp.equals(other.timeStamp)) return false; if (townCd == null) { if (other.townCd != null) return false; } else if (!townCd.equals(other.townCd)) return false; if (trstrCd == null) { if (other.trstrCd != null) return false; } else if (!trstrCd.equals(other.trstrCd)) return false; if (updJdgfDate == null) { if (other.updJdgfDate != null) return false; } else if (!updJdgfDate.equals(other.updJdgfDate)) return false; if (updJdgfStus == null) { if (other.updJdgfStus != null) return false; } else if (!updJdgfStus.equals(other.updJdgfStus)) return false; if (updateDate == null) { if (other.updateDate != null) return false; } else if (!updateDate.equals(other.updateDate)) return false; if (updateUserCd == null) { if (other.updateUserCd != null) return false; } else if (!updateUserCd.equals(other.updateUserCd)) return false; if (urgtLmtDate == null) { if (other.urgtLmtDate != null) return false; } else if (!urgtLmtDate.equals(other.urgtLmtDate)) return false; if (vioBDate == null) { if (other.vioBDate != null) return false; } else if (!vioBDate.equals(other.vioBDate)) return false; if (vioEDate == null) { if (other.vioEDate != null) return false; } else if (!vioEDate.equals(other.vioEDate)) return false; if (vioFactCd1 == null) { if (other.vioFactCd1 != null) return false; } else if (!vioFactCd1.equals(other.vioFactCd1)) return false; if (vioFactCd2 == null) { if (other.vioFactCd2 != null) return false; } else if (!vioFactCd2.equals(other.vioFactCd2)) return false; if (vioHostIdnBan == null) { if (other.vioHostIdnBan != null) return false; } else if (!vioHostIdnBan.equals(other.vioHostIdnBan)) return false; if (vioHostNm == null) { if (other.vioHostNm != null) return false; } else if (!vioHostNm.equals(other.vioHostNm)) return false; if (vioYr == null) { if (other.vioYr != null) return false; } else if (!vioYr.equals(other.vioYr)) return false; if (ynArrgMtg == null) { if (other.ynArrgMtg != null) return false; } else if (!ynArrgMtg.equals(other.ynArrgMtg)) return false; if (zipCd == null) { if (other.zipCd != null) return false; } else if (!zipCd.equals(other.zipCd)) return false; return true; } |
Solution
透過Apache Commons Lang的HashCodeBuilder與EqualsBuilder來解決此問題。
Steps
1. 建立一個Domain Base Class,裡頭透過Commons Lang的API來進行實作hashCode與equals method
實作內容很簡單,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package gov.fdc.nig.domain; import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; public class DomainBase { /* * This class enables a good hashCode method to be built for any class. * It follows the rules laid out in the book Effective Java by Joshua Bloch. * Writing a good hashCode method is actually quite difficult. * This class aims to simplify the process. * (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } /* * This class provides methods to build a good equals method for any class. * It follows rules laid out in Effective Java , by Joshua Bloch. * In particular the rule for comparing doubles, floats, and arrays can be tricky. * Also, making sure that equals() and hashCode() are consistent can be difficult. * (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { return EqualsBuilder.reflectionEquals(this, obj); } /* * Assists in implementing Comparable.compareTo(Object) methods. * It is consistent with equals(Object) and hashcode() built with EqualsBuilder and HashCodeBuilder. */ public int compareTo(Object obj) { return CompareToBuilder.reflectionCompare(this, obj); } /* * Assists in implementing Object.toString() methods. * * (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { return ToStringBuilder.reflectionToString(this); } } |
2. 原本的entity class,先繼承DomainBase,再來刪除不必要的equals, hashCode與toString method,通通交給DomainBase處理即可。class之間的關係如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | package gov.fdc.nig.domain; import java.sql.Timestamp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; /** * Nigt036 entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "NIGT036", schema = "AP_TAX") public class Nigt036 extends DomainBase implements java.io.Serializable { /** * */ private static final long serialVersionUID = 627363036088777178 L; // Fields private String vioOrgCd; private String vioOrgNm; private String vioOrgShnm; private String bureauCd; private Timestamp timeStamp; private String updateCd; private String userId; private String updateDate; // Constructors /** default constructor */ public Nigt036() {} /** minimal constructor */ public Nigt036(String vioOrgCd) { this.vioOrgCd = vioOrgCd; } /** full constructor */ public Nigt036(String vioOrgCd, String bureauCd, Timestamp timeStamp, String updateCd, String updateDate, String userId, String vioOrgNm, String vioOrgShnm) { super(); this.vioOrgCd = vioOrgCd; this.bureauCd = bureauCd; this.timeStamp = timeStamp; this.updateCd = updateCd; this.updateDate = updateDate; this.userId = userId; this.vioOrgNm = vioOrgNm; this.vioOrgShnm = vioOrgShnm; } // Property accessors @Id @Column(name = "VIO_ORG_CD", unique = true, nullable = false, length = 4) public String getVioOrgCd() { return this.vioOrgCd; } public void setVioOrgCd(String vioOrgCd) { this.vioOrgCd = vioOrgCd; } @Column(name = "VIO_ORG_NM") public String getVioOrgNm() { return this.vioOrgNm; } public void setVioOrgNm(String vioOrgNm) { this.vioOrgNm = vioOrgNm; } @Column(name = "VIO_ORG_SHNM") public String getVioOrgShnm() { return this.vioOrgShnm; } public void setVioOrgShnm(String vioOrgShnm) { this.vioOrgShnm = vioOrgShnm; } @Column(name = "BUREAU_CD", length = 3) public String getBureauCd() { return this.bureauCd; } public void setBureauCd(String bureauCd) { this.bureauCd = bureauCd; } @Column(name = "TIME_STAMP", length = 11) public Timestamp getTimeStamp() { return this.timeStamp; } public void setTimeStamp(Timestamp timeStamp) { this.timeStamp = timeStamp; } @Column(name = "UPDATE_CD", length = 2) public String getUpdateCd() { return this.updateCd; } public void setUpdateCd(String updateCd) { this.updateCd = updateCd; } @Column(name = "USER_ID", length = 8) public String getUserId() { return this.userId; } public void setUserId(String userId) { this.userId = userId; } @Column(name = "UPDATE_DATE", length = 7) public String getUpdateDate() { return this.updateDate; } public void setUpdateDate(String updateDate) { this.updateDate = updateDate; } } |
Benefits
1. 測試起來較輕鬆,且能有效提昇code coverage
2. 讓程式更加精簡、好維護
3. follow rules laid out in Effective Java , by Joshua Bloch
Subscribe to:
Posts (Atom)