DefaultAddress.java

  1. /*******************************************************************************
  2.  * Copyright 2017 The MIT Internet Trust Consortium
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *******************************************************************************/
  16. package org.mitre.openid.connect.model;

  17. import javax.persistence.Basic;
  18. import javax.persistence.Column;
  19. import javax.persistence.Entity;
  20. import javax.persistence.GeneratedValue;
  21. import javax.persistence.GenerationType;
  22. import javax.persistence.Id;
  23. import javax.persistence.Table;

  24. @Entity
  25. @Table(name="address")
  26. public class DefaultAddress implements Address {

  27.     private static final long serialVersionUID = -1304880008685206811L;

  28.     private Long id;
  29.     private String formatted;
  30.     private String streetAddress;
  31.     private String locality;
  32.     private String region;
  33.     private String postalCode;
  34.     private String country;

  35.     /**
  36.      * Empty constructor
  37.      */
  38.     public DefaultAddress() {

  39.     }

  40.     /**
  41.      * Copy constructor from an existing address.
  42.      * @param address
  43.      */
  44.     public DefaultAddress(Address address) {
  45.         setFormatted(address.getFormatted());
  46.         setStreetAddress(address.getStreetAddress());
  47.         setLocality(address.getLocality());
  48.         setRegion(address.getRegion());
  49.         setPostalCode(address.getPostalCode());
  50.         setCountry(address.getCountry());
  51.     }

  52.     /**
  53.      * @return the formatted address string
  54.      */
  55.     @Override
  56.     @Basic
  57.     @Column(name = "formatted")
  58.     public String getFormatted() {
  59.         return formatted;
  60.     }
  61.     /**
  62.      * @param formatted the formatted address to set
  63.      */
  64.     @Override
  65.     public void setFormatted(String formatted) {
  66.         this.formatted = formatted;
  67.     }
  68.     /**
  69.      * @return the streetAddress
  70.      */
  71.     @Override
  72.     @Basic
  73.     @Column(name="street_address")
  74.     public String getStreetAddress() {
  75.         return streetAddress;
  76.     }
  77.     /**
  78.      * @param streetAddress the streetAddress to set
  79.      */
  80.     @Override
  81.     public void setStreetAddress(String streetAddress) {
  82.         this.streetAddress = streetAddress;
  83.     }
  84.     /**
  85.      * @return the locality
  86.      */
  87.     @Override
  88.     @Basic
  89.     @Column(name = "locality")
  90.     public String getLocality() {
  91.         return locality;
  92.     }
  93.     /**
  94.      * @param locality the locality to set
  95.      */
  96.     @Override
  97.     public void setLocality(String locality) {
  98.         this.locality = locality;
  99.     }
  100.     /**
  101.      * @return the region
  102.      */
  103.     @Override
  104.     @Basic
  105.     @Column(name = "region")
  106.     public String getRegion() {
  107.         return region;
  108.     }
  109.     /**
  110.      * @param region the region to set
  111.      */
  112.     @Override
  113.     public void setRegion(String region) {
  114.         this.region = region;
  115.     }
  116.     /**
  117.      * @return the postalCode
  118.      */
  119.     @Override
  120.     @Basic
  121.     @Column(name="postal_code")
  122.     public String getPostalCode() {
  123.         return postalCode;
  124.     }
  125.     /**
  126.      * @param postalCode the postalCode to set
  127.      */
  128.     @Override
  129.     public void setPostalCode(String postalCode) {
  130.         this.postalCode = postalCode;
  131.     }
  132.     /**
  133.      * @return the country
  134.      */
  135.     @Override
  136.     @Basic
  137.     @Column(name = "country")
  138.     public String getCountry() {
  139.         return country;
  140.     }
  141.     /**
  142.      * @param country the country to set
  143.      */
  144.     @Override
  145.     public void setCountry(String country) {
  146.         this.country = country;
  147.     }

  148.     /**
  149.      * @return the id
  150.      */
  151.     @Override
  152.     @Id
  153.     @GeneratedValue(strategy=GenerationType.IDENTITY)
  154.     @Column(name = "id")
  155.     public Long getId() {
  156.         return id;
  157.     }

  158.     /**
  159.      * @param id the id to set
  160.      */
  161.     public void setId(Long id) {
  162.         this.id = id;
  163.     }

  164.     /* (non-Javadoc)
  165.      * @see java.lang.Object#hashCode()
  166.      */
  167.     @Override
  168.     public int hashCode() {
  169.         final int prime = 31;
  170.         int result = 1;
  171.         result = prime * result + ((country == null) ? 0 : country.hashCode());
  172.         result = prime * result + ((formatted == null) ? 0 : formatted.hashCode());
  173.         result = prime * result + ((id == null) ? 0 : id.hashCode());
  174.         result = prime * result + ((locality == null) ? 0 : locality.hashCode());
  175.         result = prime * result + ((postalCode == null) ? 0 : postalCode.hashCode());
  176.         result = prime * result + ((region == null) ? 0 : region.hashCode());
  177.         result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode());
  178.         return result;
  179.     }

  180.     /* (non-Javadoc)
  181.      * @see java.lang.Object#equals(java.lang.Object)
  182.      */
  183.     @Override
  184.     public boolean equals(Object obj) {
  185.         if (this == obj) {
  186.             return true;
  187.         }
  188.         if (obj == null) {
  189.             return false;
  190.         }
  191.         if (!(obj instanceof DefaultAddress)) {
  192.             return false;
  193.         }
  194.         DefaultAddress other = (DefaultAddress) obj;
  195.         if (country == null) {
  196.             if (other.country != null) {
  197.                 return false;
  198.             }
  199.         } else if (!country.equals(other.country)) {
  200.             return false;
  201.         }
  202.         if (formatted == null) {
  203.             if (other.formatted != null) {
  204.                 return false;
  205.             }
  206.         } else if (!formatted.equals(other.formatted)) {
  207.             return false;
  208.         }
  209.         if (id == null) {
  210.             if (other.id != null) {
  211.                 return false;
  212.             }
  213.         } else if (!id.equals(other.id)) {
  214.             return false;
  215.         }
  216.         if (locality == null) {
  217.             if (other.locality != null) {
  218.                 return false;
  219.             }
  220.         } else if (!locality.equals(other.locality)) {
  221.             return false;
  222.         }
  223.         if (postalCode == null) {
  224.             if (other.postalCode != null) {
  225.                 return false;
  226.             }
  227.         } else if (!postalCode.equals(other.postalCode)) {
  228.             return false;
  229.         }
  230.         if (region == null) {
  231.             if (other.region != null) {
  232.                 return false;
  233.             }
  234.         } else if (!region.equals(other.region)) {
  235.             return false;
  236.         }
  237.         if (streetAddress == null) {
  238.             if (other.streetAddress != null) {
  239.                 return false;
  240.             }
  241.         } else if (!streetAddress.equals(other.streetAddress)) {
  242.             return false;
  243.         }
  244.         return true;
  245.     }

  246. }