You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/01/28 06:09:40 UTC

svn commit: r1439255 - in /lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util: BytesRef.java CharsRef.java IntsRef.java LongsRef.java

Author: rmuir
Date: Mon Jan 28 05:09:40 2013
New Revision: 1439255

URL: http://svn.apache.org/viewvc?rev=1439255&view=rev
Log:
extend ctor checks to other Ref classes

Modified:
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/CharsRef.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/IntsRef.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/LongsRef.java

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java?rev=1439255&r1=1439254&r2=1439255&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/BytesRef.java Mon Jan 28 05:09:40 2013
@@ -342,7 +342,6 @@ public final class BytesRef implements C
    * Performs internal consistency checks.
    * Always returns true (or throws IllegalStateException) 
    */
-  // TODO: also for the other *Ref classes
   public boolean isValid() {
     if (bytes == null) {
       throw new IllegalStateException("bytes is null");
@@ -351,13 +350,13 @@ public final class BytesRef implements C
       throw new IllegalStateException("length is negative: " + length);
     }
     if (length > bytes.length) {
-      throw new IllegalStateException("length is out of bounds: " + length + ", bytes.length=" + bytes.length);
+      throw new IllegalStateException("length is out of bounds: " + length + ",bytes.length=" + bytes.length);
     }
     if (offset < 0) {
       throw new IllegalStateException("offset is negative: " + offset);
     }
     if (offset > bytes.length) {
-      throw new IllegalStateException("offset out of bounds: " + offset + ", length=" + bytes.length);
+      throw new IllegalStateException("offset out of bounds: " + offset + ",bytes.length=" + bytes.length);
     }
     if (offset + length < 0) {
       throw new IllegalStateException("offset+length is negative: offset=" + offset + ",length=" + length);

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/CharsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/CharsRef.java?rev=1439255&r1=1439254&r2=1439255&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/CharsRef.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/CharsRef.java Mon Jan 28 05:09:40 2013
@@ -55,13 +55,10 @@ public final class CharsRef implements C
    * length
    */
   public CharsRef(char[] chars, int offset, int length) {
-    assert chars != null;
-    assert offset >= 0;
-    assert length >= 0;
-    assert chars.length >= offset + length;
     this.chars = chars;
     this.offset = offset;
     this.length = length;
+    assert isValid();
   }
 
   /**
@@ -292,4 +289,33 @@ public final class CharsRef implements C
     clone.copyChars(other);
     return clone;
   }
+  
+  /** 
+   * Performs internal consistency checks.
+   * Always returns true (or throws IllegalStateException) 
+   */
+  public boolean isValid() {
+    if (chars == null) {
+      throw new IllegalStateException("chars is null");
+    }
+    if (length < 0) {
+      throw new IllegalStateException("length is negative: " + length);
+    }
+    if (length > chars.length) {
+      throw new IllegalStateException("length is out of bounds: " + length + ",chars.length=" + chars.length);
+    }
+    if (offset < 0) {
+      throw new IllegalStateException("offset is negative: " + offset);
+    }
+    if (offset > chars.length) {
+      throw new IllegalStateException("offset out of bounds: " + offset + ",chars.length=" + chars.length);
+    }
+    if (offset + length < 0) {
+      throw new IllegalStateException("offset+length is negative: offset=" + offset + ",length=" + length);
+    }
+    if (offset + length > chars.length) {
+      throw new IllegalStateException("offset+length out of bounds: offset=" + offset + ",length=" + length + ",chars.length=" + chars.length);
+    }
+    return true;
+  }
 }
\ No newline at end of file

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/IntsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/IntsRef.java?rev=1439255&r1=1439254&r2=1439255&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/IntsRef.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/IntsRef.java Mon Jan 28 05:09:40 2013
@@ -50,13 +50,10 @@ public final class IntsRef implements Co
    * ints should not be null.
    */
   public IntsRef(int[] ints, int offset, int length) {
-    assert ints != null;
-    assert offset >= 0;
-    assert length >= 0;
-    assert ints.length >= offset + length;
     this.ints = ints;
     this.offset = offset;
     this.length = length;
+    assert isValid();
   }
 
   @Override
@@ -176,4 +173,33 @@ public final class IntsRef implements Co
     clone.copyInts(other);
     return clone;
   }
+  
+  /** 
+   * Performs internal consistency checks.
+   * Always returns true (or throws IllegalStateException) 
+   */
+  public boolean isValid() {
+    if (ints == null) {
+      throw new IllegalStateException("ints is null");
+    }
+    if (length < 0) {
+      throw new IllegalStateException("length is negative: " + length);
+    }
+    if (length > ints.length) {
+      throw new IllegalStateException("length is out of bounds: " + length + ",ints.length=" + ints.length);
+    }
+    if (offset < 0) {
+      throw new IllegalStateException("offset is negative: " + offset);
+    }
+    if (offset > ints.length) {
+      throw new IllegalStateException("offset out of bounds: " + offset + ",ints.length=" + ints.length);
+    }
+    if (offset + length < 0) {
+      throw new IllegalStateException("offset+length is negative: offset=" + offset + ",length=" + length);
+    }
+    if (offset + length > ints.length) {
+      throw new IllegalStateException("offset+length out of bounds: offset=" + offset + ",length=" + length + ",ints.length=" + ints.length);
+    }
+    return true;
+  }
 }

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/LongsRef.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/LongsRef.java?rev=1439255&r1=1439254&r2=1439255&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/LongsRef.java (original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/util/LongsRef.java Mon Jan 28 05:09:40 2013
@@ -49,13 +49,10 @@ public final class LongsRef implements C
   /** This instance will directly reference longs w/o making a copy.
    * longs should not be null */
   public LongsRef(long[] longs, int offset, int length) {
-    assert longs != null;
-    assert offset >= 0;
-    assert length >= 0;
-    assert longs.length >= offset + length;
     this.longs = longs;
     this.offset = offset;
     this.length = length;
+    assert isValid();
   }
 
   @Override
@@ -175,4 +172,33 @@ public final class LongsRef implements C
     clone.copyLongs(other);
     return clone;
   }
+  
+  /** 
+   * Performs internal consistency checks.
+   * Always returns true (or throws IllegalStateException) 
+   */
+  public boolean isValid() {
+    if (longs == null) {
+      throw new IllegalStateException("longs is null");
+    }
+    if (length < 0) {
+      throw new IllegalStateException("length is negative: " + length);
+    }
+    if (length > longs.length) {
+      throw new IllegalStateException("length is out of bounds: " + length + ",longs.length=" + longs.length);
+    }
+    if (offset < 0) {
+      throw new IllegalStateException("offset is negative: " + offset);
+    }
+    if (offset > longs.length) {
+      throw new IllegalStateException("offset out of bounds: " + offset + ",longs.length=" + longs.length);
+    }
+    if (offset + length < 0) {
+      throw new IllegalStateException("offset+length is negative: offset=" + offset + ",length=" + length);
+    }
+    if (offset + length > longs.length) {
+      throw new IllegalStateException("offset+length out of bounds: offset=" + offset + ",length=" + length + ",longs.length=" + longs.length);
+    }
+    return true;
+  }
 }