本文整理汇总了Java中com.google.common.collect.BoundType.CLOSED属性的典型用法代码示例。如果您正苦于以下问题:Java BoundType.CLOSED属性的具体用法?Java BoundType.CLOSED怎么用?Java BoundType.CLOSED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.common.collect.BoundType
的用法示例。
在下文中一共展示了BoundType.CLOSED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIncludes
@Test
public void testIncludes() throws Exception {
DestinationName dn = DestinationName.get("persistent://pulsar/use/ns1/topic-1");
Long hashKey = factory.getLongHashCode(dn.toString());
Long upper = Math.max(hashKey + 1, NamespaceBundles.FULL_UPPER_BOUND);
BoundType upperType = upper.equals(NamespaceBundles.FULL_UPPER_BOUND) ? BoundType.CLOSED : BoundType.OPEN;
NamespaceBundle bundle = factory.getBundle(dn.getNamespaceObject(),
Range.range(hashKey / 2, BoundType.CLOSED, upper, upperType));
assertTrue(bundle.includes(dn));
bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"),
Range.range(upper, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED));
assertTrue(!bundle.includes(dn));
NamespaceBundle otherBundle = factory.getBundle(NamespaceName.get("pulsar/use/ns2"),
Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
assertTrue(!otherBundle.includes(dn));
}
示例2: matches
@Override
protected boolean matches(IPlayerQuery query, MatchPlayer player) {
final StatsUserFacet facet = player.getUserContext().facet(StatsUserFacet.class);
int kills = persistent ? facet.teamKills() : facet.lifeKills();
if(repeat && kills > 0) {
int modulo = this.range.upperEndpoint() - (this.range.upperBoundType() == BoundType.CLOSED ? 0 : 1);
kills = 1 + (kills - 1) % modulo;
}
return this.range.contains(kills);
}
示例3: describe
/**
* Return an english phrase describing the given {@link Range} e.g.
*
* Range.all() -> "unbounded"
* Range.singleton(3) -> "3"
* Range.atLeast(3) -> "at least 3"
* Range.closedOpen(3, 7) -> "at least 3 and less than 7"
* Range.closed(3, 7) -> "between 3 and 7"
*/
public static String describe(Range<?> range) {
if(range.hasLowerBound() && range.hasUpperBound() && range.lowerBoundType() == BoundType.CLOSED && range.upperBoundType() == BoundType.CLOSED) {
if(range.lowerEndpoint().equals(range.upperEndpoint())) {
// singleton
return range.lowerEndpoint().toString();
} else {
// closed-closed
return "between " + range.lowerEndpoint() + " and " + range.upperEndpoint();
}
}
final List<String> parts = new ArrayList<>(2);
if(range.hasLowerBound()) {
parts.add((range.lowerBoundType() == BoundType.CLOSED ? "at least " : "more than ") + range.lowerEndpoint());
}
if(range.hasUpperBound()) {
parts.add((range.upperBoundType() == BoundType.CLOSED ? "at most " : "less than ") + range.upperEndpoint());
}
switch(parts.size()) {
case 0: return "unbounded";
case 1: return parts.get(0);
default: return parts.get(0) + " and " + parts.get(1);
}
}
示例4: nextInt
default int nextInt(final Range<Integer> range) {
final int upperEndPoint = range.hasUpperBound()
? range.upperBoundType() == BoundType.CLOSED ? range.upperEndpoint() : range.upperEndpoint() - 1
: Integer.MAX_VALUE;
final int lowerEndPoint = range.hasLowerBound()
? range.lowerBoundType() == BoundType.CLOSED ? range.lowerEndpoint() : range.lowerEndpoint() + 1
: Integer.MIN_VALUE;
return nextIntBetween(lowerEndPoint, upperEndPoint);
}
示例5: getHashRange
private static Range<Long> getHashRange(String rangePathPart) {
String[] endPoints = rangePathPart.split("_");
checkArgument(endPoints.length == 2, "Malformed bundle hash range path part:" + rangePathPart);
Long startLong = Long.decode(endPoints[0]);
Long endLong = Long.decode(endPoints[1]);
BoundType endType = (endPoints[1].equals(LAST_BOUNDARY)) ? BoundType.CLOSED : BoundType.OPEN;
return Range.range(startLong, BoundType.CLOSED, endLong, endType);
}
示例6: RestartingS3InputStream
public RestartingS3InputStream(AmazonS3 s3, String bucket, String key, @Nullable Range<Long> range) {
_s3 = s3;
_bucket = bucket;
_key = key;
S3Object s3Object;
// Get the object synchronously so any immediate S3 errors, such as file not found, are thrown inline.
if (range == null) {
s3Object = _s3.getObject(new GetObjectRequest(_bucket, _key));
_pos = 0;
_length = s3Object.getObjectMetadata().getContentLength();
} else {
long start, end;
if (range.hasLowerBound()) {
start = range.lowerEndpoint() + (range.lowerBoundType() == BoundType.CLOSED ? 0 : 1);
} else {
start = 0;
}
if (range.hasUpperBound()) {
end = range.upperEndpoint() - (range.upperBoundType() == BoundType.CLOSED ? 0 : 1);
} else {
end = Long.MAX_VALUE;
}
s3Object = _s3.getObject(new GetObjectRequest(_bucket, _key).withRange(start, end));
_pos = start;
// The S3 metadata's content length is the length of the data actually being returned by S3.
// Since we effectively skipped the first "start" bytes we need to add them back to the total length
// of data being read to make future calculations using _pos and _length consistent.
_length = start + s3Object.getObjectMetadata().getContentLength();
}
_in = s3Object.getObjectContent();
}
示例7: Range
public Range(final T lower,final BoundType lowerBoundType,
final T upper,final BoundType upperBoundType) {
// store the lower and upper bounds
_lowerBound = lower;
_upperBound = upper;
_lowerBoundType = lowerBoundType;
_upperBoundType = upperBoundType;
// Create the delegate
if (_lowerBound != null && _upperBound != null) {
if (lowerBoundType == BoundType.OPEN && upperBoundType == BoundType.OPEN) {
_range = com.google.common.collect.Range.open(_lowerBound,_upperBound);
} else if (lowerBoundType == BoundType.OPEN && upperBoundType == BoundType.CLOSED) {
_range = com.google.common.collect.Range.openClosed(_lowerBound,_upperBound);
} else if (lowerBoundType == BoundType.CLOSED && upperBoundType == BoundType.CLOSED) {
_range = com.google.common.collect.Range.closed(_lowerBound,_upperBound);
} else if (lowerBoundType == BoundType.CLOSED && upperBoundType == BoundType.OPEN) {
_range = com.google.common.collect.Range.closedOpen(_lowerBound,_upperBound);
} else {
throw new IllegalArgumentException("Both lower and upper bound types MUST be provided!");
}
} else if (_lowerBound != null) {
if (lowerBoundType == BoundType.OPEN) {
_range = com.google.common.collect.Range.greaterThan(_lowerBound);
} else {
_range = com.google.common.collect.Range.atLeast(_lowerBound);
}
} else if (_upperBound != null) {
if (upperBoundType == BoundType.OPEN) {
_range = com.google.common.collect.Range.lessThan(_upperBound);
} else {
_range = com.google.common.collect.Range.atMost(_upperBound);
}
} else {
throw new IllegalArgumentException("Cannot create range, at least lower or upper bound SHOULD be not null");
}
}
示例8: _numberInRangeQuery
@SuppressWarnings("rawtypes")
private static <N extends Number & Comparable> Query _numberInRangeQuery(final IndexDocumentFieldID fieldId,
final Range<N> range,
final Class<N> numberType) {
boolean lowerIncluded = range.hasLowerBound() && range.lowerBoundType() == BoundType.CLOSED;
boolean upperIncluded = range.hasUpperBound() && range.upperBoundType() == BoundType.CLOSED;
N lowerBound = range.hasLowerBound() ? range.lowerEndpoint() : null;
N upperBound = range.hasUpperBound() ? range.upperEndpoint() : null;
Query outNumberEqQry = null;
if (numberType.equals(Integer.class)) {
outNumberEqQry = NumericRangeQuery.newIntRange(fieldId.asString(),
(Integer)lowerBound,(Integer)upperBound,
lowerIncluded,upperIncluded);
} else if (numberType.equals(Long.class)) {
outNumberEqQry = NumericRangeQuery.newLongRange(fieldId.asString(),
(Long)lowerBound,(Long)upperBound,
lowerIncluded,upperIncluded);
} else if (numberType.equals(Double.class)) {
outNumberEqQry = NumericRangeQuery.newDoubleRange(fieldId.asString(),
(Double)lowerBound,(Double)upperBound,
lowerIncluded,upperIncluded);
} else if (numberType.equals(Float.class)) {
outNumberEqQry = NumericRangeQuery.newFloatRange(fieldId.asString(),
(Float)lowerBound,(Float)upperBound,
lowerIncluded,upperIncluded);
}
return outNumberEqQry;
}
示例9: formatTsRange
public static String formatTsRange(Range<Long> tsRange) {
if (tsRange == null)
return null;
StringBuilder sb = new StringBuilder();
if (tsRange.hasLowerBound()) {
if (tsRange.lowerBoundType() == BoundType.CLOSED) {
sb.append("[");
} else {
sb.append("(");
}
sb.append(DateFormat.formatToTimeStr(tsRange.lowerEndpoint()));
} else {
sb.append("(-∞");
}
sb.append("~");
if (tsRange.hasUpperBound()) {
sb.append(DateFormat.formatToTimeStr(tsRange.upperEndpoint()));
if (tsRange.upperBoundType() == BoundType.CLOSED) {
sb.append("]");
} else {
sb.append(")");
}
} else {
sb.append("+∞)");
}
return sb.toString();
}
示例10: bounds
public <O extends Comparable<? super O>>Range<O> bounds() {
O mini = minInclusive();
O mine = minExclusive();
O maxi = maxInclusive();
O maxe = maxExclusive();
Ordering<O> ordering = Ordering.<O>natural();
O min = ordering.nullsLast().min(mini,mine);
O max = ordering.nullsFirst().max(maxi,maxe);
BoundType lower =
min == null ? null :
min == mini ? BoundType.CLOSED :
BoundType.OPEN;
BoundType upper =
max == null ? null :
max == maxi ? BoundType.CLOSED :
BoundType.OPEN;
if (lower == null && upper == null)
return Range.<O>all();
else if (lower != null && upper == null)
return lower == BoundType.CLOSED ?
Range.atLeast(min) :
Range.greaterThan(min);
else if (lower == null && upper != null)
return upper == BoundType.CLOSED ?
Range.atMost(max) :
Range.lessThan(max);
else {
return Range.range(min, lower, max, upper);
}
}
示例11: bt
private BoundType bt(JsonPrimitive p) {
try {
return BoundType.valueOf(p.toString());
} catch (Throwable t) {
return BoundType.CLOSED;
}
}
示例12: subrange
/**
* subrange - allocate new subcolors to this range of chars, fill in arcs.
* The range will overlap existing ranges; even in the simplest case,
* it will overlap the initial WHITE range. For each existing range that
* it overlaps, allocate a new color, mark the range as mapping to that color,
* and add an arc between the states for that color.
*/
void subrange(int from, int to, State lp, State rp) throws RegexException {
/* Avoid one call to map.get() for each character in the range.
* This map will usually contain one item, but in complex cases more.
* For example, if we had [a-f][g-h] and then someone asked for [f-g], there
* would be two. Each of these new ranges will get a new color via subcolor.
*/
Map<Range<Integer>, Short> curColors = map.subRangeMap(Range.closed(from, to)).asMapOfRanges();
/*
* To avoid concurrent mod problems, we need to copy the ranges we are working from.
*/
List<Range<Integer>> ranges = Lists.newArrayList(curColors.keySet());
for (Range<Integer> rangeToProcess : ranges) {
// bound management here irritating.
int start = rangeToProcess.lowerEndpoint();
if (rangeToProcess.lowerBoundType() == BoundType.OPEN) {
start++;
}
int end = rangeToProcess.upperEndpoint();
if (rangeToProcess.upperBoundType() == BoundType.CLOSED) {
end++;
}
// allocate a new subcolor and account it owning the entire range.
short color = subcolor(start, end - start);
compiler.getNfa().newarc(Compiler.PLAIN, color, lp, rp);
}
}
示例13: any
/**
* Generate a {@code long} within the intersection formed by the specified {@code range} and this instance own range.
*
* @param range the specfied range
* @return a generated {@code long}
*/
public long any(final Range<Long> range) {
Range<Long> r = range.intersection(constraint);
if (r.isEmpty()) {
throw new IllegalStateException(String.format(
"The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
}
long upperBound = r.hasUpperBound() ? r.upperEndpoint() : Long.MAX_VALUE;
long lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : Long.MIN_VALUE;
if (r.hasUpperBound() && BoundType.CLOSED == r.upperBoundType()) {
upperBound++;
}
if (r.hasLowerBound() && BoundType.OPEN == r.lowerBoundType()) {
lowerBound++;
}
long delta = Math.abs(upperBound - lowerBound);
long randomLong = ((( Math.abs(this.random.nextLong()) % (delta / resolution))) * resolution) + lowerBound ;
return randomLong;
}
示例14: any
/**
* Generate a random short within the intersection of the specified
* <code>range</code> and this instance current range.
*
* @param range
* the desired range
* @return a randomly generated integer
*/
public short any(final Range<Short> range) {
Range<Short> r = range.intersection(constraint);
if (r.isEmpty()) {
throw new IllegalStateException(String.format(
"The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
}
short upperBound = r.hasUpperBound() ? r.upperEndpoint() : Short.MAX_VALUE;
short lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : Short.MIN_VALUE;
if (BoundType.CLOSED == r.upperBoundType()) {
// upperBound is not included in the random.nextInt() method
upperBound++;
}
if (BoundType.OPEN == r.lowerBoundType()) {
// lowerBound is included in the random.nextInt() method
lowerBound++;
}
short delta = (short) Math.abs(upperBound - lowerBound);
short anyIntRange = (short) ((this.random.nextInt(delta / resolution) * resolution) + lowerBound);
return anyIntRange;
}
示例15: any
/**
* Generate a random integer within the intersection of the specified
* <code>range</code> and this instance current range.
*
* @param range
* the desired range
* @return a randomly generated integer
*/
public int any(final Range<Integer> range) {
Range<Integer> r = range.intersection(constraint);
if (r.isEmpty()) {
throw new IllegalStateException(String.format(
"The intersection of the passed in range %s and this class constrained range %s result in a empty range", range, constraint));
}
int upperBound = r.hasUpperBound() ? r.upperEndpoint() : Integer.MAX_VALUE;
int lowerBound = r.hasLowerBound() ? r.lowerEndpoint() : Integer.MIN_VALUE;
if (r.hasUpperBound() && BoundType.CLOSED == r.upperBoundType()) {
// upperBound is not included in the random.nextInt() method
upperBound++;
}
if (r.hasLowerBound() && BoundType.OPEN == r.lowerBoundType()) {
// lowerBound is included in the random.nextInt() method
lowerBound++;
}
int delta = Math.abs(upperBound - lowerBound);
int anyIntegerRange = (this.random.nextInt(delta / resolution) * resolution) + lowerBound ;
return anyIntegerRange;
}