/** * Attempts to acquire the lock. Returns false if the lock is not available and * true if the lock has been successfully acquired. */ private synchronized boolean attempt() { //return true if we already own the lock //also, if nobody is waiting, grant the lock immediately if ((currentOperationThread == Thread.currentThread()) || (currentOperationThread == null && operations.isEmpty())) { depth++; setCurrentOperationThread(Thread.currentThread()); return true; } return false; }
public Iterator elements() { /**/ if (isEmpty()) return new ArrayList(0).iterator(); /* if head < tail we can use the same array */ if (head <= tail) return Arrays.asList(elements).iterator(); /* otherwise we need to create a new array */ Object[] newElements = new Object[size()]; int end = (elements.length - head); System.arraycopy(elements, head, newElements, 0, end); System.arraycopy(elements, 0, newElements, end, tail); return Arrays.asList(newElements).iterator(); }
/** * Attempts to acquire the lock. Returns false if the lock is not available and * true if the lock has been successfully acquired. */ private synchronized boolean attempt() { //return true if we already own the lock //also, if nobody is waiting, grant the lock immediately if ((currentOperationThread == Thread.currentThread()) || (currentOperationThread == null && operations.isEmpty())) { depth++; setCurrentOperationThread(Thread.currentThread()); return true; } return false; }
public Iterator elements() { /**/ if (isEmpty()) return new ArrayList(0).iterator(); /* if head < tail we can use the same array */ if (head <= tail) return Arrays.asList(elements).iterator(); /* otherwise we need to create a new array */ Object[] newElements = new Object[size()]; int end = (elements.length - head); System.arraycopy(elements, head, newElements, 0, end); System.arraycopy(elements, 0, newElements, end, tail); return Arrays.asList(newElements).iterator(); }
/** * Attempts to acquire the lock. Returns false if the lock is not available and * true if the lock has been successfully acquired. */ private synchronized boolean attempt() { //return true if we already own the lock //also, if nobody is waiting, grant the lock immediately if ((currentOperationThread == Thread.currentThread()) || (currentOperationThread == null && operations.isEmpty())) { depth++; setCurrentOperationThread(Thread.currentThread()); return true; } return false; }
/** * Attempts to acquire the lock. Returns false if the lock is not available and * true if the lock has been successfully acquired. */ private synchronized boolean attempt() { //return true if we already own the lock //also, if nobody is waiting, grant the lock immediately if ((currentOperationThread == Thread.currentThread()) || (currentOperationThread == null && operations.isEmpty())) { depth++; setCurrentOperationThread(Thread.currentThread()); return true; } return false; }
public Iterator elements() { /**/ if (isEmpty()) return new ArrayList(0).iterator(); /* if head < tail we can use the same array */ if (head <= tail) return Arrays.asList(elements).iterator(); /* otherwise we need to create a new array */ Object[] newElements = new Object[size()]; int end = (elements.length - head); System.arraycopy(elements, head, newElements, 0, end); System.arraycopy(elements, 0, newElements, end, tail); return Arrays.asList(newElements).iterator(); }
public Iterator elements() { /**/ if (isEmpty()) return new ArrayList(0).iterator(); /* if head < tail we can use the same array */ if (head <= tail) return Arrays.asList(elements).iterator(); /* otherwise we need to create a new array */ Object[] newElements = new Object[size()]; int end = (elements.length - head); System.arraycopy(elements, head, newElements, 0, end); System.arraycopy(elements, 0, newElements, end, tail); return Arrays.asList(newElements).iterator(); }
@Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("["); //$NON-NLS-1$ if (!isEmpty()) { Iterator it = elements(); while (true) { sb.append(it.next()); if (it.hasNext()) sb.append(", "); //$NON-NLS-1$ else break; } } sb.append("]"); //$NON-NLS-1$ return sb.toString(); } }
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("["); //$NON-NLS-1$ if (!isEmpty()) { Iterator it = elements(); while (true) { sb.append(it.next()); if (it.hasNext()) sb.append(", "); //$NON-NLS-1$ else break; } } sb.append("]"); //$NON-NLS-1$ return sb.toString(); } }
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("["); //$NON-NLS-1$ if (!isEmpty()) { Iterator it = elements(); while (true) { sb.append(it.next()); if (it.hasNext()) sb.append(", "); //$NON-NLS-1$ else break; } } sb.append("]"); //$NON-NLS-1$ return sb.toString(); } }
@Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("["); //$NON-NLS-1$ if (!isEmpty()) { Iterator it = elements(); while (true) { sb.append(it.next()); if (it.hasNext()) sb.append(", "); //$NON-NLS-1$ else break; } } sb.append("]"); //$NON-NLS-1$ return sb.toString(); } }
/** * Removes an returns the item at the head of the queue. */ public Object dequeue() { if (isEmpty()) return null; Object result = peek(); if (!reuse) elements[head] = null; head = increment(head); return result; }
/** * Removes an returns the item at the head of the queue. */ public Object dequeue() { if (isEmpty()) return null; Object result = peek(); if (!reuse) elements[head] = null; head = increment(head); return result; }
/** * Removes an returns the item at the head of the queue. */ public Object dequeue() { if (isEmpty()) return null; Object result = peek(); if (!reuse) elements[head] = null; head = increment(head); return result; }
/** * Removes an returns the item at the head of the queue. */ public Object dequeue() { if (isEmpty()) return null; Object result = peek(); if (!reuse) elements[head] = null; head = increment(head); return result; }