Search in sources :

Example 1 with BoundType

use of com.google.common.collect.BoundType in project cassandra by apache.

the class TokenFilter method toRangeSet.

/**
     * Converts the specified slice into a range set.
     *
     * @param slice the slice to convert
     * @param options the query option
     * @return the range set corresponding to the specified slice
     * @throws InvalidRequestException if the request is invalid
     */
private RangeSet<Token> toRangeSet(TokenRestriction slice, QueryOptions options) throws InvalidRequestException {
    if (slice.hasBound(START)) {
        Token start = deserializeToken(slice.bounds(START, options).get(0));
        BoundType startBoundType = toBoundType(slice.isInclusive(START));
        if (slice.hasBound(END)) {
            BoundType endBoundType = toBoundType(slice.isInclusive(END));
            Token end = deserializeToken(slice.bounds(END, options).get(0));
            if (start.equals(end) && (BoundType.OPEN == startBoundType || BoundType.OPEN == endBoundType))
                return ImmutableRangeSet.of();
            if (start.compareTo(end) <= 0)
                return ImmutableRangeSet.of(Range.range(start, startBoundType, end, endBoundType));
            return ImmutableRangeSet.<Token>builder().add(Range.upTo(end, endBoundType)).add(Range.downTo(start, startBoundType)).build();
        }
        return ImmutableRangeSet.of(Range.downTo(start, startBoundType));
    }
    Token end = deserializeToken(slice.bounds(END, options).get(0));
    return ImmutableRangeSet.of(Range.upTo(end, toBoundType(slice.isInclusive(END))));
}
Also used : BoundType(com.google.common.collect.BoundType) Token(org.apache.cassandra.dht.Token)

Example 2 with BoundType

use of com.google.common.collect.BoundType in project guava by google.

the class MultisetNavigationTester method testEmptyMultisetNearby.

@CollectionSize.Require(ZERO)
public void testEmptyMultisetNearby() {
    for (BoundType type : BoundType.values()) {
        assertNull(sortedMultiset.headMultiset(e0(), type).lastEntry());
        assertNull(sortedMultiset.tailMultiset(e0(), type).firstEntry());
    }
}
Also used : BoundType(com.google.common.collect.BoundType)

Example 3 with BoundType

use of com.google.common.collect.BoundType in project pulsar by yahoo.

the class NamespaceBundleTest method 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(new NamespaceName("pulsar/use/ns1"), Range.range(upper, BoundType.CLOSED, NamespaceBundles.FULL_UPPER_BOUND, BoundType.CLOSED));
    assertTrue(!bundle.includes(dn));
    NamespaceBundle otherBundle = factory.getBundle(new NamespaceName("pulsar/use/ns2"), Range.range(0l, BoundType.CLOSED, 0x40000000L, BoundType.OPEN));
    assertTrue(!otherBundle.includes(dn));
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) BoundType(com.google.common.collect.BoundType) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) Test(org.testng.annotations.Test)

Example 4 with BoundType

use of com.google.common.collect.BoundType in project guava by hceylan.

the class MultisetNavigationTester method testEmptyMultisetNearby.

@CollectionSize.Require(ZERO)
public void testEmptyMultisetNearby() {
    for (BoundType type : BoundType.values()) {
        assertNull(sortedMultiset.headMultiset(samples.e0, type).lastEntry());
        assertNull(sortedMultiset.tailMultiset(samples.e0, type).firstEntry());
    }
}
Also used : BoundType(com.google.common.collect.BoundType)

Example 5 with BoundType

use of com.google.common.collect.BoundType in project pulsar by yahoo.

the class ServiceUnitZkUtils method 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);
}
Also used : BoundType(com.google.common.collect.BoundType)

Aggregations

BoundType (com.google.common.collect.BoundType)5 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)1 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)1 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)1 Token (org.apache.cassandra.dht.Token)1 Test (org.testng.annotations.Test)1