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

com.buschmais.xo.impl.AbstractResultIterable Maven / Gradle / Ivy

The newest version!
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 implements ResultIterable {

    @Override
    public T getSingleResult() {
        try (ResultIterator iterator = iterator()) {
            if (!iterator.hasNext()) {
                throw new XOException("No result available.");
            }
            T singleResult = iterator.next();
            if (iterator.hasNext()) {
                T nextResult = iterator.next();
                throw new XOException("Expected exactly one result, but got '" + singleResult + "' and '" + nextResult + "'");
            }
            return singleResult;
        }
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy