當前位置: 首頁>>代碼示例>>Java>>正文


Java RangeSet.asRanges方法代碼示例

本文整理匯總了Java中com.google.common.collect.RangeSet.asRanges方法的典型用法代碼示例。如果您正苦於以下問題:Java RangeSet.asRanges方法的具體用法?Java RangeSet.asRanges怎麽用?Java RangeSet.asRanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.RangeSet的用法示例。


在下文中一共展示了RangeSet.asRanges方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
  }
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:18,代碼來源:QuoteFilter.java

示例2: canRewriteExtract

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
private boolean canRewriteExtract(RexNode operand) {
  // We rely on timeUnits being sorted (so YEAR comes before MONTH
  // before HOUR) and unique. If we have seen a predicate on YEAR,
  // operandRanges will not be empty. This checks whether we can rewrite
  // the "extract" condition. For example, in the condition
  //
  //   extract(MONTH from time) = someValue
  //   OR extract(YEAR from time) = someValue
  //
  // we cannot rewrite extract on MONTH.
  if (timeUnit == TimeUnitRange.YEAR) {
    return true;
  }
  final RangeSet<Calendar> calendarRangeSet =
      operandRanges.get(operand.toString());
  if (calendarRangeSet == null || calendarRangeSet.isEmpty()) {
    return false;
  }
  for (Range<Calendar> range : calendarRangeSet.asRanges()) {
    // Cannot reWrite if range does not have an upper or lower bound
    if (!range.hasUpperBound() || !range.hasLowerBound()) {
      return false;
    }
  }
  return true;
}
 
開發者ID:apache,項目名稱:calcite,代碼行數:27,代碼來源:DateRangeRules.java

示例3: 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;
}
 
開發者ID:isi-nlp,項目名稱:tac-kbp-eal,代碼行數:31,代碼來源:FancierDiffLogger.java

示例4: fieldToString

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
private String fieldToString(RangeSet<Integer> rangeSet, Range<Integer> coveringRange) {
  if (rangeSet.asRanges().size() == 1 && rangeSet.encloses(coveringRange)) {
    return "*";
  }
  List<String> components = Lists.newArrayList();
  for (Range<Integer> range : rangeSet.asRanges()) {
    ContiguousSet<Integer> set = ContiguousSet.create(range, DiscreteDomain.integers());
    if (set.size() == 1) {
      components.add(set.first().toString());
    } else {
      components.add(set.first() + "-" + set.last());
    }
  }
  return String.join(",", components);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:16,代碼來源:CrontabEntry.java

示例5: annotate

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
public void annotate(IFile file, RangeSet<Integer> ranges, String markerType, String message) {
	BUSY = true;
	try {
		// Remove any markers from previous runs
		file.deleteMarkers(markerType, true, IResource.DEPTH_INFINITE);
	} catch (CoreException e1) {
		e1.printStackTrace();
	}
	
	for(Range<Integer> range : ranges.asRanges()) {
		
		int start = range.lowerEndpoint();
		int end = range.upperEndpoint();
		
		try {
			IMarker m = file.createMarker(markerType);
			m.setAttribute(IMarker.CHAR_START, start);
	    	m.setAttribute(IMarker.CHAR_END, end);
	    	if (message.length() > 0) {
	    		m.setAttribute(IMarker.MESSAGE, message);
	    	}
	    	
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	BUSY = false;
}
 
開發者ID:phoxicle,項目名稱:qvto-coverage,代碼行數:30,代碼來源:CoverageAnnotator.java

示例6: setLengthConstraint

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
/**
 * Set a new length constraint.
 *
 * @param constraint Constraint metadata
 * @param ranges Allowed ranges
 * @throws IllegalStateException if the constraint has already been set
 * @throws InvalidLengthConstraintException if one of the proposed ranges does not overlap with supertype
 * @throws NullPointerException if any of the arguments is null
 */
public final void setLengthConstraint(final @NonNull ConstraintMetaDefinition constraint,
        final @NonNull List<ValueRange> ranges) throws InvalidLengthConstraintException {
    Preconditions.checkState(lengthConstraint == null, "Length constraint already defined as %s", lengthConstraint);
    final LengthConstraint baseLengths = findLenghts();
    if (ranges.isEmpty()) {
        lengthConstraint = baseLengths;
        return;
    }

    // Run through alternatives and resolve them against the base type
    requireNonNull(constraint);
    final Builder<Integer> builder = ImmutableRangeSet.builder();
    final Range<Integer> span = baseLengths.getAllowedRanges().span();

    for (ValueRange c : ranges) {
        builder.add(Range.closed(resolveLength(c.lowerBound(), span), resolveLength(c.upperBound(), span)));
    }


    // Now verify if new ranges are strict subset of base ranges
    final RangeSet<Integer> allowed = builder.build();
    final RangeSet<Integer> baseRanges = baseLengths.getAllowedRanges();
    for (Range<Integer> range : allowed.asRanges()) {
        if (!baseRanges.encloses(range)) {
            throw new InvalidLengthConstraintException("Range %s is not a subset of parent constraint %s", range,
                baseRanges);
        }
    }

    lengthConstraint = new ResolvedLengthConstraint(constraint, allowed);
    touch();
}
 
開發者ID:opendaylight,項目名稱:yangtools,代碼行數:42,代碼來源:LengthRestrictedTypeBuilder.java

示例7: getTotalCompletedTimeFromEventPairs

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
/**
 * Get the summed elapsed time from all matched event pairs. Does not consider unmatched event
 * pairs. Pairs are determined by their {@link com.facebook.buck.event.EventKey}.
 *
 * @param eventPairs a set of paired events (incomplete events are okay).
 * @return the sum of all times between matched event pairs.
 */
protected static long getTotalCompletedTimeFromEventPairs(Collection<EventPair> eventPairs) {
  long totalTime = 0L;
  // Flatten the event groupings into a timeline, so that we don't over count parallel work.
  RangeSet<Long> timeline = TreeRangeSet.create();
  for (EventPair pair : eventPairs) {
    if (pair.isComplete() && pair.getElapsedTimeMs() > 0) {
      timeline.add(Range.open(pair.getStartTime(), pair.getEndTime()));
    }
  }
  for (Range<Long> range : timeline.asRanges()) {
    totalTime += range.upperEndpoint() - range.lowerEndpoint();
  }
  return totalTime;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:22,代碼來源:AbstractConsoleEventBusListener.java

示例8: run

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
@Override
public void run() {
	// TODO Auto-generated method stub
	Map<String, Sequence> sequence_map = Sequence.parseFastaFileAsMap(query_file);
	
	String line;
	String[] s;
	Set<String> seq_rm = new HashSet<String>();
	try {
		BufferedReader br_blast6 = new BufferedReader(new FileReader(blast_out));
		Set<Blast6Record> buffer_b6 = new HashSet<Blast6Record>();
		line = br_blast6.readLine();
		String qseqid;
		while( line!=null ) {
			s = line.split("\\s+");
			qseqid = s[0];
			
			buffer_b6.clear();
			
			buffer_b6.add(Blast6Record.blast6Record(line));
			while( (line=br_blast6.readLine())!=null && 
					line.startsWith(qseqid) ) 
				buffer_b6.add(Blast6Record.blast6Record(line));		
			
			int sz = sequence_map.get(qseqid).seq_ln();
		
			RangeSet<Integer> range_covered = TreeRangeSet.create();
			for(Blast6Record record : buffer_b6) {
				if( !seq_rm.contains(record.sseqid()) &&
						!record.qseqid().equals(record.sseqid()) &&
						record.pident()>=min_ident && 
						record.length()>=min_match &&
						(record.qstart()<=max_overhang ||
						record.qend()>sz-max_overhang) )
				range_covered.add(Range.closedOpen(record.qstart(), record.qend()).canonical(DiscreteDomain.integers()));
			}

			int unique_cvg = 0;
			for(Range<Integer> range : range_covered.asRanges()) 
				unique_cvg += range.upperEndpoint()-range.lowerEndpoint();

			if( (double)unique_cvg/sz>=min_frac ) {
				seq_rm.add(qseqid);
				myLogger.info("Redundant sequence "+qseqid+"\t"+sz+"\t"+unique_cvg+"\t"+(double)unique_cvg/sz);
			}
		}
		br_blast6.close();
	
		BufferedWriter bw_unique = Utils.getBufferedWriter(this.out_prefix+".fa");
		BufferedWriter bw_redundas = Utils.getBufferedWriter(this.out_prefix+"_redundas.fa");
		for(Map.Entry<String, Sequence> entry : sequence_map.entrySet()) {
			if(seq_rm.contains(entry.getKey())) 
				bw_redundas.write(entry.getValue().formatOutput());
			else bw_unique.write(entry.getValue().formatOutput());
		}
		bw_unique.close();
		bw_redundas.close();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:c-zhou,項目名稱:polyGembler,代碼行數:63,代碼來源:Redundas.java

示例9: testTypedefRangesResolving

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
@Test
public void testTypedefRangesResolving() throws ParseException {
    final LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(),
        "int32-leaf"));

    final Int32TypeDefinition leafType = (Int32TypeDefinition) int32Leaf.getType();
    assertEquals(QName.create(FOO, "int32-ext2"), leafType.getQName());
    assertEquals(Optional.of("mile"), leafType.getUnits());
    assertEquals(Optional.of("11"), leafType.getDefaultValue());

    final RangeSet<? extends Number> rangeset = leafType.getRangeConstraint().get().getAllowedRanges();
    final Set<? extends Range<? extends Number>> ranges = rangeset.asRanges();
    assertEquals(1, ranges.size());

    final Range<? extends Number> range = ranges.iterator().next();
    assertEquals(12, range.lowerEndpoint().intValue());
    assertEquals(20, range.upperEndpoint().intValue());

    final Int32TypeDefinition firstBaseType = leafType.getBaseType();
    assertEquals(QName.create(BAR, "int32-ext2"), firstBaseType.getQName());
    assertEquals(Optional.of("mile"), firstBaseType.getUnits());
    assertEquals(Optional.of("11"), firstBaseType.getDefaultValue());

    final RangeSet<? extends Number> firstRangeset = firstBaseType.getRangeConstraint().get().getAllowedRanges();
    final Set<? extends Range<? extends Number>> baseRanges = firstRangeset.asRanges();
    assertEquals(2, baseRanges.size());

    final Iterator<? extends Range<? extends Number>> it = baseRanges.iterator();
    final Range<? extends Number> baseTypeRange1 = it.next();
    assertEquals(3, baseTypeRange1.lowerEndpoint().intValue());
    assertEquals(9, baseTypeRange1.upperEndpoint().intValue());
    final Range<? extends Number> baseTypeRange2 = it.next();
    assertEquals(11, baseTypeRange2.lowerEndpoint().intValue());
    assertEquals(20, baseTypeRange2.upperEndpoint().intValue());

    final Int32TypeDefinition secondBaseType = firstBaseType.getBaseType();
    final QName baseQName = secondBaseType.getQName();
    assertEquals("int32-ext1", baseQName.getLocalName());
    assertEquals(BAR, baseQName.getModule());
    assertEquals(Optional.empty(), secondBaseType.getUnits());
    assertEquals(Optional.empty(), secondBaseType.getDefaultValue());

    final Set<? extends Range<? extends Number>> secondRanges = secondBaseType.getRangeConstraint().get()
            .getAllowedRanges().asRanges();
    assertEquals(1, secondRanges.size());
    final Range<? extends Number> secondRange = secondRanges.iterator().next();
    assertEquals(2, secondRange.lowerEndpoint().intValue());
    assertEquals(20, secondRange.upperEndpoint().intValue());

    assertEquals(BaseTypes.int32Type(), secondBaseType.getBaseType());
}
 
開發者ID:opendaylight,項目名稱:yangtools,代碼行數:52,代碼來源:YangParserTest.java

示例10: call

import com.google.common.collect.RangeSet; //導入方法依賴的package包/類
@Override
public Integer call() throws Exception {
    PrintWriter writer = null;
    try {
        writer = writer(evalFile);

        Sequence reference = readReference();
        List<Sequence> scaffolds = readScaffolds();

        writer.println("#reference length = " + reference.length());
        writer.println("#scaffold count = " + scaffolds.size());
        writer.println("#scaffold lengths = " + dumpLengths(scaffolds));

        RangeSet<Long> ranges = TreeRangeSet.create();
        for (HighScoringPair hsp : blastn(referenceFastaFile, scaffoldsFastaFile)) {
            if (reference.getName().equals(hsp.target())) {
                writer.println("#" + hsp.toString());
                if (hsp.targetStart() <= hsp.targetEnd()) { // strands match
                    ranges.add(Range.closed(hsp.targetStart(), hsp.targetEnd()));
                }
                else {
                    ranges.add(Range.closed(hsp.targetEnd(), hsp.targetStart()));
                }
            }
        }

        writer.println("#coalesced intervals = " + ranges);

        long breadthOfCoverage = 0;
        for (Range<Long> range : ranges.asRanges()) {
            breadthOfCoverage += ContiguousSet.create(range, DiscreteDomain.longs()).size();
        }
        double normalizedBreadthOfCoverage = (double) breadthOfCoverage / (double) reference.length();
        writer.println("#breadth-of-coverage = " + breadthOfCoverage);
        writer.println("#normalized breadth-of-coverage = " + normalizedBreadthOfCoverage);

        StringBuilder sb = new StringBuilder();
        sb.append(referenceFastaFile.getName());
        sb.append("\t");
        sb.append(scaffoldsFastaFile.getName());
        sb.append("\t");
        sb.append(reference.length());
        sb.append("\t");
        sb.append(scaffolds.size());
        sb.append("\t");
        sb.append(ranges.asRanges().size());
        sb.append("\t");
        sb.append(breadthOfCoverage);
        sb.append("\t");
        sb.append(normalizedBreadthOfCoverage);
        sb.append("\t");
        writer.println(sb.toString());

        return 0;
    }
    finally {
        try {
            writer.close();
        }
        catch (Exception e) {
            // ignore
        }
    }
}
 
開發者ID:nmdp-bioinformatics,項目名稱:ngs,代碼行數:65,代碼來源:EvaluateScaffolds.java


注:本文中的com.google.common.collect.RangeSet.asRanges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。