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

com.netflix.astyanax.recipes.Shards Maven / Gradle / Ivy

There is a newer version: 3.10.2
Show newest version
package com.netflix.astyanax.recipes;

import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;

import com.google.common.collect.Lists;
import com.netflix.astyanax.serializers.StringSerializer;

public class Shards {
    public static interface Builder {
        Collection build();
    }

    public static class StringShardBuilder {
        private String prefix = "";
        private int shardCount = 0;

        public StringShardBuilder setPrefix(String prefix) {
            this.prefix = prefix;
            return this;
        }

        public StringShardBuilder setShardCount(int count) {
            this.shardCount = count;
            return this;
        }

        public Collection build() {
            List shards = Lists.newArrayListWithExpectedSize(shardCount);
            for (int i = 0; i < shardCount; i++) {
                shards.add(StringSerializer.get().toByteBuffer(prefix + i));
            }
            return shards;
        }
    }

    public static StringShardBuilder newStringShardBuilder() {
        return new StringShardBuilder();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy