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");
        }
    }
}

package com.rollbar.payload.data;

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

/**
 * Represents the user affected by an error
 */
public class Person {
    private final String id;
    private final String username;
    private final String email;

    /**
     * Constructor
     * @param id the affected user's id
     * @throws ArgumentNullException if {@code id} is null
     */
    public Person(String id) throws ArgumentNullException {
        Validate.isNotNullOrWhitespace(id, "id");
        this.id = id;
        username = null;
        email = null;
    }

    /**
     * Constructor
     * @param id the affected user's id
     * @param username the affected user's username
     * @param email the affected user's email address
     * @throws InvalidLengthException if {@code username} or {@code email} are longer than 255 characters
     * @throws ArgumentNullException if {@id} is 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;
    }

    /**
     * @return the affected user's id
     */
    public String id() {
        return this.id;
    }

    /**
     * Set the id on a copy of this Person
     * @param id the new id
     * @return a copy of this person with the new id
     * @throws ArgumentNullException if {@code id} is null
     */
    public Person id(String id) throws ArgumentNullException {
        return new Person(id, username, email);
    }

    /**
     * @return the affected user's username
     */
    public String username() {
        return this.username;
    }

    /**
     * Set the username on a copy of this Person
     * @param username the new username
     * @return a copy of this person with the new username
     * @throws InvalidLengthException if {@code username} is longer than 255 characters
     */
    public Person username(String username) throws InvalidLengthException {
        return new Person(id, username, email);
    }

    /**
     * @return the affected user's email
     */
    public String email() {
        return this.email;
    }

    /**
     * Set the email on a copy of this Person
     * @param email
     * @return a copy of this person with the new email
     * @throws InvalidLengthException if {@code email} is longer than 255 characters
     */
    public Person email(String email) throws InvalidLengthException {
        return new Person(id, username, email);
    }
}

FIx Person checked exceptoins, and document