本文整理匯總了Java中com.google.common.collect.Range.encloses方法的典型用法代碼示例。如果您正苦於以下問題:Java Range.encloses方法的具體用法?Java Range.encloses怎麽用?Java Range.encloses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.Range
的用法示例。
在下文中一共展示了Range.encloses方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: matches
import com.google.common.collect.Range; //導入方法依賴的package包/類
public boolean matches(DrillFileSystem fs, FileStatus status) throws IOException{
if (ranges.isEmpty()) {
return false;
}
final Range<Long> fileRange = Range.closedOpen( 0L, status.getLen());
try (FSDataInputStream is = fs.open(status.getPath())) {
for(RangeMagics rMagic : ranges) {
Range<Long> r = rMagic.range;
if (!fileRange.encloses(r)) {
continue;
}
int len = (int) (r.upperEndpoint() - r.lowerEndpoint());
byte[] bytes = new byte[len];
is.readFully(r.lowerEndpoint(), bytes);
for (byte[] magic : rMagic.magics) {
if (Arrays.equals(magic, bytes)) {
return true;
}
}
}
}
return false;
}
示例2: parseRandom
import com.google.common.collect.Range; //導入方法依賴的package包/類
@MethodParser("random")
public Filter parseRandom(Element el) throws InvalidXMLException {
Node node = new Node(el);
Range<Double> chance;
try {
chance = Range.closedOpen(0d, XMLUtils.parseNumber(node, Double.class));
} catch(InvalidXMLException e) {
chance = XMLUtils.parseNumericRange(node, Double.class);
}
Range<Double> valid = Range.closed(0d, 1d);
if (valid.encloses(chance)) {
return proto.isNoOlderThan(ProtoVersions.EVENT_QUERIES) ? new RandomFilter(chance)
: new LegacyRandomFilter(chance);
} else {
double lower = chance.hasLowerBound() ? chance.lowerEndpoint() : Double.NEGATIVE_INFINITY;
double upper = chance.hasUpperBound() ? chance.upperEndpoint() : Double.POSITIVE_INFINITY;
double invalid;
if(!valid.contains(lower)) {
invalid = lower;
} else {
invalid = upper;
}
throw new InvalidXMLException("chance value (" + invalid + ") is not between 0 and 1", el);
}
}
示例3: matches
import com.google.common.collect.Range; //導入方法依賴的package包/類
public boolean matches(FileSystemWrapper fs, FileStatus status) throws IOException{
if (ranges.isEmpty() || status.isDirectory()) {
return false;
}
// walk all the way down in the symlinks until a hard entry is reached
FileStatus current = status;
while (current.isSymlink()) {
current = fs.getFileStatus(status.getSymlink());
}
// if hard entry is not a file nor can it be a symlink then it is not readable simply deny matching.
if (!current.isFile()) {
return false;
}
final Range<Long> fileRange = Range.closedOpen( 0L, status.getLen());
try (FSDataInputStream is = fs.open(status.getPath())) {
for(RangeMagics rMagic : ranges) {
Range<Long> r = rMagic.range;
if (!fileRange.encloses(r)) {
continue;
}
int len = (int) (r.upperEndpoint() - r.lowerEndpoint());
byte[] bytes = new byte[len];
is.readFully(r.lowerEndpoint(), bytes);
for (byte[] magic : rMagic.magics) {
if (Arrays.equals(magic, bytes)) {
return true;
}
}
}
}
return false;
}