当前位置: 首页>>代码示例>>Java>>正文


Java TreeRangeSet类代码示例

本文整理汇总了Java中com.google.common.collect.TreeRangeSet的典型用法代码示例。如果您正苦于以下问题:Java TreeRangeSet类的具体用法?Java TreeRangeSet怎么用?Java TreeRangeSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TreeRangeSet类属于com.google.common.collect包,在下文中一共展示了TreeRangeSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lineRangesToCharRanges

import com.google.common.collect.TreeRangeSet; //导入依赖的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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:Formatter.java

示例2: createFrontedClientMetadata

import com.google.common.collect.TreeRangeSet; //导入依赖的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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:FrontendShardDataTreeSnapshotMetadataTest.java

示例3: process

import com.google.common.collect.TreeRangeSet; //导入依赖的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();
}
 
开发者ID:oaqa,项目名称:bioasq,代码行数:26,代码来源:TokenConceptAbstractQueryGenerator.java

示例4: testThatFilterAndTruncateViolatorsFiltersIPsInDoNotBlockRangeSet

import com.google.common.collect.TreeRangeSet; //导入依赖的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);
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:20,代码来源:RateLimitingProcessorTest.java

示例5: testThatFilterAndTruncateViolatorsTruncatesTheLowestOffenders

import com.google.common.collect.TreeRangeSet; //导入依赖的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"));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-serverless-components,代码行数:20,代码来源:RateLimitingProcessorTest.java

示例6: addSequenceCoverageObject

import com.google.common.collect.TreeRangeSet; //导入依赖的package包/类
/**
 * Add another protein sequence coverage object's ranges to this one's
 * 
 * @param coverageToAdd
 */
public void addSequenceCoverageObject( ProteinSequenceCoverage coverageToAdd ) throws Exception {
	
	if( this.ranges == null )
		this.ranges = TreeRangeSet.create();
	
	if( this.getProtein().getProteinSequenceVersionId() != coverageToAdd.getProtein().getProteinSequenceVersionId() )
		throw new ProxlWebappInternalErrorException( "Attempted to add two coverage objects that do not describe the same protein." );
	
	if( coverageToAdd.getRanges() == null )
		return;
	
	for( Range<Integer> r : coverageToAdd.getRanges() ) {
		this.ranges.add( r );
	}
}
 
开发者ID:yeastrc,项目名称:proxl-web-app,代码行数:21,代码来源:ProteinSequenceCoverage.java

示例7: lineRangesToCharRanges

import com.google.common.collect.TreeRangeSet; //导入依赖的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;
}
 
开发者ID:google,项目名称:google-java-format,代码行数:22,代码来源:Formatter.java

示例8: createInterval

import com.google.common.collect.TreeRangeSet; //导入依赖的package包/类
/**
 * Generates a list of {@link Interval}s equivalent to a given
 * expression. Assumes that all the predicates in the input
 * reference a single column: the timestamp column.
 */
public static List<Interval> createInterval(RexNode e, String timeZone) {
  final List<Range<TimestampString>> ranges =
      extractRanges(e, TimeZone.getTimeZone(timeZone), false);
  if (ranges == null) {
    // We did not succeed, bail out
    return null;
  }
  final TreeRangeSet condensedRanges = TreeRangeSet.create();
  for (Range r : ranges) {
    condensedRanges.add(r);
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Inferred ranges on interval : " + condensedRanges);
  }
  return toInterval(
      ImmutableList.<Range>copyOf(condensedRanges.asRanges()));
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:DruidDateTimeUtils.java

示例9: compareFloorCeil

import com.google.common.collect.TreeRangeSet; //导入依赖的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);
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:DateRangeRules.java

示例10: constrainMaximumSpan

import com.google.common.collect.TreeRangeSet; //导入依赖的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);
}
 
开发者ID:pmarches,项目名称:peercentrum-core,代码行数:18,代码来源:P2PBlobRangeSet.java

示例11: setUp

import com.google.common.collect.TreeRangeSet; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    ranges = new ArrayList<Range<Long>>();
    ranges.add(Range.closedOpen(0L, 0L));
    ranges.add(Range.closedOpen(0L, 1L));
    ranges.add(Range.closedOpen(0L, 43L));
    ranges.add(Range.closedOpen(1L, 43L));

    rangeSet = TreeRangeSet.create();
    rangeSet.add(Range.closedOpen(0L, 0L));
    rangeSet.add(Range.closedOpen(0L, 1L));
    rangeSet.add(Range.closedOpen(0L, 43L));
    rangeSet.add(Range.closedOpen(1L, 43L));

    subject = DNATools.createGappedDNASequence("aaaattttaaaattttaaaa", "subject");
    query = DNATools.createGappedDNASequence("aaaaccccaaaa----aaaa", "query");
    substitutionMatrix = SubstitutionMatrix.getNuc4_4();
    alignmentPair = new AlignmentPair(query, subject, substitutionMatrix);
}
 
开发者ID:nmdp-bioinformatics,项目名称:ngs,代码行数:20,代码来源:AlignmentsTest.java

示例12: context

import com.google.common.collect.TreeRangeSet; //导入依赖的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;
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:31,代码来源:FancierDiffLogger.java

示例13: format

import com.google.common.collect.TreeRangeSet; //导入依赖的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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:40,代码来源:SnippetFormatter.java

示例14: characterRangesToTokenRanges

import com.google.common.collect.TreeRangeSet; //导入依赖的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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:13,代码来源:JavaInput.java

示例15: of

import com.google.common.collect.TreeRangeSet; //导入依赖的package包/类
static EncodedDiscreteResources of(Set<DiscreteResource> resources, DiscreteResourceCodec codec) {
    RangeSet<Integer> rangeSet = TreeRangeSet.create();
    resources.stream()
            .map(x -> x.valueAs(Object.class))
            .flatMap(Tools::stream)
            .map(x -> codec.encode(x))
            .map(Range::singleton)
            .map(x -> x.canonical(DiscreteDomain.integers()))
            .forEach(rangeSet::add);

    return new EncodedDiscreteResources(rangeSet, codec);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:13,代码来源:EncodedDiscreteResources.java


注:本文中的com.google.common.collect.TreeRangeSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。