Advertisement
Guest User

PhoneContact.java

a guest
Apr 30th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.79 KB | None | 0 0
  1. package com.example.model;
  2.  
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.EnumType;
  6. import javax.persistence.Enumerated;
  7. import javax.persistence.GeneratedValue;
  8. import javax.persistence.GenerationType;
  9. import javax.persistence.Id;
  10. import javax.persistence.ManyToOne;
  11. import javax.persistence.Table;
  12.  
  13. import org.springframework.beans.factory.annotation.Required;
  14.  
  15. import com.google.common.base.Strings;
  16.  
  17. @Entity
  18. @Table(name = "phone_contact")
  19. public class PhoneContact extends BaseObject {
  20.  
  21.     private static final long serialVersionUID = 3614259347370445202L;
  22.  
  23.     private Long id;
  24.     private Customer customer;
  25.     private String phoneNumber;
  26.     private String phoneExtention;
  27.     private PhoneType phoneType;
  28.  
  29.     public PhoneContact() {
  30.         super();
  31.     }
  32.  
  33.     public PhoneContact(PhoneType phoneType, String phoneNumber) {
  34.         super();
  35.         this.phoneType = phoneType;
  36.         this.phoneNumber = phoneNumber;
  37.     }
  38.  
  39.     public PhoneContact(PhoneType phoneType, String phoneNumber, String phoneExtention) {
  40.         super();
  41.         this.phoneType = phoneType;
  42.         this.phoneNumber = phoneNumber;
  43.         if (!Strings.isNullOrEmpty(phoneExtention)) {
  44.             this.phoneExtention = phoneExtention;
  45.         }
  46.     }
  47.  
  48.     @Id
  49.     @GeneratedValue(strategy = GenerationType.AUTO)
  50.     public Long getId() {
  51.         return id;
  52.     }
  53.  
  54.     public void setId(Long id) {
  55.         this.id = id;
  56.     }
  57.  
  58.     @ManyToOne
  59.     @Required
  60.     public Customer getCustomer() {
  61.         return customer;
  62.     }
  63.  
  64.     public void setCustomer(Customer customer) {
  65.         if (this.customer != null && !this.customer.equals(customer)) {
  66.             throw new RuntimeException("Invalid state: Customer cannot be changed on an existing PhoneContact");
  67.         }
  68.         this.customer = customer;
  69.     }
  70.  
  71.     @Column(name = "phone_number", length = 20)
  72.     @Required
  73.     public String getPhoneNumber() {
  74.         return phoneNumber;
  75.     }
  76.  
  77.     public void setPhoneNumber(String phoneNumber) {
  78.         this.phoneNumber = phoneNumber;
  79.     }
  80.  
  81.     @Column(name = "phone_extention", length = 10)
  82.     public String getPhoneExtention() {
  83.         return phoneExtention;
  84.     }
  85.  
  86.     public void setPhoneExtention(String phoneExtention) {
  87.         this.phoneExtention = phoneExtention;
  88.     }
  89.  
  90.     @Enumerated(EnumType.STRING)
  91.     @Column(name = "phone_type", length = 10)
  92.     @Required
  93.     public PhoneType getPhoneType() {
  94.         return phoneType;
  95.     }
  96.  
  97.     public void setPhoneType(PhoneType phoneType) {
  98.         this.phoneType = phoneType;
  99.     }
  100.  
  101.     @Override
  102.     public int hashCode() {
  103.         final int prime = 31;
  104.         int result = 1;
  105.         result = prime * result + ((customer == null) ? 0 : customer.hashCode());
  106.         result = prime * result + ((phoneExtention == null) ? 0 : phoneExtention.hashCode());
  107.         result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
  108.         result = prime * result + ((phoneType == null) ? 0 : phoneType.hashCode());
  109.         return result;
  110.     }
  111.  
  112.     @Override
  113.     public boolean equals(Object obj) {
  114.         if (this == obj)
  115.             return true;
  116.         if (obj == null)
  117.             return false;
  118.         if (getClass() != obj.getClass())
  119.             return false;
  120.         PhoneContact other = (PhoneContact) obj;
  121.         if (customer == null) {
  122.             if (other.customer != null)
  123.                 return false;
  124.         } else if (!customer.equals(other.customer))
  125.             return false;
  126.         if (phoneExtention == null) {
  127.             if (other.phoneExtention != null)
  128.                 return false;
  129.         } else if (!phoneExtention.equals(other.phoneExtention))
  130.             return false;
  131.         if (phoneNumber == null) {
  132.             if (other.phoneNumber != null)
  133.                 return false;
  134.         } else if (!phoneNumber.equals(other.phoneNumber))
  135.             return false;
  136.         if (phoneType != other.phoneType)
  137.             return false;
  138.         return true;
  139.     }
  140.  
  141.     @Override
  142.     public String toString() {
  143.         return "PhoneContact [id=" + id + ", customer=" + (customer == null ? "null" : customer.getCustomerNumber()) + ", phoneNumber="
  144.                 + phoneNumber + ", phoneExtention=" + phoneExtention + ", phoneType=" + phoneType + "]";
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement