当前位置: 首页>>代码示例>>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;未经允许,请勿转载。