accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject [3/3] git commit: Merge branch '1.4.5-SNAPSHOT' into 1.5.1-SNAPSHOT
Date Thu, 12 Dec 2013 16:22:16 GMT
Merge branch '1.4.5-SNAPSHOT' into 1.5.1-SNAPSHOT


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/994e43c1
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/994e43c1
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/994e43c1

Branch: refs/heads/1.5.1-SNAPSHOT
Commit: 994e43c18b322148ad868807ad1836d14a3926f0
Parents: e9423ae cc68925
Author: Eric Newton <eric.newton@gmail.com>
Authored: Thu Dec 12 11:20:18 2013 -0500
Committer: Eric Newton <eric.newton@gmail.com>
Committed: Thu Dec 12 11:20:18 2013 -0500

----------------------------------------------------------------------
 .../org/apache/accumulo/core/data/Range.java    | 58 +++++++++++++++++++-
 .../apache/accumulo/core/data/RangeTest.java    | 58 ++++++++++++++++++++
 2 files changed, 113 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/994e43c1/core/src/main/java/org/apache/accumulo/core/data/Range.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/accumulo/core/data/Range.java
index 7085734,0000000..65873c3
mode 100644,000000..100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Range.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Range.java
@@@ -1,854 -1,0 +1,906 @@@
 +/*
 + * 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.data;
 +
 +import java.io.DataInput;
 +import java.io.DataOutput;
++import java.io.InvalidObjectException;
 +import java.io.IOException;
 +import java.util.ArrayList;
 +import java.util.Collection;
 +import java.util.Collections;
 +import java.util.List;
 +
 +import org.apache.accumulo.core.data.thrift.TRange;
 +import org.apache.hadoop.io.Text;
 +import org.apache.hadoop.io.WritableComparable;
 +
 +/**
 + * This class is used to specify a range of Accumulo Keys.
 + * 
 + */
 +
 +public class Range implements WritableComparable<Range> {
 +  
 +  private Key start;
 +  private Key stop;
 +  private boolean startKeyInclusive;
 +  private boolean stopKeyInclusive;
 +  private boolean infiniteStartKey;
 +  private boolean infiniteStopKey;
 +  
 +  /**
 +   * Creates a range that goes from negative to positive infinity
 +   */
 +  
 +  public Range() {
 +    this((Key) null, true, (Key) null, true);
 +  }
 +  
 +  /**
 +   * Creates a range from startKey inclusive to endKey inclusive
 +   * 
 +   * @param startKey
 +   *          set this to null when negative infinity is needed
 +   * @param endKey
 +   *          set this to null when positive infinity is needed
 +   */
 +  public Range(Key startKey, Key endKey) {
 +    this(startKey, true, endKey, true);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an entire row
 +   * 
 +   * @param row
 +   *          set this to null to cover all rows
 +   */
 +  public Range(CharSequence row) {
 +    this(row, true, row, true);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an entire row
 +   * 
 +   * @param row
 +   *          set this to null to cover all rows
 +   */
 +  public Range(Text row) {
 +    this(row, true, row, true);
 +  }
 +  
 +  /**
 +   * Creates a range from startRow inclusive to endRow inclusive
 +   * 
 +   * @param startRow
 +   *          set this to null when negative infinity is needed
 +   * @param endRow
 +   *          set this to null when positive infinity is needed
 +   */
 +  public Range(Text startRow, Text endRow) {
 +    this(startRow, true, endRow, true);
 +  }
 +  
 +  /**
 +   * Creates a range from startRow inclusive to endRow inclusive
 +   * 
 +   * @param startRow
 +   *          set this to null when negative infinity is needed
 +   * @param endRow
 +   *          set this to null when positive infinity is needed
 +   */
 +  public Range(CharSequence startRow, CharSequence endRow) {
 +    this(startRow, true, endRow, true);
 +  }
 +  
 +  /**
 +   * Creates a range from startRow to endRow
 +   * 
 +   * @param startRow
 +   *          set this to null when negative infinity is needed
 +   * @param startRowInclusive
 +   *          determines if the start row is skipped
 +   * @param endRow
 +   *          set this to null when positive infinity is needed
 +   * @param endRowInclusive
 +   *          determines if the endRow is included
 +   */
 +  
 +  public Range(Text startRow, boolean startRowInclusive, Text endRow, boolean endRowInclusive) {
 +    this((startRow == null ? null : (startRowInclusive ? new Key(startRow) : new Key(startRow).followingKey(PartialKey.ROW))), true, (endRow == null ? null
 +        : (endRowInclusive ? new Key(endRow).followingKey(PartialKey.ROW) : new Key(endRow))), false);
 +  }
 +  
 +  /**
 +   * Creates a range from startRow to endRow
 +   * 
 +   * @param startRow
 +   *          set this to null when negative infinity is needed
 +   * @param startRowInclusive
 +   *          determines if the start row is skipped
 +   * @param endRow
 +   *          set this to null when positive infinity is needed
 +   * @param endRowInclusive
 +   *          determines if the endRow is included
 +   */
 +  
 +  public Range(CharSequence startRow, boolean startRowInclusive, CharSequence endRow, boolean endRowInclusive) {
 +    this(startRow == null ? null : new Text(startRow.toString()), startRowInclusive, endRow == null ? null : new Text(endRow.toString()), endRowInclusive);
 +  }
 +  
 +  /**
 +   * Creates a range from startKey to endKey
 +   * 
 +   * @param startKey
 +   *          set this to null when negative infinity is needed
 +   * @param startKeyInclusive
 +   *          determines if the ranges includes the start key
 +   * @param endKey
 +   *          set this to null when infinity is needed
 +   * @param endKeyInclusive
 +   *          determines if the range includes the end key
 +   */
 +  public Range(Key startKey, boolean startKeyInclusive, Key endKey, boolean endKeyInclusive) {
 +    this.start = startKey;
 +    this.startKeyInclusive = startKeyInclusive;
 +    this.infiniteStartKey = startKey == null;
 +    this.stop = endKey;
 +    this.stopKeyInclusive = endKeyInclusive;
 +    this.infiniteStopKey = stop == null;
 +    
 +    if (!infiniteStartKey && !infiniteStopKey && beforeStartKey(endKey)) {
 +      throw new IllegalArgumentException("Start key must be less than end key in range (" + startKey + ", " + endKey + ")");
 +    }
 +  }
 +  
 +  /**
 +   * Copies a range
 +   */
 +  public Range(Range range) {
-     this(range.start, range.stop, range.startKeyInclusive, range.stopKeyInclusive, range.infiniteStartKey, range.infiniteStopKey);
++    this(range.start, range.startKeyInclusive, range.infiniteStartKey, range.stop, range.stopKeyInclusive, range.infiniteStopKey);
 +  }
 +  
++  /**
++   * Creates a range from start to stop.
++   *
++   * @param start
++   *          set this to null when negative infinity is needed
++   * @param stop
++   *          set this to null when infinity is needed
++   * @param startKeyInclusive
++   *          determines if the ranges includes the start key
++   * @param stopKeyInclusive
++   *          determines if the range includes the end key
++   * @param infiniteStartKey
++   *          true if start key is negative infinity (null)
++   * @param infiniteStopKey
++   *          true if stop key is positive infinity (null)
++   * @throws IllegalArgumentException if stop is before start, or infiniteStartKey is true but start is not null, or infiniteStopKey is true but stop is not
++   *          null
++   */
 +  public Range(Key start, Key stop, boolean startKeyInclusive, boolean stopKeyInclusive, boolean infiniteStartKey, boolean infiniteStopKey) {
++    this(start, startKeyInclusive, infiniteStartKey, stop, stopKeyInclusive, infiniteStopKey);
++    if (!infiniteStartKey && !infiniteStopKey && beforeStartKey(stop)) {
++      throw new IllegalArgumentException("Start key must be less than end key in range (" + start + ", " + stop + ")");
++    }
++  }
++
++  /**
++   * Creates a range from start to stop. Unlike the public six-argument method,
++   * this one does not assure that stop is after start, which helps performance
++   * in cases where that assurance is already in place.
++   *
++   * @param start
++   *          set this to null when negative infinity is needed
++   * @param startKeyInclusive
++   *          determines if the ranges includes the start key
++   * @param infiniteStartKey
++   *          true if start key is negative infinity (null)
++   * @param stop
++   *          set this to null when infinity is needed
++   * @param stopKeyInclusive
++   *          determines if the range includes the end key
++   * @param infiniteStopKey
++   *          true if stop key is positive infinity (null)
++   * @throws IllegalArgumentException if infiniteStartKey is true but start is not null, or infiniteStopKey is true but stop is not null
++   */
++  protected Range(Key start, boolean startKeyInclusive, boolean infiniteStartKey, Key stop, boolean stopKeyInclusive, boolean infiniteStopKey) {
 +    if (infiniteStartKey && start != null)
 +      throw new IllegalArgumentException();
 +    
 +    if (infiniteStopKey && stop != null)
 +      throw new IllegalArgumentException();
 +    
 +    this.start = start;
 +    this.stop = stop;
 +    this.startKeyInclusive = startKeyInclusive;
 +    this.stopKeyInclusive = stopKeyInclusive;
 +    this.infiniteStartKey = infiniteStartKey;
 +    this.infiniteStopKey = infiniteStopKey;
 +  }
 +  
 +  public Range(TRange trange) {
-     this(trange.start == null ? null : new Key(trange.start), trange.stop == null ? null : new Key(trange.stop), trange.startKeyInclusive,
-         trange.stopKeyInclusive, trange.infiniteStartKey, trange.infiniteStopKey);
++    this(trange.start == null ? null : new Key(trange.start), trange.startKeyInclusive, trange.infiniteStartKey,
++        trange.stop == null ? null : new Key(trange.stop), trange.stopKeyInclusive, trange.infiniteStopKey);
++    if (!infiniteStartKey && !infiniteStopKey && beforeStartKey(stop)) {
++      throw new IllegalArgumentException("Start key must be less than end key in range (" + start + ", " + stop + ")");
++    }
 +  }
 +  
 +  /**
 +   * @return the first key in the range, null if the key is infinite
 +   */
 +  public Key getStartKey() {
 +    if (infiniteStartKey) {
 +      return null;
 +    }
 +    return start;
 +  }
 +  
 +  /**
 +   * 
 +   * @param key
 +   * @return true if the given key is before the range, otherwise false
 +   */
 +  public boolean beforeStartKey(Key key) {
 +    if (infiniteStartKey) {
 +      return false;
 +    }
 +    
 +    if (startKeyInclusive)
 +      return key.compareTo(start) < 0;
 +    return key.compareTo(start) <= 0;
 +  }
 +  
 +  /**
 +   * @return the last key in the range, null if the end key is infinite
 +   */
 +  
 +  public Key getEndKey() {
 +    if (infiniteStopKey) {
 +      return null;
 +    }
 +    return stop;
 +  }
 +  
 +  /**
 +   * @param key
 +   * @return true if the given key is after the range, otherwise false
 +   */
 +  
 +  public boolean afterEndKey(Key key) {
 +    if (infiniteStopKey)
 +      return false;
 +    
 +    if (stopKeyInclusive)
 +      return stop.compareTo(key) < 0;
 +    return stop.compareTo(key) <= 0;
 +  }
 +  
 +  @Override
 +  public int hashCode() {
 +    int startHash = infiniteStartKey ? 0 : start.hashCode() + (startKeyInclusive ? 1 : 0);
 +    int stopHash = infiniteStopKey ? 0 : stop.hashCode() + (stopKeyInclusive ? 1 : 0);
 +    
 +    return startHash + stopHash;
 +  }
 +  
 +  @Override
 +  public boolean equals(Object o) {
 +    if (o instanceof Range)
 +      return equals((Range) o);
 +    return false;
 +  }
 +  
 +  public boolean equals(Range otherRange) {
 +    
 +    return compareTo(otherRange) == 0;
 +  }
 +  
 +  /**
 +   * Compares this range to another range. Compares in the order start key, inclusiveness of start key, end key, inclusiveness of end key. Infinite keys sort
 +   * first, and non-infinite keys are compared with {@link Key#compareTo(Key)}. Inclusive sorts before non-inclusive.
 +   */
 +  public int compareTo(Range o) {
 +    int comp;
 +    
 +    if (infiniteStartKey)
 +      if (o.infiniteStartKey)
 +        comp = 0;
 +      else
 +        comp = -1;
 +    else if (o.infiniteStartKey)
 +      comp = 1;
 +    else {
 +      comp = start.compareTo(o.start);
 +      if (comp == 0)
 +        if (startKeyInclusive && !o.startKeyInclusive)
 +          comp = -1;
 +        else if (!startKeyInclusive && o.startKeyInclusive)
 +          comp = 1;
 +      
 +    }
 +    
 +    if (comp == 0)
 +      if (infiniteStopKey)
 +        if (o.infiniteStopKey)
 +          comp = 0;
 +        else
 +          comp = 1;
 +      else if (o.infiniteStopKey)
 +        comp = -1;
 +      else {
 +        comp = stop.compareTo(o.stop);
 +        if (comp == 0)
 +          if (stopKeyInclusive && !o.stopKeyInclusive)
 +            comp = 1;
 +          else if (!stopKeyInclusive && o.stopKeyInclusive)
 +            comp = -1;
 +      }
 +    
 +    return comp;
 +  }
 +  
 +  /**
 +   * 
 +   * @param key
 +   * @return true if the given key falls within the range
 +   */
 +  public boolean contains(Key key) {
 +    return !beforeStartKey(key) && !afterEndKey(key);
 +  }
 +  
 +  /**
 +   * Takes a collection on range and merges overlapping and adjacent ranges. For example given the following input
 +   * 
 +   * <pre>
 +   * [a,c], (c, d], (g,m), (j,t]
 +   * </pre>
 +   * 
 +   * the following ranges would be returned
 +   * 
 +   * <pre>
 +   * [a,d], (g,t]
 +   * </pre>
 +   * 
 +   * @param ranges
 +   * @return list of merged ranges
 +   */
 +  
 +  public static List<Range> mergeOverlapping(Collection<Range> ranges) {
 +    if (ranges.size() == 0)
 +      return Collections.emptyList();
 +    
 +    List<Range> ral = new ArrayList<Range>(ranges);
 +    Collections.sort(ral);
 +    
 +    ArrayList<Range> ret = new ArrayList<Range>(ranges.size());
 +    
 +    Range currentRange = ral.get(0);
 +    boolean currentStartKeyInclusive = ral.get(0).startKeyInclusive;
 +    
 +    for (int i = 1; i < ral.size(); i++) {
 +      // because of inclusive switch, equal keys may not be seen
 +      
 +      if (currentRange.infiniteStopKey) {
 +        // this range has the minimal start key and
 +        // an infinite end key so it will contain all
 +        // other ranges
 +        break;
 +      }
 +      
 +      Range range = ral.get(i);
 +      
 +      boolean startKeysEqual;
 +      if (range.infiniteStartKey) {
 +        // previous start key must be infinite because it is sorted
 +        assert (currentRange.infiniteStartKey);
 +        startKeysEqual = true;
 +      } else if (currentRange.infiniteStartKey) {
 +        startKeysEqual = false;
 +      } else if (currentRange.start.equals(range.start)) {
 +        startKeysEqual = true;
 +      } else {
 +        startKeysEqual = false;
 +      }
 +      
 +      if (startKeysEqual || currentRange.contains(range.start)
 +          || (!currentRange.stopKeyInclusive && range.startKeyInclusive && range.start.equals(currentRange.stop))) {
 +        int cmp;
 +        
 +        if (range.infiniteStopKey || (cmp = range.stop.compareTo(currentRange.stop)) > 0 || (cmp == 0 && range.stopKeyInclusive)) {
 +          currentRange = new Range(currentRange.getStartKey(), currentStartKeyInclusive, range.getEndKey(), range.stopKeyInclusive);
 +        }/* else currentRange contains ral.get(i) */
 +      } else {
 +        ret.add(currentRange);
 +        currentRange = range;
 +        currentStartKeyInclusive = range.startKeyInclusive;
 +      }
 +    }
 +    
 +    ret.add(currentRange);
 +    
 +    return ret;
 +  }
 +  
 +  /**
 +   * Creates a range which represents the intersection of this range and the passed in range. The following example will print true.
 +   * 
 +   * <pre>
 +   * Range range1 = new Range(&quot;a&quot;, &quot;f&quot;);
 +   * Range range2 = new Range(&quot;c&quot;, &quot;n&quot;);
 +   * Range range3 = range1.clip(range2);
 +   * System.out.println(range3.equals(new Range(&quot;c&quot;, &quot;f&quot;)));
 +   * </pre>
 +   * 
 +   * @param range
 +   * @return the intersection
 +   * @throws IllegalArgumentException
 +   *           if ranges does not overlap
 +   */
 +  
 +  public Range clip(Range range) {
 +    return clip(range, false);
 +  }
 +  
 +  /**
 +   * Same as other clip function except if gives the option to return null of the ranges do not overlap instead of throwing an exception.
 +   * 
 +   * @see Range#clip(Range)
 +   * @param range
 +   * @param returnNullIfDisjoint
 +   *          If the ranges do not overlap and true is passed, then null is returned otherwise an exception is thrown.
 +   * @return the intersection
 +   */
 +  
 +  public Range clip(Range range, boolean returnNullIfDisjoint) {
 +    
 +    Key sk = range.getStartKey();
 +    boolean ski = range.isStartKeyInclusive();
 +    
 +    Key ek = range.getEndKey();
 +    boolean eki = range.isEndKeyInclusive();
 +    
 +    if (range.getStartKey() == null) {
 +      if (getStartKey() != null) {
 +        sk = getStartKey();
 +        ski = isStartKeyInclusive();
 +      }
 +    } else if (afterEndKey(range.getStartKey())
 +        || (getEndKey() != null && range.getStartKey().equals(getEndKey()) && !(range.isStartKeyInclusive() && isEndKeyInclusive()))) {
 +      if (returnNullIfDisjoint)
 +        return null;
 +      throw new IllegalArgumentException("Range " + range + " does not overlap " + this);
 +    } else if (beforeStartKey(range.getStartKey())) {
 +      sk = getStartKey();
 +      ski = isStartKeyInclusive();
 +    }
 +    
 +    if (range.getEndKey() == null) {
 +      if (getEndKey() != null) {
 +        ek = getEndKey();
 +        eki = isEndKeyInclusive();
 +      }
 +    } else if (beforeStartKey(range.getEndKey())
 +        || (getStartKey() != null && range.getEndKey().equals(getStartKey()) && !(range.isEndKeyInclusive() && isStartKeyInclusive()))) {
 +      if (returnNullIfDisjoint)
 +        return null;
 +      throw new IllegalArgumentException("Range " + range + " does not overlap " + this);
 +    } else if (afterEndKey(range.getEndKey())) {
 +      ek = getEndKey();
 +      eki = isEndKeyInclusive();
 +    }
 +    
 +    return new Range(sk, ski, ek, eki);
 +  }
 +  
 +  /**
 +   * Creates a new range that is bounded by the columns passed in. The stary key in the returned range will have a column >= to the minimum column. The end key
 +   * in the returned range will have a column <= the max column.
 +   * 
 +   * 
 +   * @param min
 +   * @param max
 +   * @return a column bounded range
 +   * @throws IllegalArgumentException
 +   *           if min > max
 +   */
 +  
 +  public Range bound(Column min, Column max) {
 +    
 +    if (min.compareTo(max) > 0) {
 +      throw new IllegalArgumentException("min column > max column " + min + " " + max);
 +    }
 +    
 +    Key sk = getStartKey();
 +    boolean ski = isStartKeyInclusive();
 +    
 +    if (sk != null) {
 +      
 +      ByteSequence cf = sk.getColumnFamilyData();
 +      ByteSequence cq = sk.getColumnQualifierData();
 +      
 +      ByteSequence mincf = new ArrayByteSequence(min.columnFamily);
 +      ByteSequence mincq;
 +      
 +      if (min.columnQualifier != null)
 +        mincq = new ArrayByteSequence(min.columnQualifier);
 +      else
 +        mincq = new ArrayByteSequence(new byte[0]);
 +      
 +      int cmp = cf.compareTo(mincf);
 +      
 +      if (cmp < 0 || (cmp == 0 && cq.compareTo(mincq) < 0)) {
 +        ski = true;
 +        sk = new Key(sk.getRowData().toArray(), mincf.toArray(), mincq.toArray(), new byte[0], Long.MAX_VALUE, true);
 +      }
 +    }
 +    
 +    Key ek = getEndKey();
 +    boolean eki = isEndKeyInclusive();
 +    
 +    if (ek != null) {
 +      ByteSequence row = ek.getRowData();
 +      ByteSequence cf = ek.getColumnFamilyData();
 +      ByteSequence cq = ek.getColumnQualifierData();
 +      ByteSequence cv = ek.getColumnVisibilityData();
 +      
 +      ByteSequence maxcf = new ArrayByteSequence(max.columnFamily);
 +      ByteSequence maxcq = null;
 +      if (max.columnQualifier != null)
 +        maxcq = new ArrayByteSequence(max.columnQualifier);
 +      
 +      boolean set = false;
 +      
 +      int comp = cf.compareTo(maxcf);
 +      
 +      if (comp > 0) {
 +        set = true;
 +      } else if (comp == 0 && maxcq != null && cq.compareTo(maxcq) > 0) {
 +        set = true;
 +      } else if (!eki && row.length() > 0 && row.byteAt(row.length() - 1) == 0 && cf.length() == 0 && cq.length() == 0 && cv.length() == 0
 +          && ek.getTimestamp() == Long.MAX_VALUE) {
 +        row = row.subSequence(0, row.length() - 1);
 +        set = true;
 +      }
 +      
 +      if (set) {
 +        eki = false;
 +        if (maxcq == null)
 +          ek = new Key(row.toArray(), maxcf.toArray(), new byte[0], new byte[0], 0, false).followingKey(PartialKey.ROW_COLFAM);
 +        else
 +          ek = new Key(row.toArray(), maxcf.toArray(), maxcq.toArray(), new byte[0], 0, false).followingKey(PartialKey.ROW_COLFAM_COLQUAL);
 +      }
 +    }
 +    
 +    return new Range(sk, ski, ek, eki);
 +  }
 +  
 +  public String toString() {
 +    return ((startKeyInclusive && start != null) ? "[" : "(") + (start == null ? "-inf" : start) + "," + (stop == null ? "+inf" : stop)
 +        + ((stopKeyInclusive && stop != null) ? "]" : ")");
 +  }
 +  
 +  public void readFields(DataInput in) throws IOException {
 +    infiniteStartKey = in.readBoolean();
 +    infiniteStopKey = in.readBoolean();
 +    if (!infiniteStartKey) {
 +      start = new Key();
 +      start.readFields(in);
 +    } else {
 +      start = null;
 +    }
 +    
 +    if (!infiniteStopKey) {
 +      stop = new Key();
 +      stop.readFields(in);
 +    } else {
 +      stop = null;
 +    }
 +    
 +    startKeyInclusive = in.readBoolean();
 +    stopKeyInclusive = in.readBoolean();
++
++    if (!infiniteStartKey && !infiniteStopKey && beforeStartKey(stop)) {
++      throw new InvalidObjectException("Start key must be less than end key in range (" + start + ", " + stop + ")");
++    }
 +  }
 +  
 +  public void write(DataOutput out) throws IOException {
 +    out.writeBoolean(infiniteStartKey);
 +    out.writeBoolean(infiniteStopKey);
 +    if (!infiniteStartKey)
 +      start.write(out);
 +    if (!infiniteStopKey)
 +      stop.write(out);
 +    out.writeBoolean(startKeyInclusive);
 +    out.writeBoolean(stopKeyInclusive);
 +  }
 +  
 +  public boolean isStartKeyInclusive() {
 +    return startKeyInclusive;
 +  }
 +  
 +  public boolean isEndKeyInclusive() {
 +    return stopKeyInclusive;
 +  }
 +  
 +  public TRange toThrift() {
 +    return new TRange(start == null ? null : start.toThrift(), stop == null ? null : stop.toThrift(), startKeyInclusive, stopKeyInclusive, infiniteStartKey,
 +        infiniteStopKey);
 +  }
 +  
 +  public boolean isInfiniteStartKey() {
 +    return infiniteStartKey;
 +  }
 +  
 +  public boolean isInfiniteStopKey() {
 +    return infiniteStopKey;
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row Returns the same Range as new Range(row)
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   */
 +  public static Range exact(Text row) {
 +    return new Range(row);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row and column family
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cf
 +   *          all keys in the range will have this column family
 +   */
 +  public static Range exact(Text row, Text cf) {
 +    Key startKey = new Key(row, cf);
 +    return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM), false);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row, column family, and column qualifier
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cf
 +   *          all keys in the range will have this column family
 +   * 
 +   * @param cq
 +   *          all keys in the range will have this column qualifier
 +   */
 +  public static Range exact(Text row, Text cf, Text cq) {
 +    Key startKey = new Key(row, cf, cq);
 +    return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL), false);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row, column family, column qualifier, and visibility
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cf
 +   *          all keys in the range will have this column family
 +   * 
 +   * @param cq
 +   *          all keys in the range will have this column qualifier
 +   * 
 +   * @param cv
 +   *          all keys in the range will have this column visibility
 +   */
 +  public static Range exact(Text row, Text cf, Text cq, Text cv) {
 +    Key startKey = new Key(row, cf, cq, cv);
 +    return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS), false);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row, column family, column qualifier, visibility, and timestamp
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cf
 +   *          all keys in the range will have this column family
 +   * 
 +   * @param cq
 +   *          all keys in the range will have this column qualifier
 +   * 
 +   * @param cv
 +   *          all keys in the range will have this column visibility
 +   * 
 +   * @param ts
 +   *          all keys in the range will have this timestamp
 +   */
 +  public static Range exact(Text row, Text cf, Text cq, Text cv, long ts) {
 +    Key startKey = new Key(row, cf, cq, cv, ts);
 +    return new Range(startKey, true, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), false);
 +  }
 +  
 +  /**
 +   * Returns a Text that sorts just after all Texts beginning with a prefix
 +   * 
 +   * @param prefix
 +   */
 +  public static Text followingPrefix(Text prefix) {
 +    byte[] prefixBytes = prefix.getBytes();
 +    
 +    // find the last byte in the array that is not 0xff
 +    int changeIndex = prefix.getLength() - 1;
 +    while (changeIndex >= 0 && prefixBytes[changeIndex] == (byte) 0xff)
 +      changeIndex--;
 +    if (changeIndex < 0)
 +      return null;
 +    
 +    // copy prefix bytes into new array
 +    byte[] newBytes = new byte[changeIndex + 1];
 +    System.arraycopy(prefixBytes, 0, newBytes, 0, changeIndex + 1);
 +    
 +    // increment the selected byte
 +    newBytes[changeIndex]++;
 +    return new Text(newBytes);
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all rows beginning with a prefix
 +   * 
 +   * @param rowPrefix
 +   *          all keys in the range will have rows that begin with this prefix
 +   */
 +  public static Range prefix(Text rowPrefix) {
 +    Text fp = followingPrefix(rowPrefix);
 +    return new Range(new Key(rowPrefix), true, fp == null ? null : new Key(fp), false);
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all column families beginning with a prefix within a given row
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cfPrefix
 +   *          all keys in the range will have column families that begin with this prefix
 +   */
 +  public static Range prefix(Text row, Text cfPrefix) {
 +    Text fp = followingPrefix(cfPrefix);
 +    return new Range(new Key(row, cfPrefix), true, fp == null ? new Key(row).followingKey(PartialKey.ROW) : new Key(row, fp), false);
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all column qualifiers beginning with a prefix within a given row and column family
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cf
 +   *          all keys in the range will have this column family
 +   * 
 +   * @param cqPrefix
 +   *          all keys in the range will have column qualifiers that begin with this prefix
 +   */
 +  public static Range prefix(Text row, Text cf, Text cqPrefix) {
 +    Text fp = followingPrefix(cqPrefix);
 +    return new Range(new Key(row, cf, cqPrefix), true, fp == null ? new Key(row, cf).followingKey(PartialKey.ROW_COLFAM) : new Key(row, cf, fp), false);
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all column visibilities beginning with a prefix within a given row, column family, and column qualifier
 +   * 
 +   * @param row
 +   *          all keys in the range will have this row
 +   * 
 +   * @param cf
 +   *          all keys in the range will have this column family
 +   * 
 +   * @param cq
 +   *          all keys in the range will have this column qualifier
 +   * 
 +   * @param cvPrefix
 +   *          all keys in the range will have column visibilities that begin with this prefix
 +   */
 +  public static Range prefix(Text row, Text cf, Text cq, Text cvPrefix) {
 +    Text fp = followingPrefix(cvPrefix);
 +    return new Range(new Key(row, cf, cq, cvPrefix), true, fp == null ? new Key(row, cf, cq).followingKey(PartialKey.ROW_COLFAM_COLQUAL) : new Key(row, cf, cq,
 +        fp), false);
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row
 +   * 
 +   * @see Range#exact(Text)
 +   */
 +  public static Range exact(CharSequence row) {
 +    return Range.exact(new Text(row.toString()));
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row and column family
 +   * 
 +   * @see Range#exact(Text, Text)
 +   */
 +  public static Range exact(CharSequence row, CharSequence cf) {
 +    return Range.exact(new Text(row.toString()), new Text(cf.toString()));
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row, column family, and column qualifier
 +   * 
 +   * @see Range#exact(Text, Text, Text)
 +   */
 +  public static Range exact(CharSequence row, CharSequence cf, CharSequence cq) {
 +    return Range.exact(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()));
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row, column family, column qualifier, and visibility
 +   * 
 +   * @see Range#exact(Text, Text, Text, Text)
 +   */
 +  public static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv) {
 +    return Range.exact(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), new Text(cv.toString()));
 +  }
 +  
 +  /**
 +   * Creates a range that covers an exact row, column family, column qualifier, visibility, and timestamp
 +   * 
 +   * @see Range#exact(Text, Text, Text, Text, long)
 +   */
 +  public static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv, long ts) {
 +    return Range.exact(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), new Text(cv.toString()), ts);
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all rows beginning with a prefix
 +   * 
 +   * @see Range#prefix(Text)
 +   */
 +  public static Range prefix(CharSequence rowPrefix) {
 +    return Range.prefix(new Text(rowPrefix.toString()));
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all column families beginning with a prefix within a given row
 +   * 
 +   * @see Range#prefix(Text, Text)
 +   */
 +  public static Range prefix(CharSequence row, CharSequence cfPrefix) {
 +    return Range.prefix(new Text(row.toString()), new Text(cfPrefix.toString()));
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all column qualifiers beginning with a prefix within a given row and column family
 +   * 
 +   * @see Range#prefix(Text, Text, Text)
 +   */
 +  public static Range prefix(CharSequence row, CharSequence cf, CharSequence cqPrefix) {
 +    return Range.prefix(new Text(row.toString()), new Text(cf.toString()), new Text(cqPrefix.toString()));
 +  }
 +  
 +  /**
 +   * Returns a Range that covers all column visibilities beginning with a prefix within a given row, column family, and column qualifier
 +   * 
 +   * @see Range#prefix(Text, Text, Text, Text)
 +   */
 +  public static Range prefix(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cvPrefix) {
 +    return Range.prefix(new Text(row.toString()), new Text(cf.toString()), new Text(cq.toString()), new Text(cvPrefix.toString()));
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/994e43c1/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java
----------------------------------------------------------------------
diff --cc core/src/test/java/org/apache/accumulo/core/data/RangeTest.java
index a8d91b0,0000000..68d9731
mode 100644,000000..100644
--- a/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/data/RangeTest.java
@@@ -1,764 -1,0 +1,822 @@@
 +/*
 + * 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.data;
 +
++import java.io.ByteArrayInputStream;
++import java.io.ByteArrayOutputStream;
++import java.io.DataInputStream;
++import java.io.DataOutputStream;
++import java.io.InvalidObjectException;
 +import java.util.Arrays;
 +import java.util.HashSet;
 +import java.util.List;
 +
 +import junit.framework.TestCase;
 +
++import org.apache.accumulo.core.data.thrift.TRange;
 +import org.apache.hadoop.io.Text;
 +
 +public class RangeTest extends TestCase {
 +  private Range nr(String k1, String k2) {
 +    Key ik1 = null;
 +    if (k1 != null)
 +      ik1 = new Key(new Text(k1), 0l);
 +    
 +    Key ik2 = null;
 +    if (k2 != null)
 +      ik2 = new Key(new Text(k2), 0l);
 +    
 +    return new Range(ik1, ik2);
 +  }
 +  
 +  private List<Range> nrl(Range... ranges) {
 +    return Arrays.asList(ranges);
 +  }
 +  
 +  private void check(List<Range> rl, List<Range> expected) {
 +    HashSet<Range> s1 = new HashSet<Range>(rl);
 +    HashSet<Range> s2 = new HashSet<Range>(expected);
 +    
 +    assertTrue("got : " + rl + " expected : " + expected, s1.equals(s2));
 +  }
 +  
 +  public void testMergeOverlapping1() {
 +    List<Range> rl = nrl(nr("a", "c"), nr("a", "b"));
 +    List<Range> expected = nrl(nr("a", "c"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping2() {
 +    List<Range> rl = nrl(nr("a", "c"), nr("d", "f"));
 +    List<Range> expected = nrl(nr("a", "c"), nr("d", "f"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping3() {
 +    List<Range> rl = nrl(nr("a", "e"), nr("b", "f"), nr("c", "r"), nr("g", "j"), nr("t", "x"));
 +    List<Range> expected = nrl(nr("a", "r"), nr("t", "x"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping4() {
 +    List<Range> rl = nrl(nr("a", "e"), nr("b", "f"), nr("c", "r"), nr("g", "j"));
 +    List<Range> expected = nrl(nr("a", "r"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping5() {
 +    List<Range> rl = nrl(nr("a", "e"));
 +    List<Range> expected = nrl(nr("a", "e"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping6() {
 +    List<Range> rl = nrl();
 +    List<Range> expected = nrl();
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping7() {
 +    List<Range> rl = nrl(nr("a", "e"), nr("g", "q"), nr("r", "z"));
 +    List<Range> expected = nrl(nr("a", "e"), nr("g", "q"), nr("r", "z"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping8() {
 +    List<Range> rl = nrl(nr("a", "c"), nr("a", "c"));
 +    List<Range> expected = nrl(nr("a", "c"));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping9() {
 +    List<Range> rl = nrl(nr(null, null));
 +    List<Range> expected = nrl(nr(null, null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping10() {
 +    List<Range> rl = nrl(nr(null, null), nr("a", "c"));
 +    List<Range> expected = nrl(nr(null, null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping11() {
 +    List<Range> rl = nrl(nr("a", "c"), nr(null, null));
 +    List<Range> expected = nrl(nr(null, null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping12() {
 +    List<Range> rl = nrl(nr("b", "d"), nr("c", null));
 +    List<Range> expected = nrl(nr("b", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping13() {
 +    List<Range> rl = nrl(nr("b", "d"), nr("a", null));
 +    List<Range> expected = nrl(nr("a", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping14() {
 +    List<Range> rl = nrl(nr("b", "d"), nr("e", null));
 +    List<Range> expected = nrl(nr("b", "d"), nr("e", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping15() {
 +    List<Range> rl = nrl(nr("b", "d"), nr("e", null), nr("c", "f"));
 +    List<Range> expected = nrl(nr("b", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping16() {
 +    List<Range> rl = nrl(nr("b", "d"), nr("f", null), nr("c", "e"));
 +    List<Range> expected = nrl(nr("b", "e"), nr("f", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping17() {
 +    List<Range> rl = nrl(nr("b", "d"), nr("r", null), nr("c", "e"), nr("g", "t"));
 +    List<Range> expected = nrl(nr("b", "e"), nr("g", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping18() {
 +    List<Range> rl = nrl(nr(null, "d"), nr("r", null), nr("c", "e"), nr("g", "t"));
 +    List<Range> expected = nrl(nr(null, "e"), nr("g", null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping19() {
 +    List<Range> rl = nrl(nr(null, "d"), nr("r", null), nr("c", "e"), nr("g", "t"), nr("d", "h"));
 +    List<Range> expected = nrl(nr(null, null));
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping20() {
 +    
 +    List<Range> rl = nrl(new Range(new Text("a"), true, new Text("b"), false), new Range(new Text("b"), false, new Text("c"), false));
 +    List<Range> expected = nrl(new Range(new Text("a"), true, new Text("b"), false), new Range(new Text("b"), false, new Text("c"), false));
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(new Range(new Text("a"), true, new Text("b"), false), new Range(new Text("b"), true, new Text("c"), false));
 +    expected = nrl(new Range(new Text("a"), true, new Text("c"), false));
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(new Range(new Text("a"), true, new Text("b"), true), new Range(new Text("b"), false, new Text("c"), false));
 +    expected = nrl(new Range(new Text("a"), true, new Text("c"), false));
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(new Range(new Text("a"), true, new Text("b"), true), new Range(new Text("b"), true, new Text("c"), false));
 +    expected = nrl(new Range(new Text("a"), true, new Text("c"), false));
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +  }
 +  
 +  public void testMergeOverlapping22() {
 +    
 +    Range ke1 = new KeyExtent(new Text("tab1"), new Text("Bank"), null).toMetadataRange();
 +    Range ke2 = new KeyExtent(new Text("tab1"), new Text("Fails"), new Text("Bank")).toMetadataRange();
 +    Range ke3 = new KeyExtent(new Text("tab1"), new Text("Sam"), new Text("Fails")).toMetadataRange();
 +    Range ke4 = new KeyExtent(new Text("tab1"), new Text("bails"), new Text("Sam")).toMetadataRange();
 +    Range ke5 = new KeyExtent(new Text("tab1"), null, new Text("bails")).toMetadataRange();
 +    
 +    List<Range> rl = nrl(ke1, ke2, ke3, ke4, ke5);
 +    List<Range> expected = nrl(new KeyExtent(new Text("tab1"), null, null).toMetadataRange());
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(ke1, ke2, ke4, ke5);
 +    expected = nrl(new KeyExtent(new Text("tab1"), new Text("Fails"), null).toMetadataRange(),
 +        new KeyExtent(new Text("tab1"), null, new Text("Sam")).toMetadataRange());
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(ke2, ke3, ke4, ke5);
 +    expected = nrl(new KeyExtent(new Text("tab1"), null, new Text("Bank")).toMetadataRange());
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(ke1, ke2, ke3, ke4);
 +    expected = nrl(new KeyExtent(new Text("tab1"), new Text("bails"), null).toMetadataRange());
 +    check(Range.mergeOverlapping(rl), expected);
 +    
 +    rl = nrl(ke2, ke3, ke4);
 +    expected = nrl(new KeyExtent(new Text("tab1"), new Text("bails"), new Text("Bank")).toMetadataRange());
 +    check(Range.mergeOverlapping(rl), expected);
 +  }
 +  
 +  public void testMergeOverlapping21() {
 +    for (boolean b1 : new boolean[] {true, false})
 +      for (boolean b2 : new boolean[] {true, false})
 +        for (boolean b3 : new boolean[] {true, false})
 +          for (boolean b4 : new boolean[] {true, false}) {
 +            
 +            // System.out.println("b1:"+b1+" b2:"+b2+" b3:"+b3+" b4:"+b4);
 +            
 +            List<Range> rl = nrl(new Range(new Key(new Text("a")), b1, new Key(new Text("m")), b2), new Range(new Key(new Text("b")), b3,
 +                new Key(new Text("n")), b4));
 +            List<Range> expected = nrl(new Range(new Key(new Text("a")), b1, new Key(new Text("n")), b4));
 +            check(Range.mergeOverlapping(rl), expected);
 +            
 +            rl = nrl(new Range(new Key(new Text("a")), b1, new Key(new Text("m")), b2), new Range(new Key(new Text("a")), b3, new Key(new Text("n")), b4));
 +            expected = nrl(new Range(new Key(new Text("a")), b1 || b3, new Key(new Text("n")), b4));
 +            check(Range.mergeOverlapping(rl), expected);
 +            
 +            rl = nrl(new Range(new Key(new Text("a")), b1, new Key(new Text("n")), b2), new Range(new Key(new Text("b")), b3, new Key(new Text("n")), b4));
 +            expected = nrl(new Range(new Key(new Text("a")), b1, new Key(new Text("n")), b2 || b4));
 +            check(Range.mergeOverlapping(rl), expected);
 +            
 +            rl = nrl(new Range(new Key(new Text("a")), b1, new Key(new Text("n")), b2), new Range(new Key(new Text("a")), b3, new Key(new Text("n")), b4));
 +            expected = nrl(new Range(new Key(new Text("a")), b1 || b3, new Key(new Text("n")), b2 || b4));
 +            check(Range.mergeOverlapping(rl), expected);
 +          }
 +    
 +  }
 +  
 +  public void testEqualsNull() {
 +    
 +    assertTrue(nr(null, "d").equals(nr(null, "d")));
 +    
 +    assertTrue(nr(null, null).equals(nr(null, null)));
 +    
 +    assertTrue(nr("a", null).equals(nr("a", null)));
 +    
 +    assertFalse(nr(null, "d").equals(nr("a", "d")));
 +    assertFalse(nr("a", "d").equals(nr(null, "d")));
 +    
 +    assertFalse(nr(null, null).equals(nr("a", "d")));
 +    assertFalse(nr("a", "d").equals(nr(null, null)));
 +    
 +    assertFalse(nr("a", null).equals(nr("a", "d")));
 +    assertFalse(nr("a", "d").equals(nr("a", null)));
 +  }
 +  
 +  public void testEquals() {
 +    assertFalse(nr("b", "d").equals(nr("a", "d")));
 +    assertFalse(nr("a", "d").equals(nr("b", "d")));
 +    
 +    assertFalse(nr("x", "y").equals(nr("a", "d")));
 +    assertFalse(nr("a", "d").equals(nr("x", "y")));
 +    
 +    assertFalse(nr("a", "z").equals(nr("a", "d")));
 +    assertFalse(nr("a", "d").equals(nr("a", "z")));
 +    
 +    assertTrue(nr("a", "z").equals(nr("a", "z")));
 +  }
 +  
 +  public void testRow1() {
 +    Range rowRange = new Range(new Text("r1"));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertFalse(rowRange.contains(new Key(new Text("r11"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r0"))));
 +  }
 +  
 +  public void testRow2() {
 +    Range rowRange = new Range(new Text("r1"), new Text("r2"));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r2"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r0"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  public void testRow3() {
 +    Range rowRange = new Range(new Text("r1"), false, new Text("r2"), false);
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r1"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r2"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r0"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  public void testRow4() {
 +    Range rowRange = new Range(new Text("r1"), true, new Text("r2"), false);
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r2"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r0"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  public void testRow5() {
 +    Range rowRange = new Range(new Text("r1"), false, new Text("r2"), true);
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r1"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r2"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r0"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  public void testRow6() {
 +    Range rowRange = new Range(new Text("r1"), true, null, true);
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r2"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertFalse(rowRange.contains(new Key(new Text("r0"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  public void testRow7() {
 +    Range rowRange = new Range(null, true, new Text("r2"), true);
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r2"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r0"))));
 +    assertFalse(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  public void testRow8() {
 +    Range rowRange = new Range((Text) null);
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r1")).followingKey(PartialKey.ROW)));
 +    assertTrue(rowRange.contains(new Key(new Text("r11"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r2"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"))));
 +    
 +    assertTrue(rowRange.contains(new Key(new Text("r0"))));
 +    assertTrue(rowRange.contains(new Key(new Text("r2")).followingKey(PartialKey.ROW)));
 +  }
 +  
 +  private static Range nr(String r1, boolean r1i, String r2, boolean r2i) {
 +    Text tr1 = null;
 +    Text tr2 = null;
 +    
 +    if (r1 != null)
 +      tr1 = new Text(r1);
 +    
 +    if (r2 != null)
 +      tr2 = new Text(r2);
 +    
 +    return new Range(tr1, r1i, tr2, r2i);
 +    
 +  }
 +  
 +  private static Key nk(String r) {
 +    return new Key(new Text(r));
 +  }
 +  
 +  public void testClip1() {
 +    Range fence = nr("a", false, "c", false);
 +    
 +    runClipTest(fence, nr("a", false, "c", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", false, "c", true), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", true), nr("a", false, "c", false));
 +    
 +    fence = nr("a", true, "c", false);
 +    
 +    runClipTest(fence, nr("a", false, "c", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", false), nr("a", true, "c", false));
 +    runClipTest(fence, nr("a", false, "c", true), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", true), nr("a", true, "c", false));
 +    
 +    fence = nr("a", false, "c", true);
 +    
 +    runClipTest(fence, nr("a", false, "c", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", false, "c", true), nr("a", false, "c", true));
 +    runClipTest(fence, nr("a", true, "c", true), nr("a", false, "c", true));
 +    
 +    fence = nr("a", true, "c", true);
 +    
 +    runClipTest(fence, nr("a", false, "c", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", false), nr("a", true, "c", false));
 +    runClipTest(fence, nr("a", false, "c", true), nr("a", false, "c", true));
 +    runClipTest(fence, nr("a", true, "c", true), nr("a", true, "c", true));
 +  }
 +  
 +  public void testClip2() {
 +    Range fence = nr("a", false, "c", false);
 +    
 +    runClipTest(fence, nr(null, true, null, true), nr("a", false, "c", false));
 +    runClipTest(fence, nr(null, true, "c", true), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, null, true), nr("a", false, "c", false));
 +    runClipTest(fence, nr("a", true, "c", true), nr("a", false, "c", false));
 +  }
 +  
 +  public void testClip3() {
 +    Range fence = nr("a", false, "c", false);
 +    
 +    runClipTest(fence, nr("0", false, "z", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("0", true, "z", false), nr("a", false, "c", false));
 +    runClipTest(fence, nr("0", false, "z", true), nr("a", false, "c", false));
 +    runClipTest(fence, nr("0", true, "z", true), nr("a", false, "c", false));
 +    
 +    runClipTest(fence, nr("0", false, "b", false), nr("a", false, "b", false));
 +    runClipTest(fence, nr("0", true, "b", false), nr("a", false, "b", false));
 +    runClipTest(fence, nr("0", false, "b", true), nr("a", false, "b", true));
 +    runClipTest(fence, nr("0", true, "b", true), nr("a", false, "b", true));
 +    
 +    runClipTest(fence, nr("a1", false, "z", false), nr("a1", false, "c", false));
 +    runClipTest(fence, nr("a1", true, "z", false), nr("a1", true, "c", false));
 +    runClipTest(fence, nr("a1", false, "z", true), nr("a1", false, "c", false));
 +    runClipTest(fence, nr("a1", true, "z", true), nr("a1", true, "c", false));
 +    
 +    runClipTest(fence, nr("a1", false, "b", false), nr("a1", false, "b", false));
 +    runClipTest(fence, nr("a1", true, "b", false), nr("a1", true, "b", false));
 +    runClipTest(fence, nr("a1", false, "b", true), nr("a1", false, "b", true));
 +    runClipTest(fence, nr("a1", true, "b", true), nr("a1", true, "b", true));
 +  }
 +  
 +  public void testClip4() {
 +    Range fence = new Range(nk("c"), false, nk("n"), false);
 +    
 +    runClipTest(fence, new Range(nk("a"), false, nk("c"), false));
 +    runClipTest(fence, new Range(nk("a"), false, nk("c"), true));
 +    runClipTest(fence, new Range(nk("n"), false, nk("r"), false));
 +    runClipTest(fence, new Range(nk("n"), true, nk("r"), false));
 +    runClipTest(fence, new Range(nk("a"), true, nk("b"), false));
 +    runClipTest(fence, new Range(nk("a"), true, nk("b"), true));
 +    
 +    fence = new Range(nk("c"), true, nk("n"), true);
 +    
 +    runClipTest(fence, new Range(nk("a"), false, nk("c"), false));
 +    runClipTest(fence, new Range(nk("a"), false, nk("c"), true), new Range(nk("c"), true, nk("c"), true));
 +    runClipTest(fence, new Range(nk("n"), false, nk("r"), false));
 +    runClipTest(fence, new Range(nk("n"), true, nk("r"), false), new Range(nk("n"), true, nk("n"), true));
 +    runClipTest(fence, new Range(nk("q"), false, nk("r"), false));
 +    runClipTest(fence, new Range(nk("q"), true, nk("r"), false));
 +    
 +    fence = nr("b", true, "b", true);
 +    
 +    runClipTest(fence, nr("b", false, "c", false));
 +    runClipTest(fence, nr("b", true, "c", false), nr("b", true, "b", true));
 +    runClipTest(fence, nr("a", false, "b", false));
 +    runClipTest(fence, nr("a", false, "b", true), nr("b", true, "b", true));
 +    
 +  }
 +  
 +  public void testBug1() {
 +    
 +    // unit test related to a bug that was observed (bug was not in range, but want to ensure the following works)
 +    
 +    // clip caught the scanner going to a tablet passed the end of the scan range
 +    Range fence = new Range(new Text("10<"), false, new Text("~"), true);
 +    
 +    Key k1 = new Key(new Text("10<"), new Text("~tab"), new Text("~pr"));
 +    Range range = new Range(k1, true, k1.followingKey(PartialKey.ROW), false);
 +    
 +    runClipTest(fence, range);
 +    
 +    // scanner was not handling edge case properly...
 +    Range scanRange = new Range(new Key("10;007cdc5b0".getBytes(), "~tab".getBytes(), "~pr".getBytes(), "".getBytes(), 130962, false), false, new Key(new Text(
 +        "10<")).followingKey(PartialKey.ROW), false);
 +    // below is the proper check the scanner now does instead of just comparing the row bytes
 +    scanRange.afterEndKey(new Key(new Text("10<")).followingKey(PartialKey.ROW));
 +  }
 +  
 +  private void runClipTest(Range fence, Range range) {
 +    try {
 +      fence.clip(range);
 +      assertFalse(true);
 +    } catch (IllegalArgumentException e) {
 +      
 +    }
 +    
 +  }
 +  
 +  private void runClipTest(Range fence, Range range, Range expected) {
 +    Range clipped = fence.clip(range);
 +    assertEquals(expected, clipped);
 +  }
 +  
 +  private static Key nk(String r, String cf, String cq) {
 +    return new Key(new Text(r), new Text(cf), new Text(cq));
 +  }
 +  
 +  private static Key nk(String r, String cf, String cq, String cv) {
 +    return new Key(new Text(r), new Text(cf), new Text(cq), new Text(cv));
 +  }
 +  
 +  private static Column nc(String cf, String cq) {
 +    return new Column(cf.getBytes(), cq == null ? null : cq.getBytes(), null);
 +  }
 +  
 +  private static Column nc(String cf) {
 +    return nc(cf, null);
 +  }
 +  
 +  private static Range nr(String row) {
 +    return new Range(new Text(row));
 +  }
 +  
 +  public void testBound1() {
 +    Range range1 = nr("row1");
 +    
 +    Range range2 = range1.bound(nc("b"), nc("e"));
 +    
 +    assertFalse(range2.contains(nk("row1")));
 +    assertFalse(range2.contains(nk("row1", "a", "z")));
 +    assertTrue(range2.contains(nk("row1", "b", "")));
 +    assertTrue(range2.contains(nk("row1", "b", "z")));
 +    assertTrue(range2.contains(nk("row1", "c", "z")));
 +    assertTrue(range2.contains(nk("row1", "e", "")));
 +    assertTrue(range2.contains(nk("row1", "e", "z")));
 +    assertFalse(range2.contains(nk("row1", "e", "").followingKey(PartialKey.ROW_COLFAM)));
 +    assertFalse(range2.contains(nk("row1", "f", "")));
 +    assertFalse(range2.contains(nk("row1", "f", "z")));
 +    
 +  }
 +  
 +  public void testBound2() {
 +    Range range1 = new Range(nk("row1", "b", "x"), true, nk("row1", "f", "x"), true);
 +    
 +    Range range2 = range1.bound(nc("a"), nc("g"));
 +    assertEquals(range1, range2);
 +    assertFalse(range2.contains(nk("row1", "a", "x")));
 +    assertTrue(range2.contains(nk("row1", "b", "x")));
 +    assertTrue(range2.contains(nk("row1", "f", "x")));
 +    assertFalse(range2.contains(nk("row1", "g", "")));
 +    
 +    Range range3 = range1.bound(nc("c"), nc("d"));
 +    assertFalse(range3.contains(nk("row1", "b", "x")));
 +    assertTrue(range3.contains(nk("row1", "c", "")));
 +    assertTrue(range3.contains(nk("row1", "c", "z")));
 +    assertTrue(range3.contains(nk("row1", "d", "")));
 +    assertTrue(range3.contains(nk("row1", "d", "z")));
 +    assertFalse(range3.contains(nk("row1", "e", "")));
 +    assertFalse(range3.contains(nk("row1", "f", "x")));
 +    
 +    Range range4 = range1.bound(nc("c", "w"), nc("d", "z"));
 +    assertFalse(range4.contains(nk("row1", "b", "x")));
 +    assertTrue(range4.contains(nk("row1", "c", "w")));
 +    assertTrue(range4.contains(nk("row1", "c", "w", "")));
 +    assertTrue(range4.contains(nk("row1", "c", "w", "a")));
 +    assertTrue(range4.contains(nk("row1", "d", "z", "")));
 +    assertTrue(range4.contains(nk("row1", "d", "z", "a")));
 +    assertFalse(range4.contains(nk("row1", "d", "{", "")));
 +    assertFalse(range4.contains(nk("row1", "d", "z", "a").followingKey(PartialKey.ROW_COLFAM_COLQUAL)));
 +    assertFalse(range4.contains(nk("row1", "f", "x")));
 +    
 +    Range range5 = range1.bound(nc("b", "w"), nc("f", "z"));
 +    assertEquals(range1, range5);
 +    assertFalse(range5.contains(nk("row1", "b", "w")));
 +    assertTrue(range5.contains(nk("row1", "b", "x")));
 +    assertTrue(range5.contains(nk("row1", "f", "x")));
 +    assertFalse(range5.contains(nk("row1", "f", "z")));
 +    
 +    Range range6 = range1.bound(nc("b", "y"), nc("f", "w"));
 +    assertFalse(range6.contains(nk("row1", "b", "x")));
 +    assertTrue(range6.contains(nk("row1", "b", "y")));
 +    assertTrue(range6.contains(nk("row1", "f", "w")));
 +    assertTrue(range6.contains(nk("row1", "f", "w", "a")));
 +    assertFalse(range6.contains(nk("row1", "f", "w").followingKey(PartialKey.ROW_COLFAM_COLQUAL)));
 +    assertFalse(range6.contains(nk("row1", "f", "x")));
 +    
 +    Range range7 = range1.bound(nc("a", "y"), nc("g", "w"));
 +    assertEquals(range1, range7);
 +    assertFalse(range7.contains(nk("row1", "b", "w")));
 +    assertTrue(range7.contains(nk("row1", "b", "x")));
 +    assertTrue(range7.contains(nk("row1", "f", "x")));
 +    assertFalse(range7.contains(nk("row1", "f", "z")));
 +  }
 +  
 +  public void testString() {
 +    Range r1 = new Range(new Text("r1"));
 +    Range r2 = new Range("r1");
 +    assertEquals(r1, r2);
 +    
 +    r1 = new Range(new Text("r1"), new Text("r2"));
 +    r2 = new Range("r1", "r2");
 +    assertEquals(r1, r2);
 +    
 +    r1 = new Range(new Text("r1"), false, new Text("r2"), true);
 +    r2 = new Range("r1", false, "r2", true);
 +    assertEquals(r1, r2);
 +    
 +    r1 = new Range(new Text("r1"), true, new Text("r2"), false);
 +    r2 = new Range("r1", true, "r2", false);
 +    assertEquals(r1, r2);
 +    
 +  }
 +  
 +  public void testExactRange() {
 +    Range r = Range.exact("abc");
 +    assertTrue(r.contains(new Key("abc")));
 +    assertTrue(r.contains(new Key("abc", "def")));
 +    assertFalse(r.contains(new Key("abcd")));
 +    assertFalse(r.contains(new Key("abb")));
 +    assertFalse(r.contains(new Key("abd")));
 +    
 +    r = Range.exact("abc", "def");
 +    assertTrue(r.contains(new Key("abc", "def", "ghi")));
 +    assertFalse(r.contains(new Key("abc", "defg")));
 +    assertFalse(r.contains(new Key("abc", "dee")));
 +    assertFalse(r.contains(new Key("abc", "deg")));
 +    
 +    r = Range.exact("abc", "def", "ghi");
 +    assertTrue(r.contains(new Key("abc", "def", "ghi", "j&k")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghij")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghh")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghj")));
 +    
 +    r = Range.exact("abc", "def", "ghi", "j&k");
 +    assertTrue(r.contains(new Key("abc", "def", "ghi", "j&k", 7l)));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&kl")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&j")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&l")));
 +    
 +    r = Range.exact("abc", "def", "ghi", "j&k", 7l);
 +    assertTrue(r.contains(new Key("abc", "def", "ghi", "j&k", 7l)));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&k", 6l)));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&k", 8l)));
 +  }
 +  
 +  public void testPrefixRange() {
 +    Range r = Range.prefix("abc");
 +    assertTrue(r.contains(new Key("abc")));
 +    assertTrue(r.contains(new Key("abc", "def")));
 +    assertTrue(r.contains(new Key("abcd")));
 +    assertFalse(r.contains(new Key("abb")));
 +    assertFalse(r.contains(new Key("abd")));
 +    
 +    r = Range.prefix("abc", "def");
 +    assertTrue(r.contains(new Key("abc", "def", "ghi")));
 +    assertTrue(r.contains(new Key("abc", "defg")));
 +    assertFalse(r.contains(new Key("abc", "dee")));
 +    assertFalse(r.contains(new Key("abc", "deg")));
 +    
 +    r = Range.prefix("abc", "def", "ghi");
 +    assertTrue(r.contains(new Key("abc", "def", "ghi", "j&k")));
 +    assertTrue(r.contains(new Key("abc", "def", "ghij")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghh")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghj")));
 +    
 +    r = Range.prefix("abc", "def", "ghi", "j&k");
 +    assertTrue(r.contains(new Key("abc", "def", "ghi", "j&k", 7l)));
 +    assertTrue(r.contains(new Key("abc", "def", "ghi", "j&kl")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&j")));
 +    assertFalse(r.contains(new Key("abc", "def", "ghi", "j&l")));
 +    
 +    r = Range.prefix(makeText((byte) 0x07, (byte) 0xff));
 +    assertTrue(r.contains(new Key(makeText((byte) 0x07, (byte) 0xff))));
 +    assertTrue(r.contains(new Key(makeText((byte) 0x07, (byte) 0xff, (byte) 0x00))));
 +    assertFalse(r.contains(new Key(makeText((byte) 0x07, (byte) 0xfe))));
 +    assertFalse(r.contains(new Key(makeText((byte) 0x08))));
 +    
 +    r = Range.prefix(makeText((byte) 0xff));
 +    assertTrue(r.isInfiniteStopKey());
 +    assertTrue(r.contains(new Key(makeText((byte) 0xff))));
 +    assertTrue(r.contains(new Key(makeText((byte) 0xff, (byte) 0x07))));
 +    
 +    r = Range.prefix(new Text("abc"), makeText((byte) 0xff));
 +    assertTrue(r.contains(new Key(new Text("abc"), makeText((byte) 0xff))));
 +    assertTrue(r.contains(new Key(new Text("abc"), makeText((byte) 0xff, (byte) 0x07))));
 +    assertFalse(r.contains(new Key(new Text("abcd"))));
 +    assertFalse(r.contains(new Key(new Text("abd"))));
 +    
 +    r = Range.prefix(new Text("abc"), new Text("def"), makeText((byte) 0xff));
 +    assertTrue(r.contains(new Key(new Text("abc"), new Text("def"), makeText((byte) 0xff))));
 +    assertTrue(r.contains(new Key(new Text("abc"), new Text("def"), makeText((byte) 0xff, (byte) 0x07))));
 +    assertFalse(r.contains(new Key(new Text("abc"), new Text("defg"))));
 +    assertFalse(r.contains(new Key(new Text("abc"), new Text("deg"))));
 +    
 +    r = Range.prefix(new Text("abc"), new Text("def"), new Text("ghi"), makeText((byte) 0xff));
 +    assertTrue(r.contains(new Key(new Text("abc"), new Text("def"), new Text("ghi"), makeText((byte) 0xff))));
 +    assertTrue(r.contains(new Key(new Text("abc"), new Text("def"), new Text("ghi"), makeText((byte) 0xff, (byte) 0x07))));
 +    assertFalse(r.contains(new Key(new Text("abc"), new Text("def"), new Text("ghij"))));
 +    assertFalse(r.contains(new Key(new Text("abc"), new Text("def"), new Text("ghj"))));
 +  }
 +  
 +  public static Text makeText(byte... b) {
 +    return new Text(b);
 +  }
 +  
 +  public void testPrefix() {
 +    assertEquals(Range.followingPrefix(makeText((byte) 0x07)), new Text(makeText((byte) 0x08)));
 +    assertEquals(Range.followingPrefix(makeText((byte) 0xfe)), new Text(makeText((byte) 0xff)));
 +    assertNull(Range.followingPrefix(makeText((byte) 0xff)));
 +    assertNull(Range.followingPrefix(makeText((byte) 0xff, (byte) 0xff)));
 +    assertEquals(Range.followingPrefix(makeText((byte) 0x07, (byte) 0xff)), new Text(makeText((byte) 0x08)));
 +  }
++
++  public void testReadFields() throws Exception {
++    Range r = nr("nuts", "soup");
++    ByteArrayOutputStream baos = new ByteArrayOutputStream();
++    DataOutputStream dos = new DataOutputStream(baos);
++    r.write(dos);
++    dos.close();
++    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
++    DataInputStream dis = new DataInputStream(bais);
++    Range r2 = new Range();
++    r2.readFields(dis);
++    dis.close();
++
++    assertEquals(r, r2);
++  }
++
++  public void testReadFields_Check() throws Exception {
++    Range r = new Range(new Key(new Text("soup")), true, false, new Key(new Text("nuts")), true, false);
++    ByteArrayOutputStream baos = new ByteArrayOutputStream();
++    DataOutputStream dos = new DataOutputStream(baos);
++    r.write(dos);
++    dos.close();
++    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
++    DataInputStream dis = new DataInputStream(bais);
++    Range r2 = new Range();
++    try {
++      r2.readFields(dis);
++      fail("readFields allowed invalid range");
++    } catch (InvalidObjectException exc) {
++      /* good! */
++    } finally {
++      dis.close();
++    }
++  }
++
++  public void testThrift() {
++    Range r = nr("nuts", "soup");
++    TRange tr = r.toThrift();
++    Range r2 = new Range(tr);
++    assertEquals(r, r2);
++  }
++
++  public void testThrift_Check() {
++    Range r = new Range(new Key(new Text("soup")), true, false, new Key(new Text("nuts")), true, false);
++    TRange tr = r.toThrift();
++    try {
++      Range r2 = new Range(tr);
++      fail("Thrift constructor allowed invalid range");
++    } catch (IllegalArgumentException exc) {
++      /* good! */
++    }
++  }
 +}


Mime
View raw message