package de.ivu.elect.presentation.system.table;

import java.lang.ref.SoftReference;

import de.ivu.elect.presentation.system.FinderKey;

public class DAOCacheFinderKey {

  private final SoftReference<FinderKey> finderKeySoftReference;

  public DAOCacheFinderKey(FinderKey finderKey) {
    finderKeySoftReference = new SoftReference<>(finderKey);
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof DAOCacheFinderKey) {
      FinderKey fkThis = finderKeySoftReference.get();
      if (fkThis == null) {
        return false;
      }
      try {
        FinderKey fkOther = ((DAOCacheFinderKey) o).getFinderKey();
        if (fkOther == null) {
          return false;
        }
        return fkThis.equals(fkOther);
      } catch (Exception e) {
        return false;
      }
    }
    return false;

  }

  public FinderKey getFinderKey() {
    return finderKeySoftReference.get();
  }

  @Override
  public int hashCode() {
    FinderKey finderKey = getFinderKey();
    if (finderKey == null) {
      return 0;
    }

    return finderKey.hashCode();
  }
}
