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

com.netflix.zeno.util.collections.builder.Builders Maven / Gradle / Ivy

The newest version!
/*
 *
 *  Copyright 2013 Netflix, Inc.
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 *
 */
package com.netflix.zeno.util.collections.builder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * Java Utils containers builders
 *
 * @author tvaliulin
 *
 */
public class Builders {

    public static class HashMapBuilder implements MapBuilder {

        HashMap map;

        @Override
        public void builderInit(int size) {
            this.map = new HashMap(size);
        }

        @Override
        public void builderPut(int index, K key, V value) {
            map.put(key, value);
        }

        @Override
        public Map builderFinish() {
            return map;
        }
    }

    public static class TreeMapBuilder implements MapBuilder {

        TreeMap map;

        @Override
        public void builderInit(int size) {
            this.map = new TreeMap();
        }

        @Override
        public void builderPut(int index, K key, V value) {
            map.put(key, value);
        }

        @Override
        public SortedMap builderFinish() {
            return map;
        }
    }

    public static class ArrayListBuilder implements ListBuilder {
        List list;

        @Override
        public void builderInit(int size) {
            list = new ArrayList(size);
        }

        @Override
        public void builderSet(int index, E element) {
            list.add(element);
        }

        @Override
        public List builderFinish() {
            return list;
        }
    }

    public static class HashSetBuilder implements SetBuilder {
        Set set;

        @Override
        public void builderInit(int size) {
            set = new HashSet(size);
        }

        @Override
        public void builderSet(int index, E element) {
            set.add(element);
        }

        @Override
        public Set builderFinish() {
            return set;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy