本文整理汇总了Java中com.google.common.collect.ImmutableRangeSet类的典型用法代码示例。如果您正苦于以下问题:Java ImmutableRangeSet类的具体用法?Java ImmutableRangeSet怎么用?Java ImmutableRangeSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImmutableRangeSet类属于com.google.common.collect包,在下文中一共展示了ImmutableRangeSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveTo
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
public void saveTo(ByteSink sink) throws IOException {
final PrintWriter out = new PrintWriter(sink.asCharSink(Charsets.UTF_8).openBufferedStream());
out.println(docIdToBannedRegions.size());
for (final Map.Entry<Symbol, ImmutableRangeSet<Integer>> entry : docIdToBannedRegions
.entrySet()) {
out.println(entry.getKey());
final List<String> parts = Lists.newArrayList();
for (final Range<Integer> r : entry.getValue().asRanges()) {
// we know by construction these ranges are bounded above and below
parts.add(String.format("%d-%d", r.lowerEndpoint(), r.upperEndpoint()));
}
out.println(StringUtils.SpaceJoiner.join(parts));
}
out.close();
}
示例2: computeResponseMapping
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
private ResponseMapping computeResponseMapping(final ArgumentOutput input) {
final ImmutableRangeSet<Integer> bannedRegions = docIdToBannedRegions.get(input.docId());
if (bannedRegions == null) {
throw new RuntimeException(String.format(
"QuoteFilter does not know about document ID %s", input.docId()));
}
final ImmutableSet.Builder<Response> toDeleteB = ImmutableSet.builder();;
for (final Response response : input.responses()) {
if (isInQuote(input.docId(), response.baseFiller())
|| isInQuote(input.docId(), response.canonicalArgument().charOffsetSpan()))
{
toDeleteB.add(response);
}
}
final ImmutableSet<Response> toDelete = toDeleteB.build();
log.info("For document {}, filtered out {} responses which were in quoted regions",
input.docId(), toDelete.size());
return ResponseMapping.create(ImmutableMap.<Response,Response>of(), toDelete);
}
示例3: QuoteFilter
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
private QuoteFilter(Map<Symbol, ImmutableRangeSet<Integer>> docIdToBannedRegions) {
this.docIdToBannedRegions = ImmutableMap.copyOf(docIdToBannedRegions);
for (RangeSet<Integer> rs : docIdToBannedRegions.values()) {
for (final Range<Integer> r : rs.asRanges()) {
checkArgument(r.hasLowerBound());
checkArgument(r.hasUpperBound());
checkArgument(r.lowerEndpoint() >= 0);
}
}
// these ensure we can serialize safely
for (Symbol sym : docIdToBannedRegions.keySet()) {
final String s = sym.toString();
checkArgument(!s.isEmpty(), "Document IDs may not be empty");
checkArgument(!CharMatcher.WHITESPACE.matchesAnyOf(s),
"Document IDs may not contain whitespace: %s", s);
}
}
示例4: testQuotedRegionComputation
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
@Test
public void testQuotedRegionComputation() throws IOException {
final Map<String, ImmutableRangeSet<Integer>> testCases = ImmutableMap.of(
"Foo <quote>bar <quote>baz</quote> <quote>meep</quote></quote> blah <quote>another</quote>",
ImmutableRangeSet.<Integer>builder().add(Range.closed(4, 60)).add(Range.closed(67, 88))
.build(),
"<quote>lalala</quote>", ImmutableRangeSet.of(Range.closed(0, 20)),
"No quotes!", ImmutableRangeSet.<Integer>of());
for (final Map.Entry<String, ImmutableRangeSet<Integer>> entry : testCases.entrySet()) {
final Symbol docid = Symbol.from("dummy");
final QuoteFilter reference =
QuoteFilter.createFromBannedRegions(ImmutableMap.of(docid, entry.getValue()));
final QuoteFilter computed = QuoteFilter.createFromOriginalText(ImmutableMap.of(docid,
CharSource.wrap(entry.getKey())));
assertEquals(reference, computed);
}
}
示例5: readFrom
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
public static FrontendClientMetadata readFrom(final DataInput in) throws IOException, ClassNotFoundException {
final ClientIdentifier id = ClientIdentifier.readFrom(in);
final int purgedSize = in.readInt();
final Builder<UnsignedLong> b = ImmutableRangeSet.builder();
for (int i = 0; i < purgedSize; ++i) {
final byte header = WritableObjects.readLongHeader(in);
final UnsignedLong lower = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, header));
final UnsignedLong upper = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, header));
b.add(Range.closed(lower, upper));
}
final int currentSize = in.readInt();
final Collection<FrontendHistoryMetadata> currentHistories = new ArrayList<>(currentSize);
for (int i = 0; i < currentSize; ++i) {
currentHistories.add(FrontendHistoryMetadata.readFrom(in));
}
return new FrontendClientMetadata(id, b.build(), currentHistories);
}
示例6: CrontabEntry
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
private CrontabEntry(
RangeSet<Integer> minute,
RangeSet<Integer> hour,
RangeSet<Integer> dayOfMonth,
RangeSet<Integer> month,
RangeSet<Integer> dayOfWeek) {
checkEnclosed("minute", MINUTE, minute);
checkEnclosed("hour", HOUR, hour);
checkEnclosed("dayOfMonth", DAY_OF_MONTH, dayOfMonth);
checkEnclosed("month", MONTH, month);
checkEnclosed("dayOfWeek", DAY_OF_WEEK, dayOfWeek);
this.minute = ImmutableRangeSet.copyOf(minute);
this.hour = ImmutableRangeSet.copyOf(hour);
this.dayOfMonth = ImmutableRangeSet.copyOf(dayOfMonth);
this.month = ImmutableRangeSet.copyOf(month);
this.dayOfWeek = ImmutableRangeSet.copyOf(dayOfWeek);
checkArgument(hasWildcardDayOfMonth() || hasWildcardDayOfWeek(),
"Specifying both dayOfWeek and dayOfMonth is not supported.");
}
示例7: testReadWithNoData
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
@Test
public void testReadWithNoData() throws IOException {
newTimeSeriesPartition(Configuration.newBuilder()
.dataDirectory(this.testDirectory)
.memTimeSeriesSize(MEMTIMESERIES_SIZE)
.build());
EasyMock.replay(this.manager, this.listener);
Range<Field> range = MILLISECONDS_TIMESTAMP.range("'2013-11-26 12:00:00.000'", "'2013-11-26 14:00:00.000'");
ResourceIterator<Record> iterator = this.partition.read(ImmutableRangeSet.of(range),
Filters.<String>noop(),
toFilter(range));
Assert.assertFalse(iterator.hasNext());
EasyMock.verify(this.manager, this.listener);
}
示例8: exceptionTest
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
@Test
public void exceptionTest() {
final UnresolvedNumber min = UnresolvedNumber.min();
final UnresolvedNumber max = UnresolvedNumber.max();
final EnumPair enumPair = EnumPairBuilder.create("enum1", 1).setDescription("description")
.setReference("reference").setUnknownSchemaNodes(mock(UnknownSchemaNode.class)).build();
final RangeSet<Integer> rangeset = ImmutableRangeSet.of(Range.closed(1, 2));
final InvalidRangeConstraintException invalidRangeConstraintException = new InvalidRangeConstraintException(
rangeset, "error msg", "other important messages");
assertSame(rangeset, invalidRangeConstraintException.getOffendingRanges());
final InvalidBitDefinitionException invalidBitDefinitionException = new InvalidBitDefinitionException(
BIT_A, "error msg", "other important messages");
assertEquals(invalidBitDefinitionException.getOffendingBit(), BIT_A);
final InvalidEnumDefinitionException invalidEnumDefinitionException = new InvalidEnumDefinitionException(
enumPair, "error msg", "other important messages");
assertEquals(invalidEnumDefinitionException.getOffendingEnum(), enumPair);
}
示例9: compareFloorCeil
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand,
RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) {
RangeSet<Calendar> rangeSet = operandRanges.get(operand.toString());
if (rangeSet == null) {
rangeSet = ImmutableRangeSet.<Calendar>of().complement();
}
final RangeSet<Calendar> s2 = TreeRangeSet.create();
final Calendar c = timestampValue(timeLiteral);
final Range<Calendar> range = floor
? floorRange(timeUnit, comparison, c)
: ceilRange(timeUnit, comparison, c);
s2.add(range);
// Intersect old range set with new.
s2.removeAll(rangeSet.complement());
operandRanges.put(operand.toString(), ImmutableRangeSet.copyOf(s2));
if (range.isEmpty()) {
return rexBuilder.makeLiteral(false);
}
return toRex(operand, range);
}
示例10: testComplement
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
@Test
public void testComplement() {
Range range;
ImmutableRangeSet.Builder builder;
Interval.Difference difference;
difference = a.complement();
range = Range.lessThan(2);
builder = ImmutableRangeSet.builder().add(range);
range = Range.greaterThan(4);
builder.add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 1);
difference = Interval.MAGIC.complement();
builder = ImmutableRangeSet.builder();
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 0);
difference = Interval.NULL.complement();
range = Range.all();
builder = ImmutableRangeSet.builder().add(range);
assertEquals(difference.getRanges(), builder.build());
assertEquals(difference.getDimension(), 0);
}
示例11: CharacterClassRangeSet
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
private CharacterClassRangeSet(final ImmutableRangeSet<Integer> rangeSet, boolean containsEOF) {
assert rangeSet.isEmpty() || rangeSet.span().lowerEndpoint() >= 0;
assert rangeSet.isEmpty() || rangeSet.span().upperEndpoint() < CharacterClassFactory.EOF_INT;
if(rangeSet.isEmpty()) {
this.min = this.max = containsEOF ? CharacterClassFactory.EOF_INT : -1;
} else {
this.min = rangeSet.span().lowerEndpoint();
this.max = Math.max(rangeSet.span().upperEndpoint(), containsEOF ? CharacterClassFactory.EOF_INT : -1);
}
this.rangeSet = rangeSet;
this.containsEOF = containsEOF;
this.useCachedBitSet = tryOptimize();
}
示例12: isInQuote
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
public boolean isInQuote(Symbol docId, CharOffsetSpan span) {
final ImmutableRangeSet<Integer> bannedRegions = docIdToBannedRegions.get(docId);
if (bannedRegions == null) {
throw new RuntimeException(String.format(
"QuoteFilter does not know about document ID %s", docId));
}
return inBannedSet(span, bannedRegions);
}
示例13: createFromOriginalText
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
public static QuoteFilter createFromOriginalText(Map<Symbol, ? extends CharSource> originalTexts)
throws IOException {
checkNotNull(originalTexts);
final ImmutableMap.Builder<Symbol, ImmutableRangeSet<Integer>> ret = ImmutableMap.builder();
for (final Map.Entry<Symbol, ? extends CharSource> originalTextPair : originalTexts
.entrySet()) {
final Symbol docID = originalTextPair.getKey();
final CharSource originalTextSource = originalTextPair.getValue();
ret.put(docID, computeQuotedRegions(originalTextSource.read()));
}
return createFromBannedRegions(ret.build());
}
示例14: loadFrom
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
public static QuoteFilter loadFrom(ByteSource source) throws IOException {
final ImmutableList<String> input = source.asCharSource(Charsets.UTF_8).readLines();
if (input.isEmpty()) {
throw new IOException("Attempted to load QuoteFilter from empty file");
}
final int numEntries = Integer.parseInt(input.get(0));
final int expectedLines = 2 * numEntries + 1;
if (input.size() != expectedLines) {
throw new IOException(String.format(
"Invalid number of lines when loading QuoteFiler. Expected %d, got %d",
expectedLines, input.size()));
}
final ImmutableMap.Builder<Symbol, ImmutableRangeSet<Integer>> ret = ImmutableMap.builder();
int curLine = 1;
for (int i = 0; i < numEntries; ++i) {
final Symbol docid = Symbol.from(input.get(curLine++));
final ImmutableRangeSet.Builder<Integer> ranges = ImmutableRangeSet.builder();
for (final String part : StringUtils.OnSpaces.split(input.get(curLine++))) {
final List<String> endPointStrings = DASH_SPLITTER.splitToList(part);
if (endPointStrings.size() != 2) {
throw new IOException(String.format("Invalid range serialization %s", part));
}
ranges.add(Range.closed(Integer.parseInt(endPointStrings.get(0)),
Integer.parseInt(endPointStrings.get(1))));
}
ret.put(docid, ranges.build());
}
return QuoteFilter.createFromBannedRegions(ret.build());
}
示例15: testSerialization
import com.google.common.collect.ImmutableRangeSet; //导入依赖的package包/类
@Test
public void testSerialization() throws IOException {
final QuoteFilter reference = QuoteFilter.createFromBannedRegions(
ImmutableMap.of(
Symbol.from("dummy"),
ImmutableRangeSet.<Integer>builder().add(Range.closed(4, 60)).add(Range.closed(67, 88))
.build(),
Symbol.from("dummy2"), ImmutableRangeSet.of(Range.closed(0, 20))));
final ByteArraySink sink = new ByteArraySink();
reference.saveTo(sink);
final ByteSource source = ByteSource.wrap(sink.toByteArray());
final Object restored = QuoteFilter.loadFrom(source);
assertEquals(reference, restored);
}