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

io.quarkus.redis.runtime.datasource.OptimisticLockingTransactionResultImpl Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.redis.runtime.datasource;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import io.quarkus.redis.datasource.transactions.OptimisticLockingTransactionResult;

public class OptimisticLockingTransactionResultImpl implements OptimisticLockingTransactionResult {

    private final List results = new ArrayList<>();
    private final boolean discarded;
    private final I input;

    public OptimisticLockingTransactionResultImpl(boolean discarded, I input, List res) {
        this.results.addAll(res);
        this.discarded = discarded;
        this.input = input;
    }

    public static  OptimisticLockingTransactionResult discarded(I input) {
        return new OptimisticLockingTransactionResultImpl<>(true, input, Collections.emptyList());
    }

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

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

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

    @SuppressWarnings("unchecked")
    @Override
    public  T get(int index) {
        return (T) results.get(index);
    }

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

    @Override
    public I getPreTransactionResult() {
        return input;
    }
}