package com.truphone.cascades.commands;


/**
 * Check and control ListViews
 * @author STruscott
 *
 */
public class ListCommand extends DefaultCommand {
	
	private final String _payload;
	
	/**
	 * Supported indexing modes
	 * @author STruscott
	 *
	 */
	public enum IndexingMode {
		INDEX,
		NAME;
		
		/**
		 * Convert the attribute to a string
		 * @return The name of the attribute
		 */
		public String asString() {
			final String v;
			switch(this) {
			case INDEX:
				v = "index";
				break;
			case NAME:
				v = "name";
				break;
			default:
				v = "unsupported";
				break;
			}
			return v;
		}
	}
	
	/**
	 * Create a command to check the size of the list
	 * @param listView_ The list view to check
	 * @param expectedCount_ The expected count
	 */
	public ListCommand(final String listView_, final int expectedCount_) {
		super("");
		this._payload = "list " + listView_ + " count " + expectedCount_;
	}
	
	/**
	 * Create a check for an expected value
	 * @param listView_ The listview to check
	 * @param indexMode The index mode (numeric, name)
	 * @param indexPath The path (0~1~2, S~Sam Truscott^)
	 * @param expectedValue The expected value (Susan Boyle)
	 */
	public ListCommand(
			final String listView_,
			final IndexingMode indexMode,
			final String indexPath,
			final String expectedValue) {
		super("");
		final StringBuilder builder = new StringBuilder();
		builder.append("list ");
		builder.append(listView_);
		builder.append(' ');
		builder.append(indexMode.asString());
		builder.append(' ');
		builder.append(indexPath);
		builder.append(' ');
		builder.append(expectedValue);
		
		this._payload = builder.toString();
	}
	
	/**
	 * Create a check for an expected value
	 * @param listView_ The listview to check
	 * @param indexMode The index mode (numeric, name)
	 * @param indexPath The path (0~1~2, S~Sam Truscott^)
	 * @param expectedKey_ The expected value (Name)
	 * @param expectedValue The expected value (Susan Boyle^)
	 */
	public ListCommand(
			final String listView_,
			final IndexingMode indexMode_,
			final String indexPath_,
			final String expectedKey_,
			final String expectedValue_) {
		super("");
		final StringBuilder builder = new StringBuilder();
		builder.append("list ");
		builder.append(listView_);
		builder.append(' ');
		builder.append(indexMode_.asString());
		builder.append(' ');
		builder.append(indexPath_);
		builder.append(' ');
		builder.append(expectedKey_);
		builder.append('=');
		builder.append(expectedValue_);
		
		this._payload = builder.toString();
	}
	
	@Override
    public String getPayload() {
        return this._payload;
    }
	
	public static final class ListSelectCommand extends DefaultCommand {
		
		private final String _payload;
		/**
		 * Select an index on a list
		 * @param listView_ The listview to check
		 * @param indexMode The index mode (numeric, name)
		 * @param indexPath The path (0~1~2, S~Sam Truscott^)
		 * @param expectedValue The expected value (Susan Boyle)
		 */
		public ListSelectCommand(
				final String listView_,
				final IndexingMode indexMode,
				final String indexPath,
				final boolean select) {
			super("");
			final StringBuilder builder = new StringBuilder();
			builder.append("list ");
			builder.append(listView_);
			if (select) {
				builder.append(" select ");
			} else {
				builder.append(" unselect ");
			}
			builder.append(indexMode.asString());
			builder.append(' ');
			builder.append(indexPath);
			
			this._payload = builder.toString();
		}
		
		@Override
	    public String getPayload() {
	        return this._payload;
	    }
	}
	
	public static final class ListScrollCommand extends DefaultCommand {
		
		private final String _payload;
		/**
		 * Scroll to an index on a list
		 * @param listView_ The listview to check
		 * @param indexMode The index mode (numeric, name)
		 * @param indexPath The path (0~1~2, S~Sam Truscott^)
		 * @param expectedValue The expected value (Susan Boyle)
		 */
		public ListScrollCommand(
				final String listView_,
				final IndexingMode indexMode,
				final String indexPath) {
			super("");
			final StringBuilder builder = new StringBuilder();
			builder.append("list ");
			builder.append(listView_);
			builder.append(" scroll ");
			builder.append(indexMode.asString());
			builder.append(' ');
			builder.append(indexPath);
			
			this._payload = builder.toString();
		}
		
		@Override
	    public String getPayload() {
	        return this._payload;
	    }
	}
}

@@ -2932,54 +2932,67 @@
 ram 
-expectedValue The expected value (Susan Boyle)
+select_ True if it's a selection and false if a deselection
 %0A%09%09 
@@ -3074,32 +3074,33 @@
 ngMode indexMode
+_
 ,%0A%09%09%09%09final Stri
@@ -3107,24 +3107,25 @@
 ng indexPath
+_
 ,%0A%09%09%09%09final 
@@ -3134,24 +3134,25 @@
 olean select
+_
 ) %7B%0A%09%09%09super
@@ -3282,16 +3282,17 @@
  (select
+_
 ) %7B%0A%09%09%09%09
@@ -3389,32 +3389,33 @@
 append(indexMode
+_
 .asString());%0A%09%09
@@ -3455,32 +3455,33 @@
 append(indexPath
+_
 );%0A%09%09%09%0A%09%09%09this._
@@ -3809,32 +3809,33 @@
 @param indexMode
+_
  The index mode 
@@ -3863,32 +3863,33 @@
 @param indexPath
+_
  The path (0~1~2
@@ -3911,67 +3911,8 @@
 t%5E)%0A
-%09%09 * @param expectedValue The expected value (Susan Boyle)%0A
 %09%09 *
@@ -3997,24 +3997,25 @@
 de indexMode
+_
 ,%0A%09%09%09%09final 
@@ -4030,16 +4030,17 @@
 ndexPath
+_
 ) %7B%0A%09%09%09s
@@ -4211,32 +4211,33 @@
 append(indexMode
+_
 .asString());%0A%09%09
@@ -4281,24 +4281,25 @@
 nd(indexPath
+_
 );%0A%09%09%09%0A%09%09%09th

Fix the docs on the List command.