// Path: java/client/src/main/java/jp/co/rakuten/rit/roma/client/ClientException.java
// public class ClientException extends Exception {
//   private static final long serialVersionUID = -7032182229500031385L;
// 
//   public ClientException() {
//     super();
//   }
// 
//   public ClientException(Throwable cause) {
//     super(cause);
//   }
// 
//   public ClientException(String reason) {
//     super(reason);
//   }
// 
//   public ClientException(String reason, Throwable cause) {
//     super(reason, cause);
//   }
// }
// 
// Path: java/client/src/main/java/jp/co/rakuten/rit/roma/client/commands/CommandContext.java
// public class CommandContext extends HashMap<String, Object> {
//   private static final long serialVersionUID = 3317922575242590794L;
//   public static final String COMMAND_ID = "COMMAND_ID";
//   public static final String RESULT = "RESULT";
//   public static final String CONNECTION = "CONNECTION";
//   public static final String KEY = "KEY";
//   public static final String KEYS = "KEYS";
//   public static final String HASH_NAME = "HASH_NAME";
//   public static final String HASH = "HASH";
//   public static final String VALUE = "VALUE";
//   public static final String EXPIRY = "EXPIRY";
//   public static final String EXCEPTION = "EXCEPTION";
//   public static final String STRING_DATA = "STRING_DATA";
//   public static final String NODE = "NODE";
//   public static final String ROUTING_TABLE = "ROUTINGTABLE";
//   public static final String CONNECTION_POOL = "CONNECTIONPOOL";
//   public static final String CAS_ID = "CAS_ID";
// 
//   public CommandContext() {
//     super();
//   }
// 
//   @Override
//   public String toString() {
//     return super.toString();
//   }
// }


import jp.co.rakuten.rit.roma.client.ClientException;
import jp.co.rakuten.rit.roma.client.commands.CommandContext;

package jp.co.rakuten.rit.roma.client.util.commands;


public class SwapAndSizedPushCommand extends UpdateCommand {
  @Override
  protected void create(CommandContext context) throws ClientException {
    // alist_swap_and_sized_push <key> <array-size> <bytes>\r\n
    // <value>\r\n
    StringBuilder sb = (StringBuilder) context.get(CommandContext.STRING_DATA);
    sb.append(ListCommandID.STR_ALIST_SWAP_AND_SIZED_PUSH)
      .append(ListCommandID.STR_WHITE_SPACE)
      .append(context.get(CommandContext.KEY))
      .append(ListCommandID.STR_WHITE_SPACE)
      .append(context.get(UpdateCommand.ARRAY_SIZE)) // array-size
      .append(ListCommandID.STR_WHITE_SPACE)
      .append(((byte[]) context.get(CommandContext.VALUE)).length)
      .append(ListCommandID.STR_CRLF);
    context.put(CommandContext.STRING_DATA, sb);
  }

  @Override
  protected boolean parseResult(CommandContext context) throws ClientException {
    StringBuilder sb = (StringBuilder) context.get(CommandContext.STRING_DATA);
    String s = sb.toString();
    // STORED | NOT_STORED | SERVER_ERROR
    if (s.startsWith("STORED")) {
      return true;
    } else if (s.startsWith("NOT_STORED")) {
      return false;
    } else if (s.startsWith("NOT_PUSHED")) {
      return false;
    } else if (s.startsWith("SERVER_ERROR") || s.startsWith("CLIENT_ERROR")

// Path: java/client/src/main/java/jp/co/rakuten/rit/roma/client/ClientException.java
// public class ClientException extends Exception {
//   private static final long serialVersionUID = -7032182229500031385L;
// 
//   public ClientException() {
//     super();
//   }
// 
//   public ClientException(Throwable cause) {
//     super(cause);
//   }
// 
//   public ClientException(String reason) {
//     super(reason);
//   }
// 
//   public ClientException(String reason, Throwable cause) {
//     super(reason, cause);
//   }
// }
// 
// Path: java/client/src/main/java/jp/co/rakuten/rit/roma/client/commands/CommandContext.java
// public class CommandContext extends HashMap<String, Object> {
//   private static final long serialVersionUID = 3317922575242590794L;
//   public static final String COMMAND_ID = "COMMAND_ID";
//   public static final String RESULT = "RESULT";
//   public static final String CONNECTION = "CONNECTION";
//   public static final String KEY = "KEY";
//   public static final String KEYS = "KEYS";
//   public static final String HASH_NAME = "HASH_NAME";
//   public static final String HASH = "HASH";
//   public static final String VALUE = "VALUE";
//   public static final String EXPIRY = "EXPIRY";
//   public static final String EXCEPTION = "EXCEPTION";
//   public static final String STRING_DATA = "STRING_DATA";
//   public static final String NODE = "NODE";
//   public static final String ROUTING_TABLE = "ROUTINGTABLE";
//   public static final String CONNECTION_POOL = "CONNECTIONPOOL";
//   public static final String CAS_ID = "CAS_ID";
// 
//   public CommandContext() {
//     super();
//   }
// 
//   @Override
//   public String toString() {
//     return super.toString();
//   }
// }


// Path: java/client/src/main/java/jp/co/rakuten/rit/roma/client/util/commands/SwapAndSizedPushCommand.java
import jp.co.rakuten.rit.roma.client.ClientException;
import jp.co.rakuten.rit.roma.client.commands.CommandContext;

package jp.co.rakuten.rit.roma.client.util.commands;


public class SwapAndSizedPushCommand extends UpdateCommand {
  @Override
  protected void create(CommandContext context) throws ClientException {
    // alist_swap_and_sized_push <key> <array-size> <bytes>\r\n
    // <value>\r\n
    StringBuilder sb = (StringBuilder) context.get(CommandContext.STRING_DATA);
    sb.append(ListCommandID.STR_ALIST_SWAP_AND_SIZED_PUSH)
      .append(ListCommandID.STR_WHITE_SPACE)
      .append(context.get(CommandContext.KEY))
      .append(ListCommandID.STR_WHITE_SPACE)
      .append(context.get(UpdateCommand.ARRAY_SIZE)) // array-size
      .append(ListCommandID.STR_WHITE_SPACE)
      .append(((byte[]) context.get(CommandContext.VALUE)).length)
      .append(ListCommandID.STR_CRLF);
    context.put(CommandContext.STRING_DATA, sb);
  }

  @Override
  protected boolean parseResult(CommandContext context) throws ClientException {
    StringBuilder sb = (StringBuilder) context.get(CommandContext.STRING_DATA);
    String s = sb.toString();
    // STORED | NOT_STORED | SERVER_ERROR
    if (s.startsWith("STORED")) {
      return true;
    } else if (s.startsWith("NOT_STORED")) {
      return false;
    } else if (s.startsWith("NOT_PUSHED")) {
      return false;
    } else if (s.startsWith("SERVER_ERROR") || s.startsWith("CLIENT_ERROR")

        || s.startsWith("ERROR")) {
