package redis.clients.jedis.params.sortedset;

import redis.clients.jedis.params.Params;
import redis.clients.util.SafeEncoder;

import java.util.ArrayList;

public class ZIncrByParams extends Params {

  private static final String XX = "xx";
  private static final String NX = "nx";
  private static final String INCR = "incr";

  private ZIncrByParams() {
  }

  public static ZIncrByParams zIncrByParams() {
    return new ZIncrByParams();
  }

  /**
   * Only set the key if it does not already exist.
   * @return ZIncrByParams
   */
  public ZIncrByParams nx() {
    addParam(NX);
    return this;
  }

  /**
   * Only set the key if it already exist.
   * @return ZIncrByParams
   */
  public ZIncrByParams xx() {
    addParam(XX);
    return this;
  }

  public byte[][] getByteParams(byte[] key, byte[]... args) {
    ArrayList<byte[]> byteParams = new ArrayList<byte[]>();
    byteParams.add(key);

    if (contains(NX)) {
      byteParams.add(SafeEncoder.encode(NX));
    }
    if (contains(XX)) {
      byteParams.add(SafeEncoder.encode(XX));
    }

    byteParams.add(SafeEncoder.encode(INCR));

    for (byte[] arg : args) {
      byteParams.add(arg);
    }

    return byteParams.toArray(new byte[byteParams.size()][]);
  }

}

@@ -151,16 +151,517 @@
 yList;%0A%0A
+/**%0A * Parameters for ZINCRBY commands In fact, Redis doesn't have parameters for ZINCRBY. Instead Redis%0A * has INCR parameter for ZADD. When users call ZADD with INCR option, its restriction (only one%0A * member) and return type is same to ZINCRBY. Document page for ZADD also describes INCR option to%0A * act like ZINCRBY. http://redis.io/commands/zadd So we decided to wrap %22ZADD with INCR option%22 to%0A * ZINCRBY. https://github.com/xetorthio/jedis/issues/1067 Works with Redis 3.0.2 and onwards.%0A */%0A
 public c

add javadoc to ZIncrByParams