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

com.zipwhip.util.ListDirectory Maven / Gradle / Ivy

package com.zipwhip.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * Created by IntelliJ IDEA.
 * User: jed
 * Date: 9/27/11
 * Time: 10:59 AM
 *
 * An in memory implementation backed by a {@code List} implementation.
 */
public class ListDirectory  extends GenericLocalDirectory {

	public ListDirectory() {
		super(new Factory>() {
			@Override
			public Collection create() throws Exception {
				return Collections.synchronizedList(new ArrayList());
			}
		});
	}

	public ListDirectory(Collection values, InputCallable sorter) {
		this();

		if (CollectionUtil.isNullOrEmpty(values)){
			return;
		}
		if (sorter == null){
			throw new NullPointerException("Need to have a sorter");
		}

		synchronized (values) {
			for(TValue value : values){
				TKey key = sorter.call(value);

				add(key, value);
			}
		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy