Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.infinispan.lucene.testutils;
 
RepeatableLongByteSequence is a testing utility to get a source of bytes. Use nextByte() to produce them. The generated sequence is similar to a random generated sequence, but will always generate the same sequence and avoid immediate repetitions of bytes and close repetitive patterns (they might occur in large scale). After having written such a stream from one instance, create a second instance to assert equality of contents (see test) as the source is not random and will generate the same sequence.

Author(s):
Sanne Grinovero
Since:
4.0
   private byte lastUsedValue = -1;
   private byte currentMax = (byte) 1;
   private byte currentMin = (byte) -1;
   private boolean rising = true;
   public byte nextByte() {
      byte next;
      if () {
         next = ++;
         if (next == ) {
             = false;
            ++; // overflow might occur, not bad for our purposes.
         }
      } else {
         next = --;
         if (next == ) {
             = true;
            --; // as above: overflow allowed
         }
      }
      return next;
   }

   

Parameters:
buffer is going to be modified: a new series of bytes is going to be written into
   public void nextBytes(byte[] buffer) {
      for(int i=0; i < buffer.lengthi++) {
         buffer[i] = nextByte();
      }
   }
   
   public void reset() {
       = -1;
       = (byte) 1;
       = (byte) -1;
       = true;
   }
New to GrepCode? Check out our FAQ X