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

com.aliyun.tair.tairhash.factory.HashBuilderFactory 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.tairhash.factory;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.aliyun.tair.tairhash.params.ExhgetwithverResult;
import redis.clients.jedis.Builder;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.util.SafeEncoder;

public class HashBuilderFactory {

    public static final Builder> EXHGETWITHVER_RESULT_STRING
        = new Builder>() {
        @Override
        @SuppressWarnings("unchecked")
        public ExhgetwithverResult build(Object data) {
            if (data == null) {
                return null;
            }
            List result = (List)data;
            if (result.size() == 0) {
                return null;
            } else {
                String value = SafeEncoder.encode((byte[])result.get(0));
                long version = (Long)result.get(1);
                return new ExhgetwithverResult(value, version);
            }
        }

        @Override
        public String toString() {
            return "exhgetwithver";
        }
    };

    public static final Builder> EXHGETWITHVER_RESULT_BYTE
        = new Builder>() {
        @Override
        @SuppressWarnings("unchecked")
        public ExhgetwithverResult build(Object data) {
            if (data == null) {
                return null;
            }
            List result = (List)data;
            if (result.size() == 0) {
                return null;
            } else {
                byte[] value = (byte[])result.get(0);
                long version = (Long)result.get(1);
                return new ExhgetwithverResult(value, version);
            }
        }

        @Override
        public String toString() {
            return "exhgetwithver";
        }
    };

    public static final Builder>> EXHMGETWITHVER_RESULT_STRING_LIST
        = new Builder>>() {
        @Override
        @SuppressWarnings("unchecked")
        public List> build(Object data) {
            if (data == null) {
                return null;
            }
            List result = (List)data;
            if (result.size() == 0) {
                return null;
            } else {
                List> results = new ArrayList>();
                for (Object o : result) {
                    if (o == null) {
                        results.add(null);
                    } else {
                        List lo = (List)o;
                        String value = SafeEncoder.encode((byte[])lo.get(0));
                        long version = (Long)lo.get(1);
                        results.add(new ExhgetwithverResult(value, version));
                    }
                }
                return results;
            }
        }

        @Override
        public String toString() {
            return "exhmgetwithver";
        }
    };

    public static final Builder>> EXHMGETWITHVER_RESULT_BYTE_LIST
        = new Builder>>() {
        @Override
        @SuppressWarnings("unchecked")
        public List> build(Object data) {
            if (data == null) {
                return null;
            }
            List result = (List)data;
            if (result.size() == 0) {
                return null;
            } else {
                List> results = new ArrayList>();
                for (Object o : result) {
                    if (o == null) {
                        results.add(null);
                    } else {
                        List lo = (List)o;
                        byte[] value = (byte[])lo.get(0);
                        long version = (Long)lo.get(1);
                        results.add(new ExhgetwithverResult(value, version));
                    }
                }
                return results;
            }
        }

        @Override
        public String toString() {
            return "exhmgetwithver";
        }
    };

    public static final Builder>> EXHSCAN_RESULT_STRING
        = new Builder>>() {
        @Override
        @SuppressWarnings("unchecked")
        public ScanResult> build(Object data) {
            if (data == null) {
                return null;
            }
            List result = (List)data;
            String newcursor = new String((byte[])result.get(0));
            List> results = new ArrayList>();
            List rawResults = (List)result.get(1);
            Iterator iterator = rawResults.iterator();
            while (iterator.hasNext()) {
                results.add(new AbstractMap.SimpleEntry(SafeEncoder.encode(iterator.next()),
                    SafeEncoder.encode(iterator.next())));
            }
            return new ScanResult>(newcursor, results);
        }

        @Override
        public String toString() {
            return "exhscan";
        }
    };

    public static final Builder>> EXHSCAN_RESULT_BYTE
        = new Builder>>() {
        @Override
        @SuppressWarnings("unchecked")
        public ScanResult> build(Object data) {
            if (data == null) {
                return null;
            }
            List result = (List)data;
            byte[] newcursor = (byte[])result.get(0);
            List> results = new ArrayList>();
            List rawResults = (List)result.get(1);
            Iterator iterator = rawResults.iterator();
            while (iterator.hasNext()) {
                results.add(new AbstractMap.SimpleEntry(iterator.next(), iterator.next()));
            }
            return new ScanResult>(newcursor, results);
        }

        @Override
        public String toString() {
            return "exhscan";
        }
    };
}