Package com.buschmais.xo.impl

Source Code of com.buschmais.xo.impl.AbstractResultIterable

package com.buschmais.xo.impl;

import com.buschmais.xo.api.ResultIterable;
import com.buschmais.xo.api.ResultIterator;
import com.buschmais.xo.api.XOException;

public abstract class AbstractResultIterable<T> implements ResultIterable<T> {

    @Override
    public T getSingleResult() {
        ResultIterator<T> iterator = iterator();
        if (!iterator.hasNext()) {
            throw new XOException("No result available.");
        }
        try {
            T singleResult = iterator.next();
            if (iterator.hasNext()) {
                throw new XOException("More than one result available.");
            }
            return singleResult;
        } finally {
            iterator.close();
        }
    }

    @Override
    public boolean hasResult() {
        return iterator().hasNext();
    }
}
TOP

Related Classes of com.buschmais.xo.impl.AbstractResultIterable

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.