Exemplo n.º 1
0
  /** Convert this SprayPattern into data added to bay. */
  public void toBay(Bay bay) {

    // Make a byte array that's all false
    byte[] a = new byte[dataSize()];

    // Step through each true bit in this SprayPattern
    Step step = step(true);
    int byteIndex, bitIndex;
    while (step.next()) { // If this SprayPattern is all false, this loop won't run once
      byteIndex = step.i() / 8; // Divide by 8 and chop off the remainder to get the byte index
      bitIndex = step.i() % 8; // The bit index within that byte is the remainder

      // Flip the corresponding bit in a to 1
      a[byteIndex] = (byte) ((a[byteIndex] & 0xff) | (1 << (7 - bitIndex)));
    }

    // Add the byte array we made and filled to the given Bay
    bay.add(a);
  }
Exemplo n.º 2
0
 /** Convert this SprayPattern into data. */
 public Data data() {
   Bay bay = new Bay();
   toBay(bay);
   return bay.data();
 }