自分で定義したクラスについてhashMapのkeyオブジェクトの例として

1743 ワード

package iss.com.equals;

import java.util.Date;

class CountIsable {

 private Date date;

 private String accountNo;

 private String bankCode;

 public CountIsable(Date transactionTime, String accountNo, String bankCode) {
  this.date = transactionTime;
  this.accountNo = accountNo;
  this.bankCode = bankCode;
 }

 public CountIsable(String accountNo, String bankCode) {
  this.accountNo = accountNo;
  this.bankCode = bankCode;
 }
                
 public boolean equals(CountIsable mapKey) {
  if (DateUtil.compareDate(date, mapKey.getDate()) == 0
    && accountNo.equals(mapKey.getAccountNo())) {
   if (mapKey.getBankCode() == null
     || mapKey.getBankCode().equals(bankCode))
    return true;
  }
  return false;
 }
 public boolean equals(Object key) {
  CountIsable mapKey=(CountIsable)key;
  if (DateUtil.compareDate(date, mapKey.getDate()) == 0
    && accountNo.equals(mapKey.getAccountNo())) {
   if (mapKey.getBankCode() == null
     || mapKey.getBankCode().equals(bankCode))
    return true;
  }
  return false;
 }

 public String toString() {
  return date.toString() + accountNo + bankCode;
 }

public int hashCode() {
 int temp =(date.toString() + accountNo + bankCode).hashCode(); 
  return temp;
 }

 public String getAccountNo() {
  return accountNo;
 }

 public String getBankCode() {
  return bankCode;
 }

 public Date getDate() {
  return date;
 }
}