com.jashmore.sqs.util.collections.CollectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-utils Show documentation
Show all versions of common-utils Show documentation
Utility methods for dealing with basic functionality for this library, split out so so it can be consumed by other extensions
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);
}
}