@@ -0,0 +1,1858 @@
+/*%0A * Copyright 2010 Workplace Systems PLC (http://www.workplacesystems.com/).%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22); you may not%0A * use this file except in compliance with the License. You may obtain a copy of%0A * the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0Apackage com.workplacesystems.utilsj.collections.helpers;%0A%0Aimport com.workplacesystems.utilsj.UtilsjException;%0Aimport com.workplacesystems.utilsj.collections.FilterableCollection;%0Aimport com.workplacesystems.utilsj.collections.IterativeCallback;%0A%0A/**%0A *%0A * @author dave%0A */%0Apublic class HasLessThan%3CT%3E extends IterativeCallback%3CT, HasLessThan%3CT%3E%3E%0A%7B%0A    private int total;%0A    private int count = 0;%0A%0A    private HasLessThan() %7B%7D%0A%0A    public HasLessThan(int total) %7B%0A        this.total = total;%0A    %7D%0A%0A    @Override%0A    public HasLessThan%3CT%3E iterate(final FilterableCollection%3C? extends T%3E c)%0A    %7B%0A        if (total %3C= 0)%0A            return this;%0A%0A        super.iterate(c);%0A%0A        return new HasLessThan%3CT%3E(total - count);%0A    %7D%0A%0A    @Override%0A    public void nextObject(T obj) %7B%0A        count++;%0A        if (count %3E= total)%0A            _break();%0A    %7D%0A%0A    /**%0A     * Returns whether the total has been reached.%0A     * @throws QueujException if the iterative callback has not been used yet%0A     */%0A    public boolean hasLess() throws UtilsjException%0A    %7B%0A        if (!hasBeenUsed())%0A            throw new UtilsjException(%22HasLessThan.hasLess() called without having been used%22);%0A        return count %3C total;%0A    %7D%0A%7D%0A

Create HasLessThan, an IterativeCallback to replace 'Collection.size() < X' checks. It breaks the loop as soon as the check is no longer true rather than continuing to count the remaining Objects in the Collection thereby improving scalability.