package redis.clients.jedis.params.sortedset;

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

import java.util.ArrayList;

/**
 * Parameters for ZINCRBY commands In fact, Redis doesn't have parameters for ZINCRBY. Instead Redis
 * has INCR parameter for ZADD. When users call ZADD with INCR option, its restriction (only one
 * member) and return type is same to ZINCRBY. Document page for ZADD also describes INCR option to
 * act like ZINCRBY. http://redis.io/commands/zadd So we decided to wrap "ZADD with INCR option" to
 * ZINCRBY. https://github.com/xetorthio/jedis/issues/1067 Works with Redis 3.0.2 and onwards.
 */
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()][]);
  }

}

@@ -189,16 +189,34 @@
 commands
+ %3Cbr/%3E%0A * %3Cbr/%3E%0A *
  In fact
@@ -273,19 +273,16 @@
 ad Redis
-%0A *
  has INC
@@ -302,16 +302,24 @@
 or ZADD.
+%3Cbr/%3E%0A *
  When us
@@ -375,19 +375,16 @@
 only one
-%0A *
  member)
@@ -407,16 +407,19 @@
  is same
+%0A *
  to ZINC
@@ -422,16 +422,25 @@
 ZINCRBY.
+ %3Cbr/%3E%0A *
  Documen
@@ -484,19 +484,16 @@
 ption to
-%0A *
  act lik
@@ -498,24 +498,33 @@
 ike ZINCRBY.
+ %3Cbr/%3E%0A *
  http://redi
@@ -541,16 +541,34 @@
 nds/zadd
+ %3Cbr/%3E%0A * %3Cbr/%3E%0A *
  So we d
@@ -608,19 +608,16 @@
 tion%22 to
-%0A *
  ZINCRBY
@@ -617,16 +617,25 @@
 ZINCRBY.
+ %3Cbr/%3E%0A *
  https:/
@@ -673,16 +673,34 @@
 ues/1067
+ %3Cbr/%3E%0A * %3Cbr/%3E%0A *
  Works w

fix formatting to javadoc for ZIncrByParams