2021-01-31 00:36:21 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
2021-01-31 15:47:48 +01:00
|
|
|
import java.util.Arrays;
|
2021-01-31 00:36:21 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
public class SubStageGetterSingle implements SubStageGetter<byte[], DatabaseStageEntry<byte[]>> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Mono<DatabaseStageEntry<byte[]>> subStage(LLDictionary dictionary,
|
|
|
|
@Nullable CompositeSnapshot snapshot,
|
|
|
|
byte[] keyPrefix,
|
|
|
|
Flux<byte[]> keyFlux) {
|
2021-01-31 15:47:48 +01:00
|
|
|
return keyFlux.singleOrEmpty().flatMap(key -> Mono.fromCallable(() -> {
|
|
|
|
if (!Arrays.equals(keyPrefix, key)) {
|
|
|
|
throw new IndexOutOfBoundsException("Found more than one element!");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
})).thenReturn(new DatabaseSingle(dictionary, keyPrefix));
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|
|
|
|
}
|