本文整理匯總了Java中com.google.common.collect.RangeSet.add方法的典型用法代碼示例。如果您正苦於以下問題:Java RangeSet.add方法的具體用法?Java RangeSet.add怎麽用?Java RangeSet.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.RangeSet
的用法示例。
在下文中一共展示了RangeSet.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: lineRangesToCharRanges
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
/**
* Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges.
*/
public static RangeSet<Integer> lineRangesToCharRanges(
String input, RangeSet<Integer> lineRanges) {
List<Integer> lines = new ArrayList<>();
Iterators.addAll(lines, Newlines.lineOffsetIterator(input));
lines.add(input.length() + 1);
final RangeSet<Integer> characterRanges = TreeRangeSet.create();
for (Range<Integer> lineRange :
lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) {
int lineStart = lines.get(lineRange.lowerEndpoint());
// Exclude the trailing newline. This isn't strictly necessary, but handling blank lines
// as empty ranges is convenient.
int lineEnd = lines.get(lineRange.upperEndpoint()) - 1;
Range<Integer> range = Range.closedOpen(lineStart, lineEnd);
characterRanges.add(range);
}
return characterRanges;
}
示例2: createFrontedClientMetadata
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
private static FrontendClientMetadata createFrontedClientMetadata(final long num) {
final String index = String.valueOf(num);
final String indexName = "test_" + index;
final FrontendIdentifier frontendIdentifier = FrontendIdentifier.create(MemberName.forName(indexName),
FrontendType.forName(index));
final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num);
final RangeSet<UnsignedLong> purgedHistories = TreeRangeSet.create();
purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE));
final Collection<FrontendHistoryMetadata> currentHistories = Collections.singleton(
new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE),
purgedHistories));
return new FrontendClientMetadata(clientIdentifier, purgedHistories, currentHistories);
}
示例3: addCmsRanges
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
private void addCmsRanges(RangeSet<Long> ranges, ConcurrentMarkSweepGeneration generation) {
CompactibleFreeListSpace space = generation._cmsSpace();
FreeChunk freeChunk = hotspot.getStructs().staticStruct(FreeChunk.class);
oopDesc oop = hotspot.getStructs().staticStruct(oopDesc.class);
Klass klass = hotspot.getStructs().staticStruct(Klass.class);
long minChunkSize = hotspot.alignUp(hotspot.getTypes().getType("FreeChunk").getSize(),
hotspot.getMinObjAlignmentInBytes());
ranges.add(Range.closedOpen(space._bottom(), space._end()));
for (long cur = space._bottom(); cur < space._end();) {
freeChunk.setAddress(cur);
if (freeChunk.isFreeChunk(hotspot)) {
ranges.remove(Range.closedOpen(cur, cur + freeChunk.size(hotspot)));
cur += freeChunk.size(hotspot);
} else {
oop.setAddress(cur);
oop.getKlass(hotspot, klass);
cur += Math.max(oop.getObjectSize(hotspot, klass), minChunkSize);
}
}
}
示例4: testThatFilterAndTruncateViolatorsFiltersIPsInDoNotBlockRangeSet
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
@Test
public void testThatFilterAndTruncateViolatorsFiltersIPsInDoNotBlockRangeSet() {
config.setRateLimitViolationBlacklistPeriodInMinutes(1);
RangeSet<Integer> doNotAutoBlockIpRangeSet = TreeRangeSet.create();
SubnetUtils subnetUtils = new SubnetUtils("50.39.100.193/32");
subnetUtils.setInclusiveHostCount(true);
SubnetUtils.SubnetInfo subnetInfo = subnetUtils.getInfo();
Integer lowIpAsInt = subnetInfo.asInteger(subnetInfo.getLowAddress());
Integer highIpAsInt = subnetInfo.asInteger(subnetInfo.getHighAddress());
doNotAutoBlockIpRangeSet.add(Range.closed(lowIpAsInt, highIpAsInt));
Map<String, ViolationMetaData> violators = new HashMap<>();
violators.put("50.39.100.193", new ViolationMetaData(new Date(), 2));
Map<String, ViolationMetaData> actual = processor.filterAndTruncateViolators(config, doNotAutoBlockIpRangeSet,
violators);
assertTrue("The violators map should be empty after filtering", actual.size() == 0);
}
示例5: lineRangesToCharRanges
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
/**
* Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges.
*/
public static RangeSet<Integer> lineRangesToCharRanges(
String input, RangeSet<Integer> lineRanges) {
List<Integer> lines = new ArrayList<>();
Iterators.addAll(lines, Newlines.lineOffsetIterator(input));
lines.add(input.length() + 1);
final RangeSet<Integer> characterRanges = TreeRangeSet.create();
for (Range<Integer> lineRange :
lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) {
int lineStart = lines.get(lineRange.lowerEndpoint());
// Exclude the trailing newline. This isn't strictly necessary, but handling blank lines
// as empty ranges is convenient.
int lineEnd = lines.get(lineRange.upperEndpoint()) - 1;
Range<Integer> range = Range.closedOpen(lineStart, lineEnd);
characterRanges.add(range);
}
return characterRanges;
}
示例6: compareFloorCeil
import com.google.common.collect.RangeSet; //導入方法依賴的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);
}
示例7: constrainMaximumSpan
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
public P2PBlobRangeSet constrainMaximumSpan(int maximumSpanSize) {
int currentSize=0;
RangeSet<Integer> constrainedRange=TreeRangeSet.create();
for(Range<Integer> r: ranges.asRanges()){
int sizeOfRange=r.upperEndpoint()-r.lowerEndpoint()+1;
if(currentSize+sizeOfRange<=maximumSpanSize){
currentSize+=sizeOfRange;
constrainedRange.add(r);
}
else{
sizeOfRange=maximumSpanSize-currentSize-1;
constrainedRange.add(Range.closed(r.lowerEndpoint(), r.lowerEndpoint()+sizeOfRange));
break;
}
}
return new P2PBlobRangeSet(constrainedRange);
}
示例8: context
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
private String context(final String originalDocText, final Response response) {
// [1,3], [2,5], [8,10] => [1,5], [8,10]
final List<CharOffsetSpan> charSpans = justificationSpans(response);
final List<CharOffsetSpan> unitedSpans = Lists.newArrayList();
// use RangeSet to do this
final RangeSet<Integer> disconnected = TreeRangeSet.create();
for (CharOffsetSpan charSpan : charSpans) {
int startInclusive = charSpan.startInclusive();
int endInclusive = charSpan.endInclusive();
startInclusive = (startInclusive - 100) >= 0 ? startInclusive - 100 : 0;
endInclusive =
(endInclusive + 100) < originalDocText.length() ? endInclusive + 100 : endInclusive;
disconnected.add(Range.closed(startInclusive, endInclusive));
}
for (Range<Integer> range : disconnected.asRanges()) {
unitedSpans.add(CharOffsetSpan.fromOffsetsOnly(range.lowerEndpoint(), range.upperEndpoint()));
}
Collections.sort(unitedSpans);
String justificationsString = "";
if (unitedSpans.get(0).startInclusive() != 0) {
justificationsString += "[.....]";
}
for (CharOffsetSpan span : unitedSpans) {
justificationsString +=
originalDocText.substring(span.startInclusive(), span.endInclusive() + 1);
justificationsString += "[.....]";
}
return justificationsString;
}
示例9: format
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
/**
* Runs the Google Java formatter on the given source, with only the given ranges specified.
*/
public List<Replacement> format(
SnippetKind kind,
String source,
List<Range<Integer>> ranges,
int initialIndent,
boolean includeComments)
throws FormatterException {
RangeSet<Integer> rangeSet = TreeRangeSet.create();
for (Range<Integer> range : ranges) {
rangeSet.add(range);
}
if (includeComments) {
if (kind != SnippetKind.COMPILATION_UNIT) {
throw new IllegalArgumentException(
"comment formatting is only supported for compilation units");
}
return formatter.getFormatReplacements(source, ranges);
}
SnippetWrapper wrapper = snippetWrapper(kind, source, initialIndent);
ranges = offsetRanges(ranges, wrapper.offset);
String replacement = formatter.formatSource(wrapper.contents.toString(), ranges);
replacement =
replacement.substring(
wrapper.offset,
replacement.length() - (wrapper.contents.length() - wrapper.offset - source.length()));
List<Replacement> replacements = toReplacements(source, replacement);
List<Replacement> filtered = new ArrayList<>();
for (Replacement r : replacements) {
if (rangeSet.encloses(r.getReplaceRange())) {
filtered.add(r);
}
}
return filtered;
}
示例10: characterRangesToTokenRanges
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
throws FormatterException {
RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
for (Range<Integer> characterRange0 : characterRanges) {
Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
tokenRangeSet.add(
characterRangeToTokenRange(
characterRange.lowerEndpoint(),
characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
}
return tokenRangeSet;
}
示例11: readFrom
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
public static FrontendHistoryMetadata readFrom(final DataInput in) throws IOException {
byte header = WritableObjects.readLongHeader(in);
final long historyId = WritableObjects.readFirstLong(in, header);
final long cookie = WritableObjects.readSecondLong(in, header);
final boolean closed = in.readBoolean();
header = WritableObjects.readLongHeader(in);
long ls = WritableObjects.readFirstLong(in, header);
Verify.verify(ls >= 0 && ls <= Integer.MAX_VALUE);
final int csize = (int) ls;
ls = WritableObjects.readSecondLong(in, header);
Verify.verify(ls >= 0 && ls <= Integer.MAX_VALUE);
final int psize = (int) ls;
final Map<UnsignedLong, Boolean> closedTransactions = new HashMap<>(csize);
for (int i = 0; i < csize; ++i) {
final UnsignedLong key = UnsignedLong.fromLongBits(WritableObjects.readLong(in));
final Boolean value = Boolean.valueOf(in.readBoolean());
closedTransactions.put(key, value);
}
final RangeSet<UnsignedLong> purgedTransactions = TreeRangeSet.create();
for (int i = 0; i < psize; ++i) {
final byte h = WritableObjects.readLongHeader(in);
final UnsignedLong l = UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, h));
final UnsignedLong u = UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, h));
purgedTransactions.add(Range.closed(l, u));
}
return new FrontendHistoryMetadata(historyId, cookie, closed, closedTransactions, purgedTransactions);
}
示例12: addG1Ranges
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
private void addG1Ranges(RangeSet<Long> ranges, G1CollectedHeap heap) {
G1HeapRegionTable regionTable = heap._hrm()._regions();
long arrayAddress = regionTable._base();
for (int i = 0; i < regionTable._length(); i++) {
long region = hotspot.getAddressSpace().getPointer(arrayAddress + i * hotspot.getAddressSpace().getPointerSize());
if (region != 0) {
ranges.add(hotspot.getStructs().structAt(region, HeapRegion.class).getLiveRange());
}
}
}
示例13: testAllFields
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
@Test
public void testAllFields() {
assertEquals(ID, base.getId());
assertEquals(TEXT, base.getText());
assertEquals(TYPE, base.getType());
assertEquals(SPAN_1.lowerEndpoint().intValue(), base.beginPosition());
assertEquals(SPAN_2.upperEndpoint().intValue(), base.endPosition());
RangeSet<Integer> actual = TreeRangeSet.create();
actual.add(SPAN_1);
actual.add(SPAN_2);
assertEquals(actual, base.getSpans());
assertEquals(actual.span(), base.totalSpan());
}
示例14: setDynamismLevels
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
/**
* Sets the dynamism levels.
* @param levels At least one level must be given. The default level is
* <code>.5</code>.
* @return This, as per the builder pattern.
*/
public Builder setDynamismLevels(Iterable<Double> levels) {
checkArgument(Iterables.size(levels) > 0);
final RangeSet<Double> rangeSet = TreeRangeSet.create();
final Set<Range<Double>> dynamismLevelsB = new LinkedHashSet<>();
final RangeMap<Double, Double> map = TreeRangeMap.create();
for (final Double d : levels) {
checkArgument(d >= 0d && d <= 1d);
final Range<Double> newRange = createDynRange(d);
checkArgument(
rangeSet.subRangeSet(newRange).isEmpty(),
"Can not add dynamism level %s, it is too close to another level.",
d);
rangeSet.add(newRange);
dynamismLevelsB.add(newRange);
map.put(newRange, d);
}
final SetMultimap<TimeSeriesType, Range<Double>> timeSeriesTypes =
LinkedHashMultimap
.<TimeSeriesType, Range<Double>>create();
for (final Range<Double> r : dynamismLevelsB) {
checkArgument(DYNAMISM_MAP.get(r.lowerEndpoint()) != null);
checkArgument(DYNAMISM_MAP.get(r.lowerEndpoint()) == DYNAMISM_MAP.get(r
.upperEndpoint()));
timeSeriesTypes.put(DYNAMISM_MAP.get(r.lowerEndpoint()), r);
}
dynamismLevels = ImmutableSetMultimap.copyOf(timeSeriesTypes);
dynamismRangeMap = ImmutableRangeMap.copyOf(map);
return this;
}
示例15: whenUsingRangeSet_thenCorrect
import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
@Test
public void whenUsingRangeSet_thenCorrect() {
RangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 10));
rangeSet.add(Range.closed(12, 15));
assertEquals(2, rangeSet.asRanges().size());
rangeSet.add(Range.closed(10, 12));
assertTrue(rangeSet.encloses(Range.closed(1, 15)));
assertEquals(1, rangeSet.asRanges().size());
}