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


Java Range.closedOpen方法代碼示例

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


在下文中一共展示了Range.closedOpen方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: intRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
@Test
public void intRange() throws Exception {
    Entropy e = new MutableEntropy(SEED);
    Range<Integer> range = Range.closedOpen(-5, 5);
    Multiset<Integer> distribution = HashMultiset.create();

    // Choose 1k values and check that they are in the range
    for(int i = 0; i < 10000; i++) {
        final int value = e.randomInt(range);
        assertContains(range, value);
        distribution.add(value);
        e.advance();
    }

    // Assert that each of the 10 values was chosen ~1000 times
    Ranges.forEach(range, value -> {
        assertEquals(1000D, distribution.count(value), 50D);
    });
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:20,代碼來源:EntropyTest.java

示例2: lineRangesToCharRanges

import com.google.common.collect.Range; //導入方法依賴的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

示例3: buildBlockMap

import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
 * Builds a mapping of block locations to file byte range
 */
private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException {
  final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time();
  BlockLocation[] blocks;
  ImmutableRangeMap<Long,BlockLocation> blockMap;
  blocks = fs.getFileBlockLocations(status, 0 , status.getLen());
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  blockMap = blockMapBuilder.build();
  blockMapMap.put(status.getPath(), blockMap);
  context.stop();
  return blockMap;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:21,代碼來源:BlockMapBuilder.java

示例4: matches

import com.google.common.collect.Range; //導入方法依賴的package包/類
public boolean matches(DrillFileSystem fs, FileStatus status) throws IOException{
  if (ranges.isEmpty()) {
    return false;
  }
  final Range<Long> fileRange = Range.closedOpen( 0L, status.getLen());

  try (FSDataInputStream is = fs.open(status.getPath())) {
    for(RangeMagics rMagic : ranges) {
      Range<Long> r = rMagic.range;
      if (!fileRange.encloses(r)) {
        continue;
      }
      int len = (int) (r.upperEndpoint() - r.lowerEndpoint());
      byte[] bytes = new byte[len];
      is.readFully(r.lowerEndpoint(), bytes);
      for (byte[] magic : rMagic.magics) {
        if (Arrays.equals(magic, bytes)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:25,代碼來源:BasicFormatMatcher.java

示例5: getRangeMap

import com.google.common.collect.Range; //導入方法依賴的package包/類
protected RangeMap<Integer, ScenarioDefinition> getRangeMap(FeatureWrapper feature) {
	List<ScenarioDefinition> children = Lists.newArrayList(feature.getChildren());

	ImmutableRangeMap.Builder<Integer, ScenarioDefinition> builder = ImmutableRangeMap.builder();
	while (!children.isEmpty()) {
		ScenarioDefinition child = children.remove(0);
		Location location = child.getLocation();
		Integer childStart = location.getLine();

		ScenarioDefinition sibling = children.isEmpty() ? null : children.get(0);
		Location siblingLocation = null == sibling ? null : sibling.getLocation();
		Integer siblingStart = null == siblingLocation ? null : siblingLocation.getLine();

		Range<Integer> range = null == siblingStart ? Range.atLeast(childStart) : Range.closedOpen(childStart, siblingStart);
		builder.put(range, child);
	}
	return builder.build();
}
 
開發者ID:qas-guru,項目名稱:martini-core,代碼行數:19,代碼來源:DefaultMixology.java

示例6: buildBlockMap

import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
 * Builds a mapping of block locations to file byte range
 */
private ImmutableRangeMap<Long,BlockLocation> buildBlockMap(FileStatus status) throws IOException {
  final Timer.Context context = metrics.timer(BLOCK_MAP_BUILDER_TIMER).time();
  BlockLocation[] blocks;
  ImmutableRangeMap<Long,BlockLocation> blockMap;
  blocks = fs.getFileBlockLocations(status, 0 , status.getLen());
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  blockMap = blockMapBuilder.build();
  blockMapMap.put(status.getPath(), blockMap);
  context.stop();
  return blockMap;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:21,代碼來源:BlockMapBuilder.java

示例7: buildProgressAsset

import com.google.common.collect.Range; //導入方法依賴的package包/類
private ProgressAsset buildProgressAsset(Map<Integer, List<ShowImageDTO>> resolvedConfig, int index) {
    ProgressAsset progressAsset = new ProgressAsset(index);
    int lowerBound = Integer.MIN_VALUE;
    ShowImageDTO imageDTO = new ShowImageDTO("", new Size(0, 0));
    for (Entry<Integer, List<ShowImageDTO>> element : resolvedConfig.entrySet()) {
        Range<Integer> range = Range.closedOpen(lowerBound, element.getKey());
        progressAsset.add(range, imageDTO);
        lowerBound = element.getKey();
        imageDTO = getElementAtIndex(element.getValue(), index);
    }
    Range<Integer> lastRange = Range.atLeast(lowerBound);
    progressAsset.add(lastRange, imageDTO);

    return progressAsset;
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:16,代碼來源:ProgressAssetProvider.java

示例8: testBuildRangeMap

import com.google.common.collect.Range; //導入方法依賴的package包/類
@Test
public void testBuildRangeMap() {
  BlockLocation[] blocks = buildBlockLocations(new String[4], 256*1024*1024);
  long tA = System.nanoTime();
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  ImmutableRangeMap<Long,BlockLocation> map = blockMapBuilder.build();
  long tB = System.nanoTime();
  System.out.println(String.format("Took %f ms to build range map", (tB - tA) / 1e6));
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:16,代碼來源:TestAffinityCalculator.java

示例9: getSplitStringRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
public static Range<String> getSplitStringRange(DatasetConfig datasetConfig){
  final long splitVersion = datasetConfig.getReadDefinition().getSplitVersion();
  final long nextSplitVersion = splitVersion + 1;
  final String datasetId = datasetConfig.getId().getId();

  // create start and end id with empty split identifier
  final String start = getStringId(datasetId, splitVersion);
  final String end = getStringId(datasetId, nextSplitVersion);
  return Range.closedOpen(start, end);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:11,代碼來源:DatasetSplitId.java

示例10: matches

import com.google.common.collect.Range; //導入方法依賴的package包/類
public boolean matches(FileSystemWrapper fs, FileStatus status) throws IOException{
  if (ranges.isEmpty() || status.isDirectory()) {
    return false;
  }
  // walk all the way down in the symlinks until a hard entry is reached
  FileStatus current = status;
  while (current.isSymlink()) {
    current = fs.getFileStatus(status.getSymlink());
  }
  // if hard entry is not a file nor can it be a symlink then it is not readable simply deny matching.
  if (!current.isFile()) {
    return false;
  }

  final Range<Long> fileRange = Range.closedOpen( 0L, status.getLen());

  try (FSDataInputStream is = fs.open(status.getPath())) {
    for(RangeMagics rMagic : ranges) {
      Range<Long> r = rMagic.range;
      if (!fileRange.encloses(r)) {
        continue;
      }
      int len = (int) (r.upperEndpoint() - r.lowerEndpoint());
      byte[] bytes = new byte[len];
      is.readFully(r.lowerEndpoint(), bytes);
      for (byte[] magic : rMagic.magics) {
        if (Arrays.equals(magic, bytes)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:35,代碼來源:BasicFormatMatcher.java

示例11: parseRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
 * Parse a range, as in "1:12" or "42". Line numbers provided are {@code 1}-based, but are
 * converted here to {@code 0}-based.
 */
private static Range<Integer> parseRange(String arg) {
    List<String> args = COLON_SPLITTER.splitToList(arg);
    switch (args.size()) {
        case 1:
            int line = Integer.parseInt(args.get(0)) - 1;
            return Range.closedOpen(line, line + 1);
        case 2:
            int line0 = Integer.parseInt(args.get(0)) - 1;
            int line1 = Integer.parseInt(args.get(1)) - 1;
            return Range.closedOpen(line0, line1 + 1);
        default:
            throw new IllegalArgumentException(arg);
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:19,代碼來源:CommandLineOptionsParser.java

示例12: characterRangeToTokenRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
/**
 * Convert from an offset and length flag pair to a token range.
 *
 * @param offset the {@code 0}-based offset in characters
 * @param length the length in characters
 * @return the {@code 0}-based {@link Range} of tokens
 * @throws FormatterException
 */
Range<Integer> characterRangeToTokenRange(int offset, int length) throws FormatterException {
    int requiredLength = offset + length;
    if (requiredLength > text.length()) {
        throw new FormatterException(
                String.format(
                        "error: invalid length %d, offset + length (%d) is outside the file",
                        length, requiredLength));
    }
    if (length < 0) {
        return EMPTY_RANGE;
    }
    if (length == 0) {
        // 0 stands for "format the line under the cursor"
        length = 1;
    }
    ImmutableCollection<Token> enclosed =
            getPositionTokenMap()
                    .subRangeMap(Range.closedOpen(offset, offset + length))
                    .asMapOfRanges()
                    .values();
    if (enclosed.isEmpty()) {
        return EMPTY_RANGE;
    }
    return Range.closedOpen(
            enclosed.iterator().next().getTok().getIndex(), getLast(enclosed).getTok().getIndex() + 1);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:35,代碼來源:JavaInput.java

示例13: testBuildRangeMap

import com.google.common.collect.Range; //導入方法依賴的package包/類
@Test
public void testBuildRangeMap() {
  BlockLocation[] blocks = buildBlockLocations(new String[4], 256*1024*1024);
  long tA = System.nanoTime();
  ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
  for (BlockLocation block : blocks) {
    long start = block.getOffset();
    long end = start + block.getLength();
    Range<Long> range = Range.closedOpen(start, end);
    blockMapBuilder = blockMapBuilder.put(range, block);
  }
  ImmutableRangeMap<Long,BlockLocation> map = blockMapBuilder.build();
  long tB = System.nanoTime();
  System.out.println(String.format("Took %f ms to build range map", (float)(tB - tA) / 1e6));
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:16,代碼來源:TestAffinityCalculator.java

示例14: toRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
public static Range toRange(Coprocessor.KeyRange range) {
  if (range == null || (range.getStart().isEmpty() && range.getEnd().isEmpty())) {
    return Range.all();
  }
  if (range.getStart().isEmpty()) {
    return Range.lessThan(Comparables.wrap(range.getEnd()));
  }
  if (range.getEnd().isEmpty()) {
    return Range.atLeast(Comparables.wrap(range.getStart()));
  }
  return Range.closedOpen(Comparables.wrap(range.getStart()), Comparables.wrap(range.getEnd()));
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:13,代碼來源:KeyRangeUtils.java

示例15: makeRange

import com.google.common.collect.Range; //導入方法依賴的package包/類
public static Range makeRange(ByteString startKey, ByteString endKey) {
  if (startKey.isEmpty() && endKey.isEmpty()) {
    return Range.all();
  }
  if (startKey.isEmpty()) {
    return Range.lessThan(Comparables.wrap(endKey));
  } else if (endKey.isEmpty()) {
    return Range.atLeast(Comparables.wrap(startKey));
  }
  return Range.closedOpen(Comparables.wrap(startKey), Comparables.wrap(endKey));
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:12,代碼來源:KeyRangeUtils.java


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