本文整理匯總了Java中com.google.common.collect.RangeSet類的典型用法代碼示例。如果您正苦於以下問題:Java RangeSet類的具體用法?Java RangeSet怎麽用?Java RangeSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RangeSet類屬於com.google.common.collect包,在下文中一共展示了RangeSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: QuoteFilter
import com.google.common.collect.RangeSet; //導入依賴的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);
}
}
示例2: 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;
}
示例3: getFormatReplacements
import com.google.common.collect.RangeSet; //導入依賴的package包/類
/**
* Emit a list of {@link Replacement}s to convert from input to output.
*
* @param input the input compilation unit
* @param characterRanges the character ranges to reformat
* @return a list of {@link Replacement}s, sorted from low index to high index, without overlaps
* @throws FormatterException if the input string cannot be parsed
*/
public ImmutableList<Replacement> getFormatReplacements(
String input, Collection<Range<Integer>> characterRanges) throws FormatterException {
JavaInput javaInput = new JavaInput(input);
// TODO(cushon): this is only safe because the modifier ordering doesn't affect whitespace,
// and doesn't change the replacements that are output. This is not true in general for
// 'de-linting' changes (e.g. import ordering).
javaInput = ModifierOrderer.reorderModifiers(javaInput, characterRanges);
String lineSeparator = Newlines.guessLineSeparator(input);
JavaOutput javaOutput =
new JavaOutput(lineSeparator, javaInput, new JavaCommentsHelper(lineSeparator, options));
try {
format(javaInput, javaOutput, options);
} catch (FormattingError e) {
throw new FormatterException(e.diagnostics());
}
RangeSet<Integer> tokenRangeSet = javaInput.characterRangesToTokenRanges(characterRanges);
return javaOutput.getFormatReplacements(tokenRangeSet);
}
示例4: 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);
}
示例5: CrontabEntry
import com.google.common.collect.RangeSet; //導入依賴的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.");
}
示例6: buildNonUpdatingTasksFilter
import com.google.common.collect.RangeSet; //導入依賴的package包/類
private static Predicate<IAssignedTask> buildNonUpdatingTasksFilter(
final Map<IJobKey, IJobUpdateInstructions> roleJobUpdates) {
return task -> {
Optional<IJobUpdateInstructions> update = Optional.fromNullable(
roleJobUpdates.get(task.getTask().getJob()));
if (update.isPresent()) {
IJobUpdateInstructions instructions = update.get();
RangeSet<Integer> initialInstances = getInstanceIds(instructions.getInitialState());
RangeSet<Integer> desiredInstances = getInstanceIds(instructions.isSetDesiredState()
? ImmutableSet.of(instructions.getDesiredState())
: ImmutableSet.of());
int instanceId = task.getInstanceId();
return !initialInstances.contains(instanceId) && !desiredInstances.contains(instanceId);
}
return true;
};
}
示例7: process
import com.google.common.collect.RangeSet; //導入依賴的package包/類
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Collection<Concept> concepts = TypeUtil.getConcepts(jcas);
List<QueryConcept> qconcepts = ConceptAbstractQueryGenerator
.createQueryConceptsFromConceptMentions(jcas, concepts, useType, useWeight);
// filter tokens that are covered by concept mentions
RangeSet<Integer> cmentionRanges = TreeRangeSet.create();
concepts.stream().map(TypeUtil::getConceptMentions).flatMap(Collection::stream)
.map(cmention -> Range.closedOpen(cmention.getBegin(), cmention.getEnd()))
.forEach(cmentionRanges::add);
// create an aquery using all tokens with POS in posTags set
List<Token> tokens = TypeUtil.getOrderedTokens(jcas).stream().filter(token -> !cmentionRanges
.encloses(Range.closedOpen(token.getBegin(), token.getEnd()))).collect(toList());
List<QueryConcept> qconceptTokens = TokenSelectionAbstractQueryGenerator
.createQueryConceptsFromTokens(jcas, tokens, posTags, stoplist);
qconceptTokens.addAll(qconcepts);
AbstractQuery aquery = TypeFactory.createAbstractQuery(jcas, qconceptTokens);
aquery.addToIndexes();
// create a backup aquery using only nouns
List<QueryConcept> qconceptNouns = TokenSelectionAbstractQueryGenerator
.createQueryConceptsFromTokens(jcas, tokens, nounTags, stoplist);
qconceptNouns.addAll(qconcepts);
AbstractQuery aqueryNoun = TypeFactory.createAbstractQuery(jcas, qconceptNouns);
aqueryNoun.addToIndexes();
}
示例8: 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);
}
}
}
示例9: processLogEvents
import com.google.common.collect.RangeSet; //導入依賴的package包/類
/**
* 1. Build a map of requests identified by ip-date-time(minutes accuracy) this will give us rate / min by ip.
* 2. Create a range set for ips we do not want to auto block that we can query.
* 3. Collect the do not auto block range set, the ranges of ips for the manual block list.
* 4. Get the current violators from the request map that have requests grouped by ip and minutes
* 5. Filter and Truncate to remove expired IP address and IPs that are on the White or Black manual lists
* and ensure that we are under the ip limit for an IP Set
* 6. Save the violators data.
* 7. Update the auto block ip set to reflect the current violators data.
*
* @param events The Cloud Front log events
* @param config The Cloud Formation outputs from when this Lambda was created
* @param bucketName The Bucket that we are operating from
*/
@Override
public void processLogEvents(List<CloudFrontLogEvent> events, CloudFrontLogHandlerConfig config, String bucketName) {
Map<String, Integer> reqIdCountMap = new HashMap<>();
// Build a map of requests identified by ip-date-time(minutes accuracy) this will give us rate / min by ip
events.forEach(cloudFrontLogEvent -> processRequest(cloudFrontLogEvent, reqIdCountMap));
// Collect the do not auto block range set, the ranges of ips for the manual block and white list.
RangeSet<Integer> doNotAutoBlockIpRangeSet = getDoNotBlockRangeSet(config);
// Get the current violators
Map<String, ViolationMetaData> violators = getCurrentViolators(reqIdCountMap, config);
// Get and merge in all the currently blocked violators
violators.putAll(getCurrentlyBlockedIpsAndDateViolatedMap(bucketName));
// Filter and truncate to remove expired blocks and ensure that we are under the ip limit for an IP Set
violators = filterAndTruncateViolators(config, doNotAutoBlockIpRangeSet, violators);
// Save the violators data.
saveCurrentViolators(violators, bucketName);
// Update the auto block ip set to reflect the current violators data.
Map<String, List<String>> summery = processViolators(config, violators);
// log summery
logSummery(summery, config);
}
示例10: 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);
}
示例11: testThatFilterAndTruncateViolatorsTruncatesTheLowestOffenders
import com.google.common.collect.RangeSet; //導入依賴的package包/類
@Test
public void testThatFilterAndTruncateViolatorsTruncatesTheLowestOffenders() {
final int cidrLimit = 2;
processor.setCidrLimitForIpSetOverride(cidrLimit);
config.setRateLimitViolationBlacklistPeriodInMinutes(10);
RangeSet<Integer> rangeSet = TreeRangeSet.create();
Map<String, ViolationMetaData> violators = new HashMap<>();
violators.put("50.39.100.193", new ViolationMetaData(new Date(), 3));
violators.put("50.39.100.191", new ViolationMetaData(new Date(), 1));
violators.put("50.39.100.192", new ViolationMetaData(new Date(), 2));
violators.put("50.39.100.194", new ViolationMetaData(new Date(), 4));
Map<String, ViolationMetaData> actual = processor.filterAndTruncateViolators(config, rangeSet, violators);
assertTrue("The violators map should be the size of the cidr limit", actual.size() == cidrLimit);
assertTrue("violators should contain 193 and 194 the highest offenders",
actual.containsKey("50.39.100.193") && actual.containsKey("50.39.100.194"));
}
示例12: getRangeLists
import com.google.common.collect.RangeSet; //導入依賴的package包/類
/**
* Return a pair of maps containing the ranges of availability for dimensions and metrics respectively.
*
* @param metadata The metadata that contain segment availability.
*
* @return A pair of two maps of range sets. One entry is for dimensions and the other for metrics.
*/
public static Map<Columns, Map<String, RangeSet<DateTime>>> getRangeLists(DataSourceMetadata metadata) {
final Map<String, RangeSet<DateTime>> dimensionIntervals = new HashMap<>();
final Map<String, RangeSet<DateTime>> metricIntervals = new HashMap<>();
metadata.segments.stream()
.forEach(
segment -> {
buildRangeSet(segment.getDimensions(), segment.getInterval(), dimensionIntervals);
buildRangeSet(segment.getMetrics(), segment.getInterval(), metricIntervals);
}
);
EnumMap<Columns, Map<String, RangeSet<DateTime>>> intervals = new EnumMap<>(Columns.class);
intervals.put(DIMENSIONS, dimensionIntervals);
intervals.put(METRICS, metricIntervals);
return intervals;
}
示例13: isEmpty
import com.google.common.collect.RangeSet; //導入依賴的package包/類
public boolean isEmpty() {
if (!anyLvlSet.isEmpty()) {
return false;
}
for (Map.Entry<Integer, MsLevelRangeSet> lvlMapEntry : lvlMap.entrySet()) {
MsLevelRangeSet msLevelRangeSet = lvlMapEntry.getValue();
if (!msLevelRangeSet.anyPrecursorSet.isEmpty()) {
return false;
}
for (Map.Entry<DoubleRange, RangeSet<Integer>> rngMapEntry : msLevelRangeSet.rngMap.entrySet()) {
if (!rngMapEntry.getValue().isEmpty()) {
return false;
}
}
}
return true;
}
示例14: getFormatReplacements
import com.google.common.collect.RangeSet; //導入依賴的package包/類
/**
* Emit a list of {@link Replacement}s to convert from input to output.
*
* @param input the input compilation unit
* @param characterRanges the character ranges to reformat
* @return a list of {@link Replacement}s, sorted from low index to high index, without overlaps
* @throws FormatterException if the input string cannot be parsed
*/
public ImmutableList<Replacement> getFormatReplacements(
String input, Collection<Range<Integer>> characterRanges) throws FormatterException {
JavaInput javaInput = new JavaInput(input);
// TODO(cushon): this is only safe because the modifier ordering doesn't affect whitespace,
// and doesn't change the replacements that are output. This is not true in general for
// 'de-linting' changes (e.g. import ordering).
javaInput = ModifierOrderer.reorderModifiers(javaInput, characterRanges);
String lineSeparator = Newlines.guessLineSeparator(input);
JavaOutput javaOutput =
new JavaOutput(lineSeparator, javaInput, new JavaCommentsHelper(lineSeparator, options));
try {
format(javaInput, javaOutput, options);
} catch (FormattingError e) {
throw new FormatterException(e.diagnostics());
}
RangeSet<Integer> tokenRangeSet = javaInput.characterRangesToTokenRanges(characterRanges);
return javaOutput.getFormatReplacements(tokenRangeSet);
}
示例15: 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;
}