Java Code Examples for com.google.common.collect.Range#closedOpen()

The following examples show how to use com.google.common.collect.Range#closedOpen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaOutput.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Flush any incomplete last line, then add the EOF token into our data structures.
 */
void flush() {
    String lastLine = lineBuilder.toString();
    if (!lastLine.isEmpty()) {
        mutableLines.add(lastLine);
    }
    int jN = mutableLines.size();
    Range<Integer> eofRange = Range.closedOpen(kN, kN + 1);
    while (range0s.size() < jN) {
        range0s.add(Formatter.EMPTY_RANGE);
    }
    range0s.add(eofRange);
    while (ranges.size() < jN) {
        ranges.add(Formatter.EMPTY_RANGE);
    }
    ranges.add(eofRange);
    while (range1s.size() < jN) {
        range1s.add(Formatter.EMPTY_RANGE);
    }
    range1s.add(eofRange);
    setLines(ImmutableList.copyOf(mutableLines));
}
 
Example 2
Source File: JavaIdentifierAnnotatedTokenizer.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public String getIdentifierType(final PublicScanner scanner) {
	final int startPos = scanner.getCurrentTokenStartPosition();
	final int endPos = scanner.getCurrentTokenEndPosition();
	final Range<Integer> tokenRange = Range
			.closedOpen(startPos, endPos);

	final String tokenName = scanner.getCurrentTokenString();

	// TODO: Find the tightest of all
	if (isInSet(tokenName, tokenRange, variables)) {
		return IDENTIFIER_PREFIX + "_VAR";
	} else if (isInSet(tokenName, tokenRange, methods)) {
		return IDENTIFIER_PREFIX + "_METHOD";
	} else if (isInSet(tokenName, tokenRange, types)) {
		return IDENTIFIER_PREFIX + "_TYPE";
	}
	return IDENTIFIER_PREFIX + "_UNK";
}
 
Example 3
Source File: MetricCalculator.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Timed("sla_stats_computation")
@Override
public void run() {
  FluentIterable<IScheduledTask> tasks =
      FluentIterable.from(Storage.Util.fetchTasks(storage, Query.unscoped()));

  List<IScheduledTask> prodTasks = tasks.filter(Predicates.compose(
      Predicates.and(ITaskConfig::isProduction, IS_SERVICE),
      Tasks::getConfig)).toList();

  List<IScheduledTask> nonProdTasks = tasks.filter(Predicates.compose(
      Predicates.and(Predicates.not(ITaskConfig::isProduction), IS_SERVICE),
      Tasks::getConfig)).toList();

  long nowMs = clock.nowMillis();
  Range<Long> timeRange = Range.closedOpen(nowMs - settings.refreshRateMs, nowMs);

  runAlgorithms(prodTasks, settings.prodMetrics, timeRange, NAME_QUALIFIER_PROD);
  runAlgorithms(nonProdTasks, settings.nonProdMetrics, timeRange, NAME_QUALIFIER_NON_PROD);
}
 
Example 4
Source File: JavaIdentifierAnnotatedTokenizer.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public String getIdentifierType(final PublicScanner scanner) {
	final int startPos = scanner.getCurrentTokenStartPosition();
	final int endPos = scanner.getCurrentTokenEndPosition();
	final Range<Integer> tokenRange = Range
			.closedOpen(startPos, endPos);

	final String tokenName = scanner.getCurrentTokenString();

	// TODO: Find the tightest of all
	if (isInSet(tokenName, tokenRange, variables)) {
		return IDENTIFIER_PREFIX + "_VAR";
	} else if (isInSet(tokenName, tokenRange, methods)) {
		return IDENTIFIER_PREFIX + "_METHOD";
	} else if (isInSet(tokenName, tokenRange, types)) {
		return IDENTIFIER_PREFIX + "_TYPE";
	}
	return IDENTIFIER_PREFIX + "_UNK";
}
 
Example 5
Source File: TemporaryPorts.java    From helios with Apache License 2.0 5 votes vote down vote up
public synchronized Range<Integer> localPortRange(final String name, final int idx) {
  Preconditions.checkState(!closed, "closed");
  for (int i = 0; i < retries; i++) {
    final int base = randomPort();
    final List<AllocatedPort> rangePorts = Lists.newArrayList();
    boolean successful = true;
    for (int j = 0; j < idx; j++) {
      final int port = base + j;
      final AllocatedPort allocatedPort = lock(port, name);
      if (allocatedPort == null) {
        successful = false;
        break;
      }
      rangePorts.add(allocatedPort);
      if (!available(port)) {
        successful = false;
        break;
      }
    }
    if (successful) {
      ports.addAll(rangePorts);
      return Range.closedOpen(base, base + idx);
    } else {
      rangePorts.forEach(AllocatedPort::release);
    }
  }
  throw new AllocationFailedException();
}
 
Example 6
Source File: IdentifierPerType.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static final void addToMap(
		final Map<String, RangeSet<Integer>> identifiers,
		final ASTNode node, final String identifier) {
	final int startPosition = node.getStartPosition();
	final Range<Integer> nodeRange = Range.closedOpen(startPosition,
			startPosition + node.getLength());

	RangeSet<Integer> idRanges = identifiers.get(identifier);
	if (idRanges == null) {
		idRanges = TreeRangeSet.create();
		identifiers.put(identifier, idRanges);
	}

	idRanges.add(nodeRange);
}
 
Example 7
Source File: KeyRangeUtils.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example 8
Source File: TestAffinityCalculator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 9
Source File: AnnotateVariants.java    From dataflow-java with Apache License 2.0 5 votes vote down vote up
private String getCachedTranscriptBases(Genomics genomics, Annotation transcript)
    throws IOException {
  Range<Long> rng = Range.closedOpen(transcript.getStart(), transcript.getEnd());
  if (!refBaseCache.containsKey(rng)) {
    refBaseCache.put(rng, retrieveReferenceBases(genomics, transcript));
  }
  return refBaseCache.get(rng);
}
 
Example 10
Source File: DeliveryAddressController.java    From pizzeria with MIT License 5 votes vote down vote up
@GetMapping("/{deliveryAddressIndex}/remove")
public String removeDeliveryAddress(@PathVariable("deliveryAddressIndex") int deliveryAddressIndex, @RequestParam(name = "returnUrl", defaultValue = "/customer") String returnUrl, Principal principal, RedirectAttributes redirectAttributes) {
    Customer customer = getCustomerFromPrincipal(principal);
    Range<Integer> indexRange = Range.closedOpen(0, customer.getDeliveryAddresses().size());
    if (indexRange.contains(deliveryAddressIndex)) {
        customer.getDeliveryAddresses().remove(deliveryAddressIndex);
        customerService.updateCustomer(customer);
    }
    return Joiner.on(StringUtils.EMPTY).join("redirect:", returnUrl);
}
 
Example 11
Source File: JavaOutput.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Expand a token range to start and end on acceptable boundaries for re-formatting.
 *
 * @param iRange the {@link Range} of tokens
 * @return the expanded token range
 */
private Range<Integer> expandToBreakableRegions(Range<Integer> iRange) {
    // The original line range.
    int loTok = iRange.lowerEndpoint();
    int hiTok = iRange.upperEndpoint() - 1;

    // Expand the token indices to formattable boundaries (e.g. edges of statements).
    if (!partialFormatRanges.contains(loTok) || !partialFormatRanges.contains(hiTok)) {
        return EMPTY_RANGE;
    }
    loTok = partialFormatRanges.rangeContaining(loTok).lowerEndpoint();
    hiTok = partialFormatRanges.rangeContaining(hiTok).upperEndpoint();
    return Range.closedOpen(loTok, hiTok + 1);
}
 
Example 12
Source File: JavaOutput.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** Flush any incomplete last line, then add the EOF token into our data structures. */
public void flush() {
  String lastLine = lineBuilder.toString();
  if (!CharMatcher.whitespace().matchesAllOf(lastLine)) {
    mutableLines.add(lastLine);
  }
  int jN = mutableLines.size();
  Range<Integer> eofRange = Range.closedOpen(kN, kN + 1);
  while (ranges.size() < jN) {
    ranges.add(Formatter.EMPTY_RANGE);
  }
  ranges.add(eofRange);
  setLines(ImmutableList.copyOf(mutableLines));
}
 
Example 13
Source File: SnippetFormatter.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static Range<Integer> offsetRange(Range<Integer> range, int offset) {
    range = range.canonical(DiscreteDomain.integers());
    return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset);
}
 
Example 14
Source File: RangeTest.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testClosed() {

    Range anull = Range.closedOpen(0, 0);

    Range r1 = Range.closed(2, 5);

    Range a1 = Range.open(1, 2);
    Range a2 = Range.open(1, 3);
    Range a3 = Range.open(1, 5);
    Range a4 = Range.open(1, 6);
    Range a5 = Range.open(6, 7);
    Range a6 = Range.open(5, 7);
    Range a7 = Range.open(4, 7);
    Range a8 = Range.open(2, 7);
    Range a9 = Range.open(1, 7);

    Range b1 = Range.closed(1, 2);
    Range b2 = Range.closed(1, 3);
    Range b3 = Range.closed(1, 5);
    Range b4 = Range.closed(1, 6);
    Range b5 = Range.closed(6, 7);
    Range b6 = Range.closed(5, 7);
    Range b7 = Range.closed(4, 7);
    Range b8 = Range.closed(2, 7);
    Range b9 = Range.closed(1, 7);

    Range c1 = Range.open(2, 3);
    Range c2 = Range.open(3, 4);
    Range c3 = Range.open(4, 5);

    Range d1 = Range.closed(2, 3);
    Range d2 = Range.closed(3, 4);
    Range d3 = Range.closed(4, 5);

    Assert.assertTrue(RangeUtil.remove(r1, anull).equals(Lists.newArrayList(r1)));
    Assert.assertTrue(RangeUtil.remove(r1, a1).equals(Lists.newArrayList(r1)));
    Assert.assertTrue(RangeUtil.remove(r1, a2).equals(Lists.newArrayList(Range.closed(3, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, a3).equals(Lists.newArrayList(Range.closed(5, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, a4).equals(Lists.newArrayList()));
    Assert.assertTrue(RangeUtil.remove(r1, a5).equals(Lists.newArrayList(r1)));
    Assert.assertTrue(RangeUtil.remove(r1, a6).equals(Lists.newArrayList(r1)));
    Assert.assertTrue(RangeUtil.remove(r1, a7).equals(Lists.newArrayList(Range.closed(2, 4))));
    Assert.assertTrue(RangeUtil.remove(r1, a8).equals(Lists.newArrayList(Range.closed(2, 2))));
    Assert.assertTrue(RangeUtil.remove(r1, a9).equals(Lists.newArrayList()));

    Assert.assertTrue(RangeUtil.remove(r1, b1).equals(Lists.newArrayList(Range.openClosed(2, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, b2).equals(Lists.newArrayList(Range.openClosed(3, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, b3).equals(Lists.newArrayList()));
    Assert.assertTrue(RangeUtil.remove(r1, b4).equals(Lists.newArrayList()));
    Assert.assertTrue(RangeUtil.remove(r1, b5).equals(Lists.newArrayList(r1)));
    Assert.assertTrue(RangeUtil.remove(r1, b6).equals(Lists.newArrayList(Range.closedOpen(2, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, b7).equals(Lists.newArrayList(Range.closedOpen(2, 4))));
    Assert.assertTrue(RangeUtil.remove(r1, b8).equals(Lists.newArrayList()));
    Assert.assertTrue(RangeUtil.remove(r1, b9).equals(Lists.newArrayList()));

    Assert.assertTrue(RangeUtil.remove(r1, c1).equals(Lists.newArrayList(Range.closed(2, 2), Range.closed(3, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, c2).equals(Lists.newArrayList(Range.closed(2, 3), Range.closed(4, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, c3).equals(Lists.newArrayList(Range.closed(2, 4), Range.closed(5, 5))));

    Assert.assertTrue(RangeUtil.remove(r1, d1).equals(Lists.newArrayList(Range.openClosed(3, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, d2).equals(Lists.newArrayList(Range.closedOpen(2, 3), Range.openClosed(4, 5))));
    Assert.assertTrue(RangeUtil.remove(r1, d3).equals(Lists.newArrayList(Range.closedOpen(2, 4))));

}
 
Example 15
Source File: Replacement.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public static Replacement create(int startPosition, int endPosition, String replaceWith) {
    return new Replacement(Range.closedOpen(startPosition, endPosition), replaceWith);
}
 
Example 16
Source File: BasicFormatMatcher.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public RangeMagics(MagicString ms) {
  this.range = Range.closedOpen( ms.getOffset(), (long) ms.getBytes().length);
  this.magics = new byte[][]{ms.getBytes()};
}
 
Example 17
Source File: GVCFWriterUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testToVCFHeaderLine() {
    final Range<Integer> band = Range.closedOpen(10,20);
    Assert.assertEquals(GVCFBlockCombiner.rangeToVCFHeaderLine(band).getKey(), "GVCFBlock10-20", "Wrong key for " + band);
    Assert.assertEquals(GVCFBlockCombiner.rangeToVCFHeaderLine(band).getValue(), "minGQ=10(inclusive),maxGQ=20(exclusive)", "Wrong value for" + band);
}
 
Example 18
Source File: SnippetFormatter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static Range<Integer> offsetRange(Range<Integer> range, int offset) {
    range = range.canonical(DiscreteDomain.integers());
    return Range.closedOpen(range.lowerEndpoint() + offset, range.upperEndpoint() + offset);
}
 
Example 19
Source File: PartialFormattingTest.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
private Range<Integer> rangeOf(String input, String needle) {
  int idx = input.indexOf(needle);
  return Range.closedOpen(idx, idx + needle.length());
}
 
Example 20
Source File: PartitionChunkId.java    From dremio-oss with Apache License 2.0 3 votes vote down vote up
/**
 * Create a range for partition chunk id
 *
 * Create a range to check if a split id belongs to the provided dataset id and its version is comprised
 * into startSplitVersion (included) and endSplitVersion (excluded).
 *
 * @param datasetId the dataset id
 * @param startSplitVersion the minimum split version
 * @param endSplitVersion the maximum split version
 * @return
 */
public static Range<PartitionChunkId> getSplitRange(EntityId datasetId, long startSplitVersion, long endSplitVersion) {
  // create start and end id with empty split identifier
  final PartitionChunkId start = getId(datasetId, startSplitVersion);
  final PartitionChunkId end = getId(datasetId, endSplitVersion);
  return Range.closedOpen(start, end);
}