package au.gov.ga.geodesy.igssitelog.domain.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.apache.commons.lang.ObjectUtils;

/**
 * http://sopac.ucsd.edu/ns/geodesy/doc/igsSiteLog/equipment/2004/baseEquipmentLib.xsd:baseSensorEquipmentType.effectiveDates Note: this is an attempt to
 * interpret date values as java dates, rather than as strings as defined in the SOPAC schema (feel free to revert to java strings, if this starts to cause
 * trouble).
 */
@Embeddable
public class EffectiveDates {

    @Column(name = "EFFECTIVE_FROM")
    private Date from;

    @Column(name = "EFFECTIVE_TO")
    private Date to;

    public EffectiveDates() {
    }

    public EffectiveDates(Date from) {
        this(from, null);
    }

    public EffectiveDates(Date from, Date to) {
        setFrom(from);
        setTo(to);
    }

    public Date getFrom() {
        return from;
    }

    public void setFrom(Date from) {
        this.from = from;
    }

    public Date getTo() {
        return to;
    }

    public void setTo(Date to) {
        this.to = to;
    }

    public boolean equals(Object x) {
        if (x instanceof EffectiveDates && x != null) {
            EffectiveDates dates = (EffectiveDates) x;
            return ObjectUtils.equals(from, dates.getFrom()) && ObjectUtils.equals(to, dates.getTo());
        }
        return false;
    }
}

@@ -171,27 +171,37 @@
 ns.lang.
-ObjectUtils
+builder.EqualsBuilder
 ;%0A%0A/**%0A 
@@ -1189,54 +1189,193 @@
  (x 
-instanceof EffectiveDates && x != null) %7B%0A    
+== null) %7B%0A            return false;%0A        %7D%0A        if (x == this) %7B%0A            return true;%0A        %7D%0A        if (x.getClass() != getClass()) %7B%0A            return false;%0A        %7D%0A
     
@@ -1393,21 +1393,21 @@
 veDates 
-dates
+other
  = (Effe
@@ -1433,31 +1433,15 @@
     
-    
 return 
-ObjectUtils.
 equa
@@ -1449,21 +1449,21 @@
 s(from, 
-dates
+other
 .getFrom
@@ -1473,77 +1473,383 @@
  && 
-ObjectUtils.
+equals(to, other.getTo());%0A    %7D%0A%0A    /**%0A     * We compare dates ourselves because some are java.util.Dates and some are%0A     * java.sql.Timestamps.%0A     */%0A    private boolean 
 equals(
-to, dates.getTo());%0A        %7D%0A        return false
+Date a, Date b) %7B%0A        if (a == b) %7B%0A            return true;%0A        %7D%0A        if (a == null %7C%7C b == null) %7B%0A            return false;%0A        %7D%0A        return a.getTime() == b.getTime()
 ;%0A  

Add equals method to EffectiveDates.