All Downloads are FREE. Search and download functionalities are using the official Maven repository.

redis.clients.jedis.params.Params Maven / Gradle / Ivy

The newest version!
package redis.clients.jedis.params;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import redis.clients.jedis.util.SafeEncoder;

public abstract class Params {

  private Map params;

  @SuppressWarnings("unchecked")
  public  T getParam(String name) {
    if (params == null) return null;

    return (T) params.get(name);
  }

  public byte[][] getByteParams() {
    ArrayList byteParams = new ArrayList();

    for (Entry param : params.entrySet()) {
      byteParams.add(SafeEncoder.encode(param.getKey()));
      if (param.getValue() != null) {
        byteParams.add(SafeEncoder.encode(String.valueOf(param.getValue())));
      }
    }

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

  protected boolean contains(String name) {
    if (params == null) return false;

    return params.containsKey(name);
  }

  protected void addParam(String name, Object value) {
    if (params == null) {
      params = new HashMap();
    }
    params.put(name, value);
  }

  protected void addParam(String name) {
    if (params == null) {
      params = new HashMap();
    }
    params.put(name, null);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy