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

com.aliyun.tair.tairbloom.params.BfinsertParams Maven / Gradle / Ivy

Go to download

Aliyun Tair Redis client for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 3.0.9
Show newest version
package com.aliyun.tair.tairbloom.params;

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

import java.util.ArrayList;

public class BfinsertParams extends Params {
    private static final String CAPACITY = "CAPACITY";
    private static final String ERROR = "ERROR";
    private static final String NOCREATE = "NOCREATE";
    private static final String ITEMS = "ITEMS";

    public BfinsertParams() {
    }

    public static BfinsertParams BfinsertParams() {
        return new BfinsertParams();
    }

    public BfinsertParams capacity(long initCapacity) {
        addParam(CAPACITY, initCapacity);
        return this;
    }

    public BfinsertParams error(double errorRate) {
        addParam(ERROR, errorRate);
        return this;
    }

    public BfinsertParams nocreate() {
        addParam(NOCREATE);
        return this;
    }

    private void addParamWithValue(ArrayList byteParams, String option) {
        if (contains(option)) {
            byteParams.add(SafeEncoder.encode(option));
            byteParams.add(SafeEncoder.encode(String.valueOf((Object)getParam(option))));
        }
    }

    public byte[][] getByteParamsMeta(String key, String... meta) {
        ArrayList byteParamsMeta = new ArrayList();
        byteParamsMeta.add(SafeEncoder.encode(key));
        for (String s : meta) {
            byteParamsMeta.add(SafeEncoder.encode(s));
        }

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

    public byte[][] getByteParamsMeta(byte[] key, byte[]... meta) {
        ArrayList byteParamsMeta = new ArrayList();
        byteParamsMeta.add(key);
        for (byte[] bytes : meta) {
            byteParamsMeta.add(bytes);
        }

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

    public byte[][] getByteParams(byte[][] meta, String... args) {
        ArrayList byteParams = new ArrayList();

        for (byte[] bytes : meta) {
            byteParams.add(bytes);
        }

        for (String s : args) {
            byteParams.add(SafeEncoder.encode(s));
        }

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

    public byte[][] getByteParams(byte[][] meta, byte[]... args) {
        ArrayList byteParams = new ArrayList();

        for (byte[] bytes : meta) {
            byteParams.add(bytes);
        }

        for (byte[] arg : args) {
            byteParams.add(arg);
        }
        return byteParams.toArray(new byte[byteParams.size()][]);
    }

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

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

        addParamWithValue(byteParams, CAPACITY);
        addParamWithValue(byteParams, ERROR);

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy