Poll for the next N waiting jobs in line.

@param size maximum amount of jobs to poll for
@return up to "size" jobs
762629
public final List<PrintJobStatusExtImpl> poll(final int size) {
        final CriteriaBuilder builder = getSession().getCriteriaBuilder();
        final CriteriaQuery<PrintJobStatusExtImpl> criteria =
                builder.createQuery(PrintJobStatusExtImpl.class);
        final Root<PrintJobStatusExtImpl> root = criteria.from(PrintJobStatusExtImpl.class);
        root.alias("pj");
        criteria.where(builder.equal(root.get("status"), PrintJobStatus.Status.WAITING));
        criteria.orderBy(builder.asc(root.get("entry").get("startTime")));
        final Query<PrintJobStatusExtImpl> query = getSession().createQuery(criteria);
        query.setMaxResults(size);
        // LOCK but don't wait for release (since this is run continuously
        // anyway, no wait prevents deadlock)
        query.setLockMode("pj", LockMode.UPGRADE_NOWAIT);
        try {
            return query.getResultList();
        } catch (PessimisticLockException ex) {
            // Another process was polling at the same time. We can ignore this error
            return Collections.emptyList();
        }
    }
581836
public static Buffer getQueue(int size) {

        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(
                Messages.get().getBundle().key(Messages.INIT_PUBLISH_HISTORY_SIZE_SET_1, new Integer(size)));
        }

        return BufferUtils.synchronizedBuffer(TypedBuffer.decorate(new CircularFifoBuffer(size) {

            /** The serialization version id constant. */
            private static final long serialVersionUID = -6257542123241183114L;

            /**
             * Called when the queue is full to remove the oldest element.<p>
             *
             * @see org.apache.commons.collections.buffer.BoundedFifoBuffer#remove()
             */
            @Override
            public Object remove() {

                CmsPublishJobInfoBean publishJob = (CmsPublishJobInfoBean)super.remove();
                try {
                    OpenCms.getPublishManager().getEngine().getPublishHistory().remove(publishJob);
                } catch (CmsException exc) {
                    if (LOG.isErrorEnabled()) {
                        LOG.error(exc.getLocalizedMessage(), exc);
                    }
                }
                return publishJob;
            }
        }, CmsPublishJobInfoBean.class));
    }
327027
public static AreaI area(final AreaSizeI size)
  {
    Objects.requireNonNull(size, "Size");
    return AreaI.of(0, size.sizeX(), 0, size.sizeY());
  }
524066
public ImageHandlerBuilder resizeToWidth(int size) {
         if (image.getWidth() < size) return this;
         BufferedImage resize = Scalr.resize(image, Scalr.Mode.FIT_TO_WIDTH, size);
         image.flush();
         image = resize;
         return this;
     }
402481
@Override
    public int getNumberOfJobs() throws JobPersistenceException {
        return  doWithLock(new LockCallback<Integer>() {
            @Override
            public Integer doWithLock(JedisCommands jedis) throws JobPersistenceException {
                return storage.getNumberOfJobs(jedis);
            }
        }, "Could not get number of jobs.");
    }
335344
public static int[] randomPermutation(int size) {
        Random r = new Random();
        int[] result = new int[size];

        for (int j = 0; j < size; j++) {
            result[j] = j;
        }
        
        for (int j = size - 1; j > 0; j--) {
            int k = r.nextInt(j);
            int temp = result[j];
            result[j] = result[k];
            result[k] = temp;
        }

        return result;
    }
18609
public SeleniumAssert hasSize(Integer size) {
        if (actual instanceof PreviousWebElements) {
            Integers.instance().assertEqual(info, ((PreviousWebElements) actual).getPreviousWebElements().size(), size);
        }
        return this;
    }
128538
public static BlockingQueue<Runnable> buildQueue(int size, boolean isPriority) {
        BlockingQueue<Runnable> queue;
        if (size == 0) { // 默认无队列
            queue = new SynchronousQueue<Runnable>();
        } else { // 有限队列或无限队列
            if (isPriority) {
                queue = size < 0 ? new PriorityBlockingQueue<Runnable>()
                    : new PriorityBlockingQueue<Runnable>(size);
            } else {
                queue = size < 0 ? new LinkedBlockingQueue<Runnable>()
                    : new LinkedBlockingQueue<Runnable>(size);
            }
        }
        return queue;
    }
1321578
@SuppressWarnings("unchecked")
    @Override
    public E poll() {
        if (_size.get() == 0)
            return null;

        E e = null;

        _headLock.lock(); // Size cannot shrink
        try {
            if (_size.get() > 0) {
                final int head = _indexes[HEAD_OFFSET];
                e = (E) _elements[head];
                _elements[head] = null;
                _indexes[HEAD_OFFSET] = (head + 1) % _elements.length;
                if (_size.decrementAndGet() > 0)
                    _notEmpty.signal();
            }
        } finally {
            _headLock.unlock();
        }
        return e;
    }
632593
protected Func1<HttpClientResponse<ByteBuf>, Integer> withBookkeeping(final int batchSize) {
    return response -> {
      boolean ok = response.getStatus().code() == 200;
      if (ok) {
        numMetricsSent.increment(batchSize);
      } else {
        LOGGER.info("Status code: {} - Lost {} metrics",
            response.getStatus().code(), batchSize);
        numMetricsDroppedHttpErr.increment(batchSize);
      }

      return batchSize;
    };
  }
284736
public RunList<R> limit(final int n) {
        return limit(new CountingPredicate<R>() {
            public boolean apply(int index, R input) {
                return index<n;
            }
        });
    }
1357722
public WrappedByteBuffer skip(int size) {
        _autoExpand(size);
        _buf.position(_buf.position() + size);
        return this;
    }
771519
public final T poll() {
		if (size > 0) {
			T result = heap[1]; // save first value
			heap[1] = heap[size]; // move last to first
			heap[size] = null; // permit GC of objects
			size--;
			downHeap(); // adjust heap
			return result;
		} else {
			return null;
		}
	}
1025943
public static List<Integer> getRandomIntegers(final int start, final int end, final int size) {
        if (size > (end - start + 1)) {
            throw new IllegalArgumentException("The specified size more then (end - start + 1)!");
        }

        final List<Integer> integers = genIntegers(start, end);
        final List<Integer> ret = new ArrayList<Integer>();

        int remainsSize;
        int index;

        while (ret.size() < size) {
            remainsSize = integers.size();
            index = (int) (Math.random() * (remainsSize - 1));
            final Integer i = integers.get(index);

            ret.add(i);
            integers.remove(i);
        }

        return ret;
    }
918051
public void ensureCapacity(int size) {
    if (size > elements.length) {
      reallocate(Math.max(size, 2 * elements.length));
    }
  }
1320161
public final int getNewBufferSize(int curSize, int minNewSize) {
      if (curSize <= maxDoublingSize)
         return Math.max(curSize << 1, minNewSize);
      else
         return Math.max(curSize + (curSize >> 2), minNewSize);
   }
1118096
public static DoubleMinMax[] newArray(int size) {
    DoubleMinMax[] ret = new DoubleMinMax[size];
    for(int i = 0; i < size; i++) {
      ret[i] = new DoubleMinMax();
    }
    return ret;
  }