Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 78913178DF for ; Mon, 1 Jun 2015 10:12:14 +0000 (UTC) Received: (qmail 25337 invoked by uid 500); 1 Jun 2015 10:12:14 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 25276 invoked by uid 500); 1 Jun 2015 10:12:14 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 25267 invoked by uid 99); 1 Jun 2015 10:12:14 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jun 2015 10:12:14 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 126E9AC026E for ; Mon, 1 Jun 2015 10:12:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1682859 - in /commons/proper/collections/trunk/src: changes/changes.xml main/java/org/apache/commons/collections4/map/LRUMap.java test/java/org/apache/commons/collections4/map/LRUMapTest.java Date: Mon, 01 Jun 2015 10:12:13 -0000 To: commits@commons.apache.org From: tn@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150601101214.126E9AC026E@hades.apache.org> Author: tn Date: Mon Jun 1 10:12:13 2015 New Revision: 1682859 URL: http://svn.apache.org/r1682859 Log: [COLLECTIONS-557] Added support to specify the initial size of a LRUMap. Thanks to Philippe Mouawad. Modified: commons/proper/collections/trunk/src/changes/changes.xml commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/LRUMap.java commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java Modified: commons/proper/collections/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1682859&r1=1682858&r2=1682859&view=diff ============================================================================== --- commons/proper/collections/trunk/src/changes/changes.xml (original) +++ commons/proper/collections/trunk/src/changes/changes.xml Mon Jun 1 10:12:13 2015 @@ -22,6 +22,9 @@ + + Added support to specify the initial size of a "LRUMap". + Added decorators for "NavigableSet" interface. Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/LRUMap.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/LRUMap.java?rev=1682859&r1=1682858&r2=1682859&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/LRUMap.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/LRUMap.java Mon Jun 1 10:12:13 2015 @@ -91,6 +91,19 @@ public class LRUMap * Constructs a new, empty map with the specified maximum size. * * @param maxSize the maximum size of the map + * @param initialSize the initial size of the map + * @throws IllegalArgumentException if the maximum size is less than one + * @throws IllegalArgumentException if the initial size is negative or larger than the maximum size + * @since 4.1 + */ + public LRUMap(final int maxSize, final int initialSize) { + this(maxSize, initialSize, DEFAULT_LOAD_FACTOR); + } + + /** + * Constructs a new, empty map with the specified maximum size. + * + * @param maxSize the maximum size of the map * @param scanUntilRemovable scan until a removeable entry is found, default false * @throws IllegalArgumentException if the maximum size is less than one * @since 3.1 @@ -100,10 +113,11 @@ public class LRUMap } /** - * Constructs a new, empty map with the specified initial capacity and + * Constructs a new, empty map with the specified max capacity and * load factor. * * @param maxSize the maximum size of the map + * @param initialSize the initial size of the map * @param loadFactor the load factor * @throws IllegalArgumentException if the maximum size is less than one * @throws IllegalArgumentException if the load factor is less than zero @@ -113,21 +127,54 @@ public class LRUMap } /** - * Constructs a new, empty map with the specified initial capacity and + * Constructs a new, empty map with the specified max / initial capacity and * load factor. * * @param maxSize the maximum size of the map * @param loadFactor the load factor + * @throws IllegalArgumentException if the maximum size is less than one + * @throws IllegalArgumentException if the initial size is negative or larger than the maximum size + * @throws IllegalArgumentException if the load factor is less than zero + * @since 4.1 + */ + public LRUMap(final int maxSize, final int initialSize, final float loadFactor) { + this(maxSize, initialSize, loadFactor, false); + } + + /** + * Constructs a new, empty map with the specified max capacity and load factor. + * + * @param maxSize the maximum size of the map + * @param loadFactor the load factor * @param scanUntilRemovable scan until a removeable entry is found, default false * @throws IllegalArgumentException if the maximum size is less than one * @throws IllegalArgumentException if the load factor is less than zero * @since 3.1 */ public LRUMap(final int maxSize, final float loadFactor, final boolean scanUntilRemovable) { - super(maxSize < 1 ? DEFAULT_CAPACITY : maxSize, loadFactor); + this(maxSize, maxSize, loadFactor, scanUntilRemovable); + } + + /** + * Constructs a new, empty map with the specified max / initial capacity and load factor. + * + * @param maxSize the maximum size of the map + * @param initialSize the initial size of the map + * @param loadFactor the load factor + * @param scanUntilRemovable scan until a removeable entry is found, default false + * @throws IllegalArgumentException if the maximum size is less than one + * @throws IllegalArgumentException if the initial size is negative or larger than the maximum size + * @throws IllegalArgumentException if the load factor is less than zero + * @since 4.1 + */ + public LRUMap(final int maxSize, final int initialSize, final float loadFactor, final boolean scanUntilRemovable) { + super(initialSize, loadFactor); if (maxSize < 1) { throw new IllegalArgumentException("LRUMap max size must be greater than 0"); } + if (initialSize > maxSize) { + throw new IllegalArgumentException("LRUMap initial size must not be greather than max size"); + } this.maxSize = maxSize; this.scanUntilRemovable = scanUntilRemovable; } Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java?rev=1682859&r1=1682858&r2=1682859&view=diff ============================================================================== --- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java (original) +++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java Mon Jun 1 10:12:13 2015 @@ -62,12 +62,59 @@ public class LRUMapTest extends Ab return true; } + /** + * {@inheritDoc} + */ @Override - public String getCompatibilityVersion() { - return "4"; + public LRUMap getMap() { + return (LRUMap) super.getMap(); } //----------------------------------------------------------------------- + public void testCtors() { + try { + new LRUMap(0); + fail("maxSize must be positive"); + } catch(IllegalArgumentException ex) { + // expected + } + + try { + new LRUMap(-1, 12, 0.75f, false); + fail("maxSize must be positive"); + } catch(IllegalArgumentException ex) { + // expected + } + + try { + new LRUMap(10, -1); + fail("initialSize must not be negative"); + } catch(IllegalArgumentException ex) { + // expected + } + + try { + new LRUMap(10, 12); + fail("initialSize must not be larger than maxSize"); + } catch(IllegalArgumentException ex) { + // expected + } + + try { + new LRUMap(10, -1, 0.75f, false); + fail("initialSize must not be negative"); + } catch(IllegalArgumentException ex) { + // expected + } + + try { + new LRUMap(10, 12, 0.75f, false); + fail("initialSize must not be larger than maxSize"); + } catch(IllegalArgumentException ex) { + // expected + } + } + public void testLRU() { if (!isPutAddSupported() || !isPutChangeSupported()) { return; @@ -873,6 +920,11 @@ public class LRUMapTest extends Ab + counter[0] + " did succeed", counter[0] >= threads.length); } + @Override + public String getCompatibilityVersion() { + return "4"; + } + // public void testCreate() throws Exception { // resetEmpty(); // writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/LRUMap.emptyCollection.version4.obj"); @@ -880,11 +932,4 @@ public class LRUMapTest extends Ab // writeExternalFormToDisk((java.io.Serializable) map, "src/test/resources/data/test/LRUMap.fullCollection.version4.obj"); // } - /** - * {@inheritDoc} - */ - @Override - public LRUMap getMap() { - return (LRUMap) super.getMap(); - } }