Example #1
0
 @Test
 public void headtail() {
   Range<Integer> range = new IntRange(0, 5).incrementBy(2);
   assertThat(range.isEmpty(), is(false));
   assertThat(range.head(), is(0));
   assertThat(range.tail().head(), is(2));
   assertThat(range.tail().tail().head(), is(4));
   assertThat(range.tail().tail().tail().isEmpty(), is(true));
 }
Example #2
0
  @Test
  public void empty() {
    List<IntRange> ranges = asList(new IntRange(0, 0), new IntRange(5, 4));

    for (Range<Integer> range : ranges) {
      assertThat(range.iterator().hasNext(), is(false));
      assertThat(range.isEmpty(), is(true));
      assertThat(range.size(), is(0));
      assertThat((Object) range.head(), is(nullValue()));
      assertThat(range.tail().isEmpty(), is(true));
    }
  }
 void addRange(Range range, TextSectionMapping mapTable, VmResourceId destinationResource) {
   RangeGroup structure = getSafe(rangeMap, range.start);
   if (structure == null) {
     structure = new RangeGroup();
     this.rangeMap.put(range.start, structure);
   }
   if (range.isEmpty()) {
     structure.emptyRangesAtStart++;
   } else {
     if (structure.nonEmptyRangeMapping != null) {
       throw new RuntimeException();
     }
     structure.nonEmptyRangeMapping = new RangeMapping(range, destinationResource, mapTable);
   }
 }
Example #4
0
    public boolean shouldComplete(NativeEvent event) {
      // Never complete if there's an active selection
      Range range = getSession().getSelection().getRange();
      if (!range.isEmpty()) return false;

      // Don't consider Tab to be a completion if we're at the start of a
      // line (e.g. only zero or more whitespace characters between the
      // beginning of the line and the cursor)

      if (event != null && event.getKeyCode() != KeyCodes.KEY_TAB) return true;

      int col = range.getStart().getColumn();
      if (col == 0) return false;

      String row = getSession().getLine(range.getStart().getRow());
      return row.substring(0, col).trim().length() != 0;
    }
 public void removeRange(Range range) {
   RangeGroup rangeGroup = rangeMap.get(range.start);
   if (range.isEmpty()) {
     if (rangeGroup.emptyRangesAtStart <= 0) {
       throw new IllegalStateException();
     }
     rangeGroup.emptyRangesAtStart--;
   } else {
     if (rangeGroup.nonEmptyRangeMapping == null
         || !range.equals(rangeGroup.nonEmptyRangeMapping.sourceRange)) {
       throw new IllegalStateException();
     }
     rangeGroup.nonEmptyRangeMapping = null;
   }
   if (rangeGroup.nonEmptyRangeMapping == null && rangeGroup.emptyRangesAtStart == 0) {
     rangeMap.remove(range.start);
   }
 }