code: @Override
      public Object[] toArray() {
          int size = size();
          Object[] retArray;
          if (size < 1) {
              retArray = new Object[] {};
          } else {
  
              retArray = new Object[size];
              int retArrayIndex = 0;
  
              synchronized (this) {
  
                  synchronized (lock) {
                      //Add the items in the expedited buffer first
                      //Check if we wrap around the end of the array before iterating
                      if (expeditedPutIndex > expeditedTakeIndex) {
                          for (int i = expeditedTakeIndex; i <= expeditedPutIndex; i++) {
                              retArray[retArrayIndex] = expeditedBuffer[i];
                              retArrayIndex++;
                          }
                      } else {
                          //We wrap around the array. Loop through in two passes(upper and lower)
                          for (int i = expeditedTakeIndex; i < expeditedBuffer.length; i++) {
                              retArray[retArrayIndex] = expeditedBuffer[i];
                              retArrayIndex++;
                          }
                          for (int i = 0; i < expeditedPutIndex; i++) {
                              retArray[retArrayIndex] = expeditedBuffer[i];
                              retArrayIndex++;
                          }
                      }
  
                      //Next add the items in the main buffer
                      //Check if we wrap around the end of the array before iterating
                      if (putIndex > takeIndex) {
                          for (int i = takeIndex; i <= putIndex; i++) {
                              retArray[retArrayIndex] = buffer[i];
                              retArrayIndex++;
                          }
                      } else {
                          //We wrap around the array. Loop through in two passes(upper and lower)
                          for (int i = takeIndex; i < buffer.length; i++) {
                              retArray[retArrayIndex] = buffer[i];
                              retArrayIndex++;
                          }
                          for (int i = 0; i < putIndex; i++) {
                              retArray[retArrayIndex] = buffer[i];
                              retArrayIndex++;
                          }
                      }
                  }
              }
          }
          return retArray;
  
      }
docs: /*
  @awisniew - ADDED
  
  (non-Javadoc)
  
  @see java.util.Collection#toArray()