/*
 * Copyright 2010-2011 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.ning.billing.account.api;

import com.ning.billing.util.entity.UpdatableEntityBase;

import java.util.UUID;

public class DefaultAccountEmail extends UpdatableEntityBase implements AccountEmail {
    private final UUID accountId;
    private final String email;

    public DefaultAccountEmail(UUID accountId, String email) {
        super();
        this.accountId = accountId;
        this.email = email;
    }

    public DefaultAccountEmail(AccountEmail source, String newEmail) {
        this(source.getAccountId(), newEmail);
    }

    public DefaultAccountEmail(UUID id, UUID accountId, String email) {
        super(id);
        this.accountId = accountId;
        this.email = email;
    }

    @Override
    public UUID getAccountId() {
        return accountId;
    }

    @Override
    public String getEmail() {
        return email;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DefaultAccountEmail that = (DefaultAccountEmail) o;

        if (!accountId.equals(that.accountId)) return false;
        if (!email.equals(that.email)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = accountId.hashCode();
        result = 31 * result + email.hashCode();
        return result;
    }
}

@@ -656,16 +656,40 @@
 t.api;%0A%0A
+import java.util.UUID;%0A%0A
 import c
@@ -742,32 +742,8 @@
 e;%0A%0A
-import java.util.UUID;%0A%0A
 publ
@@ -919,24 +919,30 @@
 ccountEmail(
+final 
 UUID account
@@ -936,32 +936,38 @@
  UUID accountId,
+ final
  String email) %7B
@@ -1086,16 +1086,22 @@
 ntEmail(
+final 
 AccountE
@@ -1112,16 +1112,22 @@
  source,
+ final
  String 
@@ -1227,16 +1227,22 @@
 ail(
+final 
 UUID id,
  UUI
@@ -1237,16 +1237,22 @@
 UUID id,
+ final
  UUID ac
@@ -1259,16 +1259,22 @@
 countId,
+ final
  String 
@@ -1518,32 +1518,345 @@
 n email;%0A    %7D%0A%0A
+    @Override%0A    public String toString() %7B%0A        final StringBuilder sb = new StringBuilder();%0A        sb.append(%22DefaultAccountEmail%22);%0A        sb.append(%22%7BaccountId=%22).append(accountId);%0A        sb.append(%22, email='%22).append(email).append('%5C'');%0A        sb.append('%7D');%0A        return sb.toString();%0A    %7D%0A%0A
     @Override%0A  
@@ -1879,16 +1879,22 @@
  equals(
+final 
 Object o
@@ -1919,16 +1919,30 @@
 is == o)
+ %7B%0A           
  return 
@@ -1943,24 +1943,34 @@
 eturn true;%0A
+        %7D%0A
         if (
@@ -2009,16 +2009,30 @@
 Class())
+ %7B%0A           
  return 
@@ -2029,32 +2029,42 @@
    return false;
+%0A        %7D
 %0A%0A        Defaul
@@ -2057,16 +2057,22 @@
         
+final 
 DefaultA
@@ -2128,16 +2128,36 @@
     if (
+accountId != null ? 
 !account
@@ -2185,62 +2185,162 @@
 tId)
-) return false;%0A        if (!email.equals(that.email))
+ : that.accountId != null) %7B%0A            return false;%0A        %7D%0A        if (email != null ? !email.equals(that.email) : that.email != null) %7B%0A           
  ret
@@ -2349,16 +2349,26 @@
 n false;
+%0A        %7D
 %0A%0A      
@@ -2451,16 +2451,36 @@
 result =
+ accountId != null ?
  account
@@ -2484,32 +2484,36 @@
 untId.hashCode()
+ : 0
 ;%0A        result
@@ -2528,16 +2528,33 @@
 result +
+ (email != null ?
  email.h
@@ -2562,16 +2562,21 @@
 shCode()
+ : 0)
 ;%0A      

reformat DefaultAccountEmail