package com.rollbar.payload.data;

import com.rollbar.payload.utilities.ArgumentNullException;
import com.rollbar.payload.utilities.InvalidLengthException;
import com.rollbar.payload.utilities.Validate;

public class Person {
    private final String id;
    private final String username;
    private final String email;

    public Person(String id) throws ArgumentNullException {
        Validate.isNotNullOrWhitespace(id, "id");
        this.id = id;
        username = null;
        email = null;
    }

    public Person(String id, String username, String email) throws InvalidLengthException, ArgumentNullException {
        Validate.isNotNullOrWhitespace(id, "id");
        this.id = id;
        if (username != null) {
            Validate.maxLength(username, 255, "username");
        }
        this.username = username;
        if (email != null) {
            Validate.maxLength(email, 255, "email");
        }
        this.email = email;
    }

    public String id() {
        return this.id;
    }

    public Person id(String id) throws ArgumentNullException {
        try {
            return new Person(id, username, email);
        } catch (InvalidLengthException e) {
            throw new IllegalStateException("username isn't changing, so this error shouldn't occur");
        }
    }

    public String username() {
        return this.username;
    }

    public Person username(String username) throws InvalidLengthException {
        try {
            return new Person(id, username, email);
        } catch (ArgumentNullException e) {
            throw new IllegalStateException("id can't be null");
        }
    }

    public String email() {
        return this.email;
    }

    public Person email(String email) {
        try {
            return new Person(id, username, email);
        } catch (ArgumentNullException e) {
            throw new IllegalStateException("id can't be null");
        } catch (InvalidLengthException e) {
            throw new IllegalStateException("username can't be the wrong length");
        }
    }
}

@@ -197,16 +197,68 @@
 idate;%0A%0A
+/**%0A * Represents the user affected by an error%0A */%0A
 public c
@@ -368,16 +368,150 @@
 email;%0A%0A
+    /**%0A     * Constructor%0A     * @param id the affected user's id%0A     * @throws ArgumentNullException if %7B@code id%7D is null%0A     */%0A
     publ
@@ -680,32 +680,373 @@
  = null;%0A    %7D%0A%0A
+    /**%0A     * Constructor%0A     * @param id the affected user's id%0A     * @param username the affected user's username%0A     * @param email the affected user's email address%0A     * @throws InvalidLengthException if %7B@code username%7D or %7B@code email%7D are longer than 255 characters%0A     * @throws ArgumentNullException if %7B@id%7D is null%0A     */%0A
     public Perso
@@ -1470,32 +1470,86 @@
 = email;%0A    %7D%0A%0A
+    /**%0A     * @return the affected user's id%0A     */%0A
     public Strin
@@ -1584,32 +1584,231 @@
 .id;%0A    %7D%0A%0A    
+/**%0A     * Set the id on a copy of this Person%0A     * @param id the new id%0A     * @return a copy of this person with the new id%0A     * @throws ArgumentNullException if %7B@code id%7D is null%0A     */%0A    
 public Person id
@@ -1850,34 +1850,16 @@
 ption %7B%0A
-        try %7B%0A    
         
@@ -1906,45 +1906,98 @@
     
+%7D%0A%0A
     
-%7D catch (InvalidLengthException e
+/**%0A     * @return the affected user's username%0A     */%0A    public String username(
 ) %7B%0A
@@ -2008,137 +2008,183 @@
     
- 
-   throw new IllegalStateException(%22username isn't changing, so
+return this.username;%0A    %7D%0A%0A    /**%0A     * Set the username on a copy of
  this 
+P
 er
-ror shouldn't occur%22);%0A        %7D%0A    %7D%0A%0A    public String
+son%0A     * @param username the new username%0A     * @return a copy of this person with the new
  use
@@ -2192,49 +2192,104 @@
 name
-() %7B
 %0A     
-   return this.username;
+* @throws InvalidLengthException if %7B@code username%7D is longer than 255 characters
 %0A    
-%7D%0A
+ */
 %0A   
@@ -2361,34 +2361,16 @@
 ption %7B%0A
-        try %7B%0A    
         
@@ -2417,424 +2417,398 @@
     
-    %7D catch (ArgumentNullException e) %7B%0A            throw new IllegalStateException(%22id can't be null%22);%0A        %7D%0A    %7D%0A%0A    public String email() %7B%0A        return this.email;%0A    %7D%0A%0A    public Person email(String email) %7B%0A        try %7B%0A       
+%7D%0A%0A    /**%0A     * @return the affected user's email%0A     */%0A    public String email() %7B%0A        return this.email;%0A    %7D%0A%0A    /**%0A     * Set the email on a copy of this Person%0A     * @param email%0A
      
+* @
 return 
-new Person(id, username,
+a copy of this person with the new
  email
-);
 %0A     
-   %7D catch (ArgumentNullException e) %7B%0A            throw new IllegalStateException(%22id can't be null%22);%0A        %7D catch (
+* @throws InvalidLengthException if %7B@code email%7D is longer than 255 characters%0A     */%0A    public Person email(String email) throws 
 Inva
@@ -2830,23 +2830,18 @@
 ion 
-e) %7B%0A  
+%7B%0A
         
   th
@@ -2840,90 +2840,47 @@
     
-  throw new IllegalStateException(%22username can't be the wrong length%22);%0A        %7D
+return new Person(id, username, email);
 %0A   

FIx Person checked exceptoins, and document