com.clover.sdk.v3.customers.Customer.java Source code

Java tutorial

Introduction

Here is the source code for com.clover.sdk.v3.customers.Customer.java

Source

/**
 * Copyright (C) 2015 Clover Network, Inc.
 *
 * Licensed 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.
 */
/**
 * Autogenerated by Avro
 * 
 * DO NOT EDIT DIRECTLY
 */

package com.clover.sdk.v3.customers;

import com.clover.sdk.GenericClient;

@SuppressWarnings("all")
public final class Customer
        implements android.os.Parcelable, com.clover.sdk.v3.Validator, com.clover.sdk.JSONifiable {

    /**
     * Unique identifier
     */
    public java.lang.String getId() {
        return genClient.cacheGet(CacheKey.id);
    }

    /**
     * First/given name of the customer
     */
    public java.lang.String getFirstName() {
        return genClient.cacheGet(CacheKey.firstName);
    }

    /**
     * Last name/surname of the customer
     */
    public java.lang.String getLastName() {
        return genClient.cacheGet(CacheKey.lastName);
    }

    public java.lang.Boolean getMarketingAllowed() {
        return genClient.cacheGet(CacheKey.marketingAllowed);
    }

    public java.lang.Long getCustomerSince() {
        return genClient.cacheGet(CacheKey.customerSince);
    }

    public java.util.List<com.clover.sdk.v3.base.Reference> getOrders() {
        return genClient.cacheGet(CacheKey.orders);
    }

    public java.util.List<com.clover.sdk.v3.customers.Address> getAddresses() {
        return genClient.cacheGet(CacheKey.addresses);
    }

    public java.util.List<com.clover.sdk.v3.customers.EmailAddress> getEmailAddresses() {
        return genClient.cacheGet(CacheKey.emailAddresses);
    }

    public java.util.List<com.clover.sdk.v3.customers.PhoneNumber> getPhoneNumbers() {
        return genClient.cacheGet(CacheKey.phoneNumbers);
    }

    private enum CacheKey implements com.clover.sdk.ValueExtractorEnum<Customer> {
        id {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractOther("id", java.lang.String.class);
            }
        },
        firstName {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractOther("firstName", java.lang.String.class);
            }
        },
        lastName {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractOther("lastName", java.lang.String.class);
            }
        },
        marketingAllowed {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractOther("marketingAllowed", java.lang.Boolean.class);
            }
        },
        customerSince {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractOther("customerSince", java.lang.Long.class);
            }
        },
        orders {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractListRecord("orders",
                        com.clover.sdk.v3.base.Reference.JSON_CREATOR);
            }
        },
        addresses {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractListRecord("addresses",
                        com.clover.sdk.v3.customers.Address.JSON_CREATOR);
            }
        },
        emailAddresses {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractListRecord("emailAddresses",
                        com.clover.sdk.v3.customers.EmailAddress.JSON_CREATOR);
            }
        },
        phoneNumbers {
            @Override
            public Object extractValue(Customer instance) {
                return instance.genClient.extractListRecord("phoneNumbers",
                        com.clover.sdk.v3.customers.PhoneNumber.JSON_CREATOR);
            }
        },;
    }

    private GenericClient<Customer> genClient = new GenericClient<Customer>(this);

    /**
     * Constructs a new empty instance.
     */
    public Customer() {
    }

    /**
     * Constructs a new instance from the given JSON String.
     */
    public Customer(String json) throws IllegalArgumentException {
        try {
            genClient.setJsonObject(new org.json.JSONObject(json));
        } catch (org.json.JSONException e) {
            throw new IllegalArgumentException("invalid json", e);
        }
    }

    /**
     * Construct a new instance backed by the given JSONObject, the parameter is not copied so changes to it will be
     * reflected in this instance and vice-versa.
     */
    public Customer(org.json.JSONObject jsonObject) {
        genClient.setJsonObject(jsonObject);
    }

    /**
     * Constructs a new instance that is a deep copy of the source instance. It does not copy the bundle or changelog.
     */
    public Customer(Customer src) {
        if (src.genClient.getJsonObject() != null) {
            genClient.setJsonObject(com.clover.sdk.v3.JsonHelper.deepCopy(src.genClient.getJSONObject()));
        }
    }

    /**
     * Returns the internal JSONObject backing this instance, the return value is not a copy so changes to it will be
     * reflected in this instance and vice-versa.
     */
    public org.json.JSONObject getJSONObject() {
        return genClient.getJSONObject();
    }

    @Override
    public void validate() {
        genClient.validateLength(getId(), 13);

        genClient.validateLength(getFirstName(), 64);

        genClient.validateLength(getLastName(), 64);
    }

    /** Checks whether the 'id' field is set and is not null */
    public boolean isNotNullId() {
        return genClient.cacheValueIsNotNull(CacheKey.id);
    }

    /** Checks whether the 'firstName' field is set and is not null */
    public boolean isNotNullFirstName() {
        return genClient.cacheValueIsNotNull(CacheKey.firstName);
    }

    /** Checks whether the 'lastName' field is set and is not null */
    public boolean isNotNullLastName() {
        return genClient.cacheValueIsNotNull(CacheKey.lastName);
    }

    /** Checks whether the 'marketingAllowed' field is set and is not null */
    public boolean isNotNullMarketingAllowed() {
        return genClient.cacheValueIsNotNull(CacheKey.marketingAllowed);
    }

    /** Checks whether the 'customerSince' field is set and is not null */
    public boolean isNotNullCustomerSince() {
        return genClient.cacheValueIsNotNull(CacheKey.customerSince);
    }

    /** Checks whether the 'orders' field is set and is not null */
    public boolean isNotNullOrders() {
        return genClient.cacheValueIsNotNull(CacheKey.orders);
    }

    /** Checks whether the 'orders' field is set and is not null and is not empty */
    public boolean isNotEmptyOrders() {
        return isNotNullOrders() && !getOrders().isEmpty();
    }

    /** Checks whether the 'addresses' field is set and is not null */
    public boolean isNotNullAddresses() {
        return genClient.cacheValueIsNotNull(CacheKey.addresses);
    }

    /** Checks whether the 'addresses' field is set and is not null and is not empty */
    public boolean isNotEmptyAddresses() {
        return isNotNullAddresses() && !getAddresses().isEmpty();
    }

    /** Checks whether the 'emailAddresses' field is set and is not null */
    public boolean isNotNullEmailAddresses() {
        return genClient.cacheValueIsNotNull(CacheKey.emailAddresses);
    }

    /** Checks whether the 'emailAddresses' field is set and is not null and is not empty */
    public boolean isNotEmptyEmailAddresses() {
        return isNotNullEmailAddresses() && !getEmailAddresses().isEmpty();
    }

    /** Checks whether the 'phoneNumbers' field is set and is not null */
    public boolean isNotNullPhoneNumbers() {
        return genClient.cacheValueIsNotNull(CacheKey.phoneNumbers);
    }

    /** Checks whether the 'phoneNumbers' field is set and is not null and is not empty */
    public boolean isNotEmptyPhoneNumbers() {
        return isNotNullPhoneNumbers() && !getPhoneNumbers().isEmpty();
    }

    /** Checks whether the 'id' field has been set, however the value could be null */
    public boolean hasId() {
        return genClient.cacheHasKey(CacheKey.id);
    }

    /** Checks whether the 'firstName' field has been set, however the value could be null */
    public boolean hasFirstName() {
        return genClient.cacheHasKey(CacheKey.firstName);
    }

    /** Checks whether the 'lastName' field has been set, however the value could be null */
    public boolean hasLastName() {
        return genClient.cacheHasKey(CacheKey.lastName);
    }

    /** Checks whether the 'marketingAllowed' field has been set, however the value could be null */
    public boolean hasMarketingAllowed() {
        return genClient.cacheHasKey(CacheKey.marketingAllowed);
    }

    /** Checks whether the 'customerSince' field has been set, however the value could be null */
    public boolean hasCustomerSince() {
        return genClient.cacheHasKey(CacheKey.customerSince);
    }

    /** Checks whether the 'orders' field has been set, however the value could be null */
    public boolean hasOrders() {
        return genClient.cacheHasKey(CacheKey.orders);
    }

    /** Checks whether the 'addresses' field has been set, however the value could be null */
    public boolean hasAddresses() {
        return genClient.cacheHasKey(CacheKey.addresses);
    }

    /** Checks whether the 'emailAddresses' field has been set, however the value could be null */
    public boolean hasEmailAddresses() {
        return genClient.cacheHasKey(CacheKey.emailAddresses);
    }

    /** Checks whether the 'phoneNumbers' field has been set, however the value could be null */
    public boolean hasPhoneNumbers() {
        return genClient.cacheHasKey(CacheKey.phoneNumbers);
    }

    /**
     * Sets the field 'id'.
     */
    public Customer setId(java.lang.String id) {
        return genClient.setOther(id, CacheKey.id);
    }

    /**
     * Sets the field 'firstName'.
     */
    public Customer setFirstName(java.lang.String firstName) {
        return genClient.setOther(firstName, CacheKey.firstName);
    }

    /**
     * Sets the field 'lastName'.
     */
    public Customer setLastName(java.lang.String lastName) {
        return genClient.setOther(lastName, CacheKey.lastName);
    }

    /**
     * Sets the field 'marketingAllowed'.
     */
    public Customer setMarketingAllowed(java.lang.Boolean marketingAllowed) {
        return genClient.setOther(marketingAllowed, CacheKey.marketingAllowed);
    }

    /**
     * Sets the field 'customerSince'.
     */
    public Customer setCustomerSince(java.lang.Long customerSince) {
        return genClient.setOther(customerSince, CacheKey.customerSince);
    }

    /**
     * Sets the field 'orders'.
     *
     * Nulls in the given List are skipped. List parameter is copied, so it will not reflect any changes, but objects inside it will.
     */
    public Customer setOrders(java.util.List<com.clover.sdk.v3.base.Reference> orders) {
        return genClient.setArrayRecord(orders, CacheKey.orders);
    }

    /**
     * Sets the field 'addresses'.
     *
     * Nulls in the given List are skipped. List parameter is copied, so it will not reflect any changes, but objects inside it will.
     */
    public Customer setAddresses(java.util.List<com.clover.sdk.v3.customers.Address> addresses) {
        return genClient.setArrayRecord(addresses, CacheKey.addresses);
    }

    /**
     * Sets the field 'emailAddresses'.
     *
     * Nulls in the given List are skipped. List parameter is copied, so it will not reflect any changes, but objects inside it will.
     */
    public Customer setEmailAddresses(java.util.List<com.clover.sdk.v3.customers.EmailAddress> emailAddresses) {
        return genClient.setArrayRecord(emailAddresses, CacheKey.emailAddresses);
    }

    /**
     * Sets the field 'phoneNumbers'.
     *
     * Nulls in the given List are skipped. List parameter is copied, so it will not reflect any changes, but objects inside it will.
     */
    public Customer setPhoneNumbers(java.util.List<com.clover.sdk.v3.customers.PhoneNumber> phoneNumbers) {
        return genClient.setArrayRecord(phoneNumbers, CacheKey.phoneNumbers);
    }

    /** Clears the 'id' field, the 'has' method for this field will now return false */
    public void clearId() {
        genClient.clear(CacheKey.id);
    }

    /** Clears the 'firstName' field, the 'has' method for this field will now return false */
    public void clearFirstName() {
        genClient.clear(CacheKey.firstName);
    }

    /** Clears the 'lastName' field, the 'has' method for this field will now return false */
    public void clearLastName() {
        genClient.clear(CacheKey.lastName);
    }

    /** Clears the 'marketingAllowed' field, the 'has' method for this field will now return false */
    public void clearMarketingAllowed() {
        genClient.clear(CacheKey.marketingAllowed);
    }

    /** Clears the 'customerSince' field, the 'has' method for this field will now return false */
    public void clearCustomerSince() {
        genClient.clear(CacheKey.customerSince);
    }

    /** Clears the 'orders' field, the 'has' method for this field will now return false */
    public void clearOrders() {
        genClient.clear(CacheKey.orders);
    }

    /** Clears the 'addresses' field, the 'has' method for this field will now return false */
    public void clearAddresses() {
        genClient.clear(CacheKey.addresses);
    }

    /** Clears the 'emailAddresses' field, the 'has' method for this field will now return false */
    public void clearEmailAddresses() {
        genClient.clear(CacheKey.emailAddresses);
    }

    /** Clears the 'phoneNumbers' field, the 'has' method for this field will now return false */
    public void clearPhoneNumbers() {
        genClient.clear(CacheKey.phoneNumbers);
    }

    /**
     * Returns true if this instance has any changes.
     */
    public boolean containsChanges() {
        return genClient.containsChanges();
    }

    /**
     * Reset the log of changes made to this instance, calling copyChanges() after this would return an empty instance.
     */
    public void resetChangeLog() {
        genClient.resetChangeLog();
    }

    /**
     * Create a copy of this instance that contains only fields that were set after the constructor was called.
     */
    public Customer copyChanges() {
        Customer copy = new Customer();
        copy.mergeChanges(this);
        copy.resetChangeLog();
        return copy;
    }

    /**
     * Copy all the changed fields from the given source to this instance.
     */
    public void mergeChanges(Customer src) {
        if (src.genClient.getChangeLog() != null) {
            genClient.mergeChanges(new Customer(src).getJSONObject(), src.genClient);
        }
    }

    /**
     * Gets a Bundle which can be used to get and set data attached to this instance. The attached Bundle will be
     * parcelled but not jsonified.
     */
    public android.os.Bundle getBundle() {
        return genClient.getBundle();
    }

    @Override
    public String toString() {
        return genClient.toString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(android.os.Parcel dest, int flags) {
        genClient.writeToParcel(dest, flags);
    }

    public static final android.os.Parcelable.Creator<Customer> CREATOR = new android.os.Parcelable.Creator<Customer>() {
        @Override
        public Customer createFromParcel(android.os.Parcel in) {
            Customer instance = new Customer(
                    com.clover.sdk.v3.JsonParcelHelper.ObjectWrapper.CREATOR.createFromParcel(in).unwrap());
            instance.genClient.setBundle(in.readBundle(getClass().getClassLoader()));
            instance.genClient.setChangeLog(in.readBundle());
            return instance;
        }

        @Override
        public Customer[] newArray(int size) {
            return new Customer[size];
        }
    };

    public static final com.clover.sdk.JSONifiable.Creator<Customer> JSON_CREATOR = new com.clover.sdk.JSONifiable.Creator<Customer>() {
        @Override
        public Customer create(org.json.JSONObject jsonObject) {
            return new Customer(jsonObject);
        }
    };

    public interface Constraints {

        public static final boolean ID_IS_REQUIRED = false;
        public static final long ID_MAX_LEN = 13;

        public static final boolean FIRSTNAME_IS_REQUIRED = false;
        public static final long FIRSTNAME_MAX_LEN = 64;

        public static final boolean LASTNAME_IS_REQUIRED = false;
        public static final long LASTNAME_MAX_LEN = 64;

        public static final boolean MARKETINGALLOWED_IS_REQUIRED = false;

        public static final boolean CUSTOMERSINCE_IS_REQUIRED = false;

        public static final boolean ORDERS_IS_REQUIRED = false;

        public static final boolean ADDRESSES_IS_REQUIRED = false;

        public static final boolean EMAILADDRESSES_IS_REQUIRED = false;

        public static final boolean PHONENUMBERS_IS_REQUIRED = false;

    }

}