@Override public boolean hasNext() { return !isEmpty(); }
/** * Warning - this will convert the entire queue to an array to get a hashcode, * so use it with caution. */ @Override public int hashCode() { return new HashCodeBuilder(13, 47) .append(toArray()) .toHashCode(); }
queue = new ConsumableBlockingQueue<>(maxQueueSize); restart = true; queue.put(element); } catch (final InterruptedException e) { throw new RuntimeException("Interrupted while waiting to add an element to the queue", e); if (restart && !queue.isEmpty()) { restart = false; store.runAsync(() -> {
@Override public T next() { if (!hasNext()) { throw new NoSuchElementException("No more items"); } return poll(); } };
/** * Warning - this will convert the entire queue to an array to check if the * items are equal so use it with with caution. * * @param obj the object to compare * @return true if equal, otherwise false. */ @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (null == obj || getClass() != obj.getClass()) { return false; } final ConsumableBlockingQueue queue = (ConsumableBlockingQueue) obj; return new EqualsBuilder() .append(toArray(), queue.toArray()) .isEquals(); }
/** * Warning - this will convert the entire queue to an array to get a string, * so use with caution. */ @Override public String toString() { return new ToStringBuilder(this) .append("items", toArray()) .toString(); } }