Package org.apache.accumulo.core.client.mock

Source Code of org.apache.accumulo.core.client.mock.MockScanner$RangeFilter

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.accumulo.core.client.mock;

import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.FilteringIterator;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.apache.accumulo.core.iterators.SortedMapIterator;
import org.apache.accumulo.core.iterators.filter.Filter;
import org.apache.accumulo.core.security.Authorizations;

public class MockScanner extends MockScannerBase implements Scanner {
 
  int timeOut = 0;
  int batchSize = 0;
  Range range = new Range();
 
  MockScanner(MockTable table, Authorizations auths) {
    super(table, auths);
  }
 
  @Override
  public void setTimeOut(int timeOut) {
    this.timeOut = timeOut;
  }
 
  @Override
  public int getTimeOut() {
    return timeOut;
  }
 
  @Override
  public void setRange(Range range) {
    this.range = range;
  }
 
  @Override
  public Range getRange() {
    return this.range;
  }
 
  @Override
  public void setBatchSize(int size) {
    this.batchSize = size;
  }
 
  @Override
  public int getBatchSize() {
    return this.batchSize;
  }
 
  @Override
  public void enableIsolation() {}
 
  @Override
  public void disableIsolation() {}
 
  static class RangeFilter implements Filter {
    Range range;
   
    public RangeFilter(Range range) {
      this.range = range;
    }
   
    @Override
    public void init(Map<String,String> options) {}
   
    @Override
    public boolean accept(Key k, Value v) {
      return range.contains(k);
    }
  }
 
  @Override
  public Iterator<Entry<Key,Value>> iterator() {
    SortedKeyValueIterator<Key,Value> i = new SortedMapIterator(table.table);
    try {
      i = createFilter(i);
      i.seek(range, createColumnBSS(columns), !columns.isEmpty());
      return new IteratorAdapter(new FilteringIterator(i, Collections.singletonList(new RangeFilter(range))));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
   
  }
 
}
TOP

Related Classes of org.apache.accumulo.core.client.mock.MockScanner$RangeFilter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.