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

com.jashmore.sqs.util.collections.CollectionUtils Maven / Gradle / Ivy

Go to download

Utility methods for dealing with basic functionality for this library, split out so so it can be consumed by other extensions

There is a newer version: 6.0.0
Show newest version
package com.jashmore.sqs.util.collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.experimental.UtilityClass;

/**
 * Collection helper functions that can be used instead of having a Guava dependency.
 */
@UtilityClass
public class CollectionUtils {

    public  List immutableListOf(T element) {
        return Collections.singletonList(element);
    }

    public  List immutableListOf(T one, T two) {
        return Collections.unmodifiableList(Arrays.asList(one, two));
    }

    public  List immutableListOf(T one, T two, T three) {
        return Collections.unmodifiableList(Arrays.asList(one, two, three));
    }

    public  List immutableListOf(T one, T two, T three, T four) {
        return Collections.unmodifiableList(Arrays.asList(one, two, three, four));
    }

    public  List immutableListOf(T one, T two, T three, T four, T five) {
        return Collections.unmodifiableList(Arrays.asList(one, two, three, four, five));
    }

    public  List immutableListFrom(Collection one, Collection two) {
        final List underlyingList = new ArrayList<>(one.size() + two.size());
        underlyingList.addAll(one);
        underlyingList.addAll(two);
        return Collections.unmodifiableList(underlyingList);
    }

    public  Map immutableMapOf(T keyOne, S valueOne, T keyTwo, S valueTwo) {
        final Map internalMap = new HashMap<>();
        internalMap.put(keyOne, valueOne);
        internalMap.put(keyTwo, valueTwo);
        return Collections.unmodifiableMap(internalMap);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy