public synchronized void add(T newElement){
  if (elements.size() - 1 > nextElementIndex) {
    elements.set(nextElementIndex++,newElement);
  }
 else {
    elements.add(nextElementIndex++,newElement);
  }
  if (nextElementIndex == capacity) {
    nextElementIndex=0;
  }
}

public synchronized void add ( T newElement ) { if ( elements . size ( ) - 1 > nextElementIndex ) { elements . set ( nextElementIndex ++ , newElement ) ; } else { elements . add ( nextElementIndex ++ , newElement ) ; } if ( nextElementIndex == capacity ) { nextElementIndex = 0 ; } }
add an element to the buffer .
