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

io.pelle.mango.server.base.query.BaseCollectionQuery Maven / Gradle / Ivy

package io.pelle.mango.server.base.query;

import java.util.Collection;
import java.util.Iterator;

public class BaseCollectionQuery implements Iterable
{
	private Collection collection;

	public BaseCollectionQuery(Collection eObjects)
	{
		this.collection = eObjects;
	}
	

	public int getCount() {
		return collection.size();
	}

	public Collection getCollection()
	{
		return collection;
	}
	
	public boolean hasExactlyOne()
	{
		return collection.size() == 1;
	}

	public T getSingleResult()
	{
		if (!hasExactlyOne())
		{
			throw new RuntimeException(String.format("found %d but expected expected one", collection.size()));
		}

		return collection.iterator().next();
	}

	@Override
	public Iterator iterator() {
		return collection.iterator();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy