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

io.lettuce.core.output.DefaultTransactionResult Maven / Gradle / Ivy

Go to download

Advanced and thread-safe Java Redis client for synchronous, asynchronous, and reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs and much more.

The newest version!
package io.lettuce.core.output;

import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;

import io.lettuce.core.TransactionResult;
import io.lettuce.core.internal.LettuceAssert;

/**
 * Result of a {@code MULTI} transaction.
 *
 * @author Mark Paluch
 * @since 5.0
 */
class DefaultTransactionResult implements Iterable, TransactionResult {

    private final boolean discarded;

    private final List result;

    /**
     * Creates a new {@link DefaultTransactionResult}.
     *
     * @param discarded {@code true} if the transaction is discarded.
     * @param result the transaction result, must not be {@code null}.
     */
    public DefaultTransactionResult(boolean discarded, List result) {

        LettuceAssert.notNull(result, "Result must not be null");

        this.discarded = discarded;
        this.result = result;
    }

    @Override
    public boolean wasDiscarded() {
        return discarded;
    }

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

    @Override
    public int size() {
        return result.size();
    }

    @Override
    public boolean isEmpty() {
        return result.isEmpty();
    }

    @Override
    public  T get(int index) {
        return (T) result.get(index);
    }

    @Override
    public Stream stream() {
        return result.stream();
    }

    @Override
    public String toString() {

        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [wasRolledBack=").append(discarded);
        sb.append(", responses=").append(size());
        sb.append(']');
        return sb.toString();
    }

}