package com.douglaswhitehead.model.digitaldata.privacy;

import java.util.ArrayList;
import java.util.List;

/**
 * Implementation of the Privacy interface.
 * 
 * @author douglas.whitehead
 *
 */
public class PrivacyImpl implements Privacy {
	
	/**
	 * Variable for DEFAULT_ACCESS_CATEGORY object.
	 */
	private final static AccessCategory DEFAULT_ACCESS_CATEGORY = new AccessCategoryImpl.Builder()
																		.categoryName("Default")
																		.domains(new String[]{"*"})
																	.build();
	
	/**
	 * Variable for <tt>accessCategories</tt> object.
	 */
	//private List<AccessCategory> accessCategories = new ArrayList<AccessCategory>();
	private AccessCategory accessCategories[];
	
	/**
	 * PrivacyImpl constructor.
	 * 
	 * @param accessCategories
	 */
	private PrivacyImpl(
		final AccessCategory[] accessCategories
	) {
		/*this.accessCategories.clear();
		for (AccessCategory accessCategory: accessCategories) {
			this.accessCategories.add(accessCategory);
		}*/
		this.accessCategories = accessCategories;
	}
	
	/**
	 * Returns the AccessCategory[] array.
	 * 
	 * @return AccessCategory[]
	 */
	@Override
	public AccessCategory[] getAccessCategories() {
		//return accessCategories.toArray(new AccessCategory[accessCategories.size()]);
		return accessCategories;
	}
	
	/**
	 * Implementation of the Privacy.Builder interface.
	 * 
	 * @author douglas.whitehead
	 *
	 */
	public static class Builder implements Privacy.Builder {
		
		/**
		 * Variable for <tt>accessCategories</tt> array.
		 */
		private AccessCategory[] accessCategories;
		
		/**
		 * Builds the AccessCategory[] array.
		 * 
		 * @param AccessCategory[] accessCategories
		 * @return Builder
		 */
		@Override
		public Builder accessCategories(
			final AccessCategory[] accessCategories
		) {
			this.accessCategories = safeguardDefaultAccessCategory(accessCategories);
			return builder();
		}
		
		/**
		 * Builds and returns the PrivacyImpl object.
		 * 
		 * @return PrivacyImpl
		 */
		@Override
		public PrivacyImpl build() {
			return new PrivacyImpl(
				accessCategories
			);
		}
		
		/**
		 * Ensures the DEFAULT_ACCESS_CATEGORY object is added to the AccessCategory[] array.
		 * 
		 * @param AccessCategory[] accessCategories
		 * @return AccessCategory[]
		 */
		private AccessCategory[] safeguardDefaultAccessCategory(final AccessCategory[] accessCategories) {
			List<AccessCategory> _accessCategories = new ArrayList<AccessCategory>();
			for (AccessCategory accessCategory: accessCategories) {
				_accessCategories.add(accessCategory);
			}
			_accessCategories.add(DEFAULT_ACCESS_CATEGORY);
			return _accessCategories.toArray(new AccessCategory[_accessCategories.size()]);
		}
		
		/**
		 * Returns the Builder.
		 * 
		 * @return Builder
		 */
		private Builder builder() {
			return this;
		}
		
	}	

}

@@ -1821,39 +1821,8 @@
 s = 
-safeguardDefaultAccessCategory(
 acce
@@ -1833,17 +1833,16 @@
 tegories
-)
 ;%0A%09%09%09ret
@@ -2028,16 +2028,47 @@
 pl(%0A%09%09%09%09
+safeguardDefaultAccessCategory(
 accessCa
@@ -2075,16 +2075,17 @@
 tegories
+)
 %0A%09%09%09);%0A%09
@@ -2450,16 +2450,52 @@
 ory%3E();%0A
+%09%09%09if (accessCategories != null) %7B%0A%09
 %09%09%09for (
@@ -2549,16 +2549,17 @@
 ) %7B%0A%09%09%09%09
+%09
 _accessC
@@ -2589,16 +2589,22 @@
 egory);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%09

Update to PrivacyImpl class.