Exemplo n.º 1
0
  @Override
  public DisposableRangeIterator getRangeIterator(boolean bottomUp) {
    if (_riterator == null || !_riterator.isReusable()) {
      _riterator =
          new DisposableRangeIterator() {

            int from;
            int to;

            @Override
            public void bottomUpInit() {
              super.bottomUpInit();
              this.from = VALUES.nextSetBit(0);
              this.to = VALUES.nextClearBit(from + 1) - 1;
            }

            @Override
            public void topDownInit() {
              super.topDownInit();
              this.to = VALUES.prevSetBit(VALUES.size() - 1);
              this.from = VALUES.prevClearBit(to) + 1;
            }

            public boolean hasNext() {
              return this.from != -1;
            }

            @Override
            public boolean hasPrevious() {
              return this.to != -1;
            }

            public void next() {
              this.from = VALUES.nextSetBit(this.to + 1);
              this.to = VALUES.nextClearBit(this.from) - 1;
            }

            @Override
            public void previous() {
              this.to = VALUES.prevSetBit(this.from - 1);
              this.from = VALUES.prevClearBit(this.to) + 1;
            }

            @Override
            public int min() {
              return from + OFFSET;
            }

            @Override
            public int max() {
              return to + OFFSET;
            }
          };
    }
    if (bottomUp) {
      _riterator.bottomUpInit();
    } else {
      _riterator.topDownInit();
    }
    return _riterator;
  }
Exemplo n.º 2
0
  @Override
  public DisposableRangeIterator getRangeIterator(boolean bottomUp) {
    if (_riterator == null || !_riterator.isReusable()) {
      _riterator =
          new DisposableRangeIterator() {

            DisposableRangeIterator vir;

            @Override
            public void bottomUpInit() {
              super.bottomUpInit();
              vir = var.getRangeIterator(true);
            }

            @Override
            public void topDownInit() {
              super.topDownInit();
              vir = var.getRangeIterator(false);
            }

            @Override
            public boolean hasNext() {
              return vir.hasNext();
            }

            @Override
            public boolean hasPrevious() {
              return vir.hasPrevious();
            }

            @Override
            public void next() {
              vir.next();
            }

            @Override
            public void previous() {
              vir.previous();
            }

            @Override
            public int min() {
              return vir.min() + cste;
            }

            @Override
            public int max() {
              return vir.max() + cste;
            }

            @Override
            public void dispose() {
              super.dispose();
              vir.dispose();
            }
          };
    }
    if (bottomUp) {
      _riterator.bottomUpInit();
    } else {
      _riterator.topDownInit();
    }
    return _riterator;
  }