com.couchbase.client.java.kv.SamplingScan Maven / Gradle / Ivy
Show all versions of java-client Show documentation
/*
* Copyright (c) 2022 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.client.java.kv;
import java.util.Optional;
import com.couchbase.client.core.annotation.Stability;
import com.couchbase.client.core.error.InvalidArgumentException;
import com.couchbase.client.core.kv.CoreSamplingScan;
/**
* Performs a KV range scan using random sampling.
*
* Use {@link ScanType#samplingScan(long)} and {@link ScanType#samplingScan(long, long)} to construct.
*/
@Stability.Volatile
public class SamplingScan extends ScanType {
private final long limit;
private final Optional seed;
SamplingScan(final long limit, final Optional seed) {
if (limit <= 0) {
throw InvalidArgumentException.fromMessage("The limit of the SamplingScan must be greater than 0");
}
this.limit = limit;
this.seed = seed;
}
/**
* Returns the limit set for this sampling scan.
*
* @return the limit set for this sampling scan.
*/
public long limit() {
return limit;
}
/**
* Returns the seed set for this sampling scan.
*
* @return the seed set for this sampling scan.
*/
public Optional seed() {
return seed;
}
@Stability.Internal
public Built build() {
return new Built();
}
@Stability.Internal
public class Built implements CoreSamplingScan {
public long limit() {
return limit;
}
public Optional seed() {
return seed;
}
}
@Override
public String toString() {
return "SamplingScan{" +
"limit=" + limit +
", seed=" + seed +
'}';
}
}