Subject: Re: Simple composite key of ansi padded strings

  Andi Huber 2018-06-22, 06:49
  Andi Huber 2018-06-22, 06:46
  Andi Huber 2018-06-22, 07:25
  Brian K 2018-06-21, 20:09
Thanks Andi!  There were a few parts that I had to change.  For instance,
using targetClassName triggered a validation error when building in
SimpleApp.  The following is working:

public class CourtPrecinctPrimaryKey implements Serializable {

    public String courtCd;
    public String precinctCd;

    private static final String SEPARATOR = ",";

    public CourtPrecinctPrimaryKey() {
    }

    public CourtPrecinctPrimaryKey(String value) {
        StringTokenizer token = new StringTokenizer(value, SEPARATOR);
        this.courtCd = StringUtils.stripEnd(token.nextToken(),null);
        this.precinctCd = StringUtils.stripEnd(token.nextToken(),null);
    }

    @Override
    public String toString() {
        return ""
                + SEPARATOR + StringUtils.stripEnd(this.courtCd.trim(),
null)
                + SEPARATOR + StringUtils.stripEnd(this.precinctCd.trim(),
null);
    }

    @Override
    public int hashCode() {
        return StringUtils.stripEnd(this.courtCd, null).hashCode() ^
StringUtils.stripEnd(this.precinctCd, null).hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof CourtPrecinctPrimaryKey)) {
            return false;
        }
        CourtPrecinctPrimaryKey c = (CourtPrecinctPrimaryKey) obj;
        return courtCd.startsWith(c.courtCd) &&
precinctCd.startsWith(c.precinctCd);
    }

}