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

org.aeonbits.owner.util.Collections Maven / Gradle / Ivy

There is a newer version: 1.0.12
Show newest version
/*
 * Copyright (c) 2012-2015, Luigi R. Viggiano
 * All rights reserved.
 *
 * This software is distributable under the BSD license.
 * See the terms of the BSD license in the documentation provided with this software.
 */

package org.aeonbits.owner.util;

import java.io.Serializable;
import java.util.AbstractMap;
import java.util.AbstractMap.SimpleEntry;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import static java.util.Arrays.asList;

/**
 * Utility class to create a maps, lists and sets
 * 

Examples of usage:

*
 * import static org.aeonbits.owner.util.Collections.map;
 * import static org.aeonbits.owner.util.Collections.entry;
 * import static org.aeonbits.owner.util.Collections.set;
 * import static org.aeonbits.owner.util.Collections.list;
 *
 * Map<String, String> myMap = map("foo", "bar");
 * Map<String, String> myMap2 = map(entry("foo", "bar"), entry("baz", "qux");
 * Set<String> mySet = set("foo", "bar", "baz", "qux");
 * List<String> myList = list("foo", "bar", "baz", "qux");
 * 
* * @author Luigi R. Viggiano * @since 1.0.6 */ public abstract class Collections { // Suppresses default constructor, ensuring non-instantiability. private Collections() {} private static final class EntryMap extends AbstractMap implements Serializable { private static final long serialVersionUID = -789853606407653214L; private final Set> entries; private EntryMap(Entry... entries) { this.entries = set(entries); } @SuppressWarnings("unchecked") @Override public Set> entrySet() { return (Set) entries; } } public static Entry entry(K key, V value) { return new SimpleEntry(key, value); } @SuppressWarnings("unchecked") public static Map map(K key, V value) { return map(entry(key, value)); } public static Map map(Map.Entry... entries) { return new EntryMap(entries); } public static Set set(E... elements) { return new LinkedHashSet(list(elements)); } public static List list(E... elements) { return asList(elements); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy