本文整理汇总了Java中com.google.common.collect.BoundType类的典型用法代码示例。如果您正苦于以下问题:Java BoundType类的具体用法?Java BoundType怎么用?Java BoundType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BoundType类属于com.google.common.collect包,在下文中一共展示了BoundType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateNamespaceBundleRange
import com.google.common.collect.BoundType; //导入依赖的package包/类
protected NamespaceBundle validateNamespaceBundleRange(NamespaceName fqnn, BundlesData bundles,
String bundleRange) {
try {
checkArgument(bundleRange.contains("_"), "Invalid bundle range");
String[] boundaries = bundleRange.split("_");
Long lowerEndpoint = Long.decode(boundaries[0]);
Long upperEndpoint = Long.decode(boundaries[1]);
Range<Long> hashRange = Range.range(lowerEndpoint, BoundType.CLOSED, upperEndpoint,
(upperEndpoint.equals(NamespaceBundles.FULL_UPPER_BOUND)) ? BoundType.CLOSED : BoundType.OPEN);
NamespaceBundle nsBundle = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundle(fqnn,
hashRange);
NamespaceBundles nsBundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(fqnn,
bundles);
nsBundles.validateBundle(nsBundle);
return nsBundle;
} catch (Exception e) {
log.error("[{}] Failed to validate namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
}
}
示例2: testEquals
import com.google.common.collect.BoundType; //导入依赖的package包/类
@Test
public void testEquals() throws Exception {
NamespaceBundle bundle = factory.getBundle(NamespaceName.get("pulsar/use/ns1"),
Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
NamespaceBundle bundle2 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"),
Range.range(0x20000000l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
assertTrue(!bundle.equals(bundle2));
NamespaceBundle bundle0 = factory.getBundle(NamespaceName.get("pulsar/use/ns1"),
Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
assertTrue(bundle0.equals(bundle));
NamespaceBundle otherBundle = factory.getBundle(NamespaceName.get("pulsar/use/ns2"),
Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
assertTrue(!otherBundle.equals(bundle));
}
示例3: testIncludes
import com.google.common.collect.BoundType; //导入依赖的package包/类
@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));
}
示例4: _numberEqualsQuery
import com.google.common.collect.BoundType; //导入依赖的package包/类
private static <N extends Number> Query _numberEqualsQuery(final IndexDocumentFieldID fieldId,
final N number,
final Class<N> numberType) {
Query outQry = null;
if (numberType.equals(Integer.class)) {
outQry = _numberInRangeQuery(fieldId,
_createRange((Integer)number,BoundType.CLOSED,(Integer)number,BoundType.CLOSED),
Integer.class);
} else if (numberType.equals(Long.class)) {
outQry = _numberInRangeQuery(fieldId,
_createRange((Long)number,BoundType.CLOSED,(Long)number,BoundType.CLOSED),
Long.class);
} else if (numberType.equals(Double.class)) {
outQry = _numberInRangeQuery(fieldId,
_createRange((Double)number,BoundType.CLOSED,(Double)number,BoundType.CLOSED),
Double.class);
} else if (numberType.equals(Long.class)) {
outQry = _numberInRangeQuery(fieldId,
_createRange((Float)number,BoundType.CLOSED,(Float)number,BoundType.CLOSED),
Float.class);
} else {
throw new IllegalArgumentException();
}
return outQry;
}
示例5: printStats
import com.google.common.collect.BoundType; //导入依赖的package包/类
/**
* Print statistics on stdout.
*/
protected void printStats() {
final SortedMultiset<Integer> sizeDistribution = sampleGrammar
.computeGrammarTreeSizeStats();
System.out.println("Size Stats: 1-5:"
+ sizeDistribution.subMultiset(0, BoundType.CLOSED, 5,
BoundType.CLOSED).size()
+ " 6-15:"
+ sizeDistribution.subMultiset(6, BoundType.CLOSED, 15,
BoundType.CLOSED).size()
+ " 16-30:"
+ sizeDistribution.subMultiset(16, BoundType.CLOSED, 30,
BoundType.CLOSED).size()
+ " >30:"
+ sizeDistribution.subMultiset(31, BoundType.CLOSED,
Integer.MAX_VALUE, BoundType.CLOSED).size());
int sumOfSizes = 0;
for (final com.google.common.collect.Multiset.Entry<Integer> sizeEntry : sizeDistribution
.entrySet()) {
sumOfSizes += sizeEntry.getCount() * sizeEntry.getElement();
}
final double avgSize = (((double) sumOfSizes) / sizeDistribution.size());
System.out.println("Avg Tree Size: " + String.format("%.2f", avgSize));
}
示例6: pruneToThreshold
import com.google.common.collect.BoundType; //导入依赖的package包/类
/**
* Prune the list to the given threshold.
*/
private List<Pair<SortedMultiset<Double>, SortedMultiset<Double>>> pruneToThreshold(
final double threshold) {
final List<Pair<SortedMultiset<Double>, SortedMultiset<Double>>> filtered = Lists
.newArrayList();
for (final Pair<SortedMultiset<Double>, SortedMultiset<Double>> suggestion : suggestionPrecision) {
final SortedMultiset<Double> allFilteredSuggestions = suggestion.first
.tailMultiset(threshold, BoundType.CLOSED);
final SortedMultiset<Double> correctFilteredSuggestions = suggestion.second
.tailMultiset(threshold, BoundType.CLOSED);
final Pair<SortedMultiset<Double>, SortedMultiset<Double>> filteredPair = Pair
.create(allFilteredSuggestions,
correctFilteredSuggestions);
filtered.add(filteredPair);
}
return filtered;
}
示例7: deserialize
import com.google.common.collect.BoundType; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Range<?> deserialize(
JsonElement json,
Type typeOfT,
JsonDeserializationContext context)
throws JsonParseException {
checkArgument(json.isJsonObject());
try {
JsonObject obj = json.getAsJsonObject();
JsonObject upper = obj.getAsJsonObject("upper");
JsonObject lower = obj.getAsJsonObject("lower");
BoundType ubt = bt(upper.getAsJsonPrimitive("type"));
BoundType lbt = bt(lower.getAsJsonPrimitive("type"));
Object ub = des(upper.get("endpoint"),context);
Object lb = des(lower.get("endpoint"),context);
return Range.range((Comparable)lb, lbt, (Comparable)ub, ubt);
} catch (Throwable t) {
throw Throwables.propagate(t);
}
}
示例8: canonical
import com.google.common.collect.BoundType; //导入依赖的package包/类
static Range<IPAddress> canonical(final Range<IPAddress> range,
final LongDiscreteDomain<IPAddress> domain) {
if (range.isEmpty()) {
return null;
}
final boolean l = range.lowerBoundType() == BoundType.OPEN;
final boolean u = range.upperBoundType() == BoundType.OPEN;
final IPAddress s = range.lowerEndpoint();
final IPAddress e = range.upperEndpoint();
if (l && u) {
Range.closed(domain.next(s), domain.previous(e));
} else if (l) {
return Range.closed(domain.next(s), e);
} else if (u) {
return Range.closed(s, domain.previous(e));
}
return range;
}
示例9: computeBmp
import com.google.common.collect.BoundType; //导入依赖的package包/类
private void computeBmp(RangeMap<Integer, Short> fullMap) {
for (Map.Entry<Range<Integer>, Short> me : fullMap.asMapOfRanges().entrySet()) {
Range<Integer> range = me.getKey();
int min = range.lowerEndpoint();
if (range.lowerBoundType() == BoundType.OPEN) {
min++;
}
if (min < Character.MAX_VALUE) {
int rmax = range.upperEndpoint();
if (range.upperBoundType() == BoundType.OPEN) {
rmax--;
}
int max = Math.min(Character.MAX_VALUE, rmax);
for (int x = min; x <= max; x++) {
this.bmpMap[x] = me.getValue();
}
}
}
}
示例10: isLessThan
import com.google.common.collect.BoundType; //导入依赖的package包/类
/**
* Return true if the specified range is strictly less than the specified value.
*
* @param <C> range endpoint type
* @param range range, must not be null
* @param value value, must not be null
* @return true if the specified range is strictly less than the specified value
*/
public static <C extends Comparable> boolean isLessThan(final Range<C> range, final C value)
{
checkNotNull(range);
checkNotNull(value);
if (!range.hasUpperBound())
{
return false;
}
if (range.upperBoundType() == BoundType.OPEN && range.upperEndpoint().equals(value))
{
return true;
}
return range.upperEndpoint().compareTo(value) < 0;
}
示例11: getMessageRepresentation
import com.google.common.collect.BoundType; //导入依赖的package包/类
/** Returns an appropriate string representation of a metric value for use in error messages. */
@Override
protected String getMessageRepresentation(Distribution distribution) {
StringBuilder sb = new StringBuilder("{");
boolean first = true;
for (Map.Entry<Range<Double>, Long> entry :
distribution.intervalCounts().asMapOfRanges().entrySet()) {
if (entry.getValue() != 0L) {
if (first) {
first = false;
} else {
sb.append(',');
}
if (entry.getKey().hasLowerBound()) {
sb.append((entry.getKey().lowerBoundType() == BoundType.CLOSED) ? '[' : '(');
sb.append(entry.getKey().lowerEndpoint());
}
sb.append("..");
if (entry.getKey().hasUpperBound()) {
sb.append(entry.getKey().upperEndpoint());
sb.append((entry.getKey().upperBoundType() == BoundType.CLOSED) ? ']' : ')');
}
sb.append('=');
sb.append(entry.getValue());
}
}
sb.append('}');
return sb.toString();
}
示例12: testEmptyMultisetNearby
import com.google.common.collect.BoundType; //导入依赖的package包/类
@CollectionSize.Require(ZERO)
public void testEmptyMultisetNearby() {
for (BoundType type : BoundType.values()) {
assertNull(sortedMultiset.headMultiset(e0(), type).lastEntry());
assertNull(sortedMultiset.tailMultiset(e0(), type).firstEntry());
}
}
示例13: setPlayerLimits
import com.google.common.collect.BoundType; //导入依赖的package包/类
@Override
public void setPlayerLimits(Range<Integer> limits) {
if(!playerLimits.equals(limits)) {
checkArgument(limits.lowerBoundType() == BoundType.CLOSED);
checkArgument(limits.upperBoundType() == BoundType.CLOSED);
playerLimits = limits;
callEvent(new MatchResizeEvent(this));
}
}
示例14: matches
import com.google.common.collect.BoundType; //导入依赖的package包/类
@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);
}
示例15: describe
import com.google.common.collect.BoundType; //导入依赖的package包/类
/**
* 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);
}
}