This is an automated email from the ASF dual-hosted git repository.

gk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/turbine-fulcrum-pool.git

commit 1e3320acc3528d5eae92b0072cd7befb1caa3dad
Author: Jeffery Painter <[email protected]>
AuthorDate: Fri Jan 11 14:19:15 2019 +0000

    Start conversion to generics, please review and give feedback
    
    git-svn-id: 
https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/pool@1851054 
13f79535-47bb-0310-9956-ffa450edef68
---
 src/changes/changes.xml                                 |  7 ++++++-
 src/java/org/apache/fulcrum/pool/BoundedBuffer.java     |  5 +++--
 .../org/apache/fulcrum/pool/DefaultPoolService.java     | 17 +++++++++--------
 src/java/org/apache/fulcrum/pool/PoolBuffer.java        |  8 ++++----
 src/java/org/apache/fulcrum/pool/PoolService.java       |  6 ++++--
 5 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b6d4c63..ad37d4e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,7 +24,12 @@
   </properties>
 
   <body>
-    <release version="1.0.5" date="in SVN">
+    <release version="1.0.6" date="in SVN">
+       <action dev="painter" type="update">
+         Move to generics
+       </action>
+    </release>
+    <release version="1.0.5" date="2019-01-11">
        <action dev="painter" type="update">
          Update test to use junit 5
        </action>
diff --git a/src/java/org/apache/fulcrum/pool/BoundedBuffer.java 
b/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
index 56bfbed..d75a268 100644
--- a/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
+++ b/src/java/org/apache/fulcrum/pool/BoundedBuffer.java
@@ -133,12 +133,13 @@ public class BoundedBuffer
      *
      * @return the oldest item from the buffer, or null if the buffer is empty.
      */
-    public synchronized Object poll()
+    public synchronized <T> T poll()
     {
         if (usedSlots_ > 0)
         {
             --usedSlots_;
-            Object old = array_[takePtr_];
+            @SuppressWarnings("unchecked")
+                       T old = (T) array_[takePtr_];
             array_[takePtr_] = null;
             if (++takePtr_ >= array_.length)
                 takePtr_ = 0;
diff --git a/src/java/org/apache/fulcrum/pool/DefaultPoolService.java 
b/src/java/org/apache/fulcrum/pool/DefaultPoolService.java
index f713bda..6e8e0f9 100644
--- a/src/java/org/apache/fulcrum/pool/DefaultPoolService.java
+++ b/src/java/org/apache/fulcrum/pool/DefaultPoolService.java
@@ -78,11 +78,11 @@ public class DefaultPoolService extends AbstractLogEnabled
         * @return the instance.
         * @throws PoolException if recycling fails.
         */
-       public Object getInstance(String className) throws PoolException 
+       public <T> T getInstance(String className) throws PoolException 
        {
                try 
                {
-                       Object instance = pollInstance(className, null, null);
+                       T instance = pollInstance(className, null, null);
                        return instance == null ? 
getFactory().getInstance(className) : instance;
                } 
                catch (FactoryException fe) 
@@ -183,17 +183,18 @@ public class DefaultPoolService extends AbstractLogEnabled
         * Gets an instance of a specified class either from the pool or by 
instatiating
         * from the class if the pool is empty.
         *
+        * @param <T> type of the class
         * @param clazz the class.
         * @return the instance.
         * @throws PoolException if recycling fails.
         */
        @SuppressWarnings("unchecked")
-       public Object getInstance(Class clazz) throws PoolException 
+       public <T> T getInstance(Class<?> clazz) throws PoolException 
        {
                try 
                {
-                       Object instance = pollInstance(clazz.getName(), null, 
null);
-                       return instance == null ? 
factoryService.getInstance(clazz) : instance;
+                       T instance = pollInstance(clazz.getName(), null, null);
+                       return instance == null ? (T) 
factoryService.getInstance(clazz) : instance;
                } 
                catch (FactoryException fe) 
                {
@@ -211,11 +212,11 @@ public class DefaultPoolService extends AbstractLogEnabled
         * @return the instance.
         * @throws PoolException if recycling fails.
         */
-       public Object getInstance(Class clazz, Object params[], String 
signature[]) throws PoolException 
+       public <T> T getInstance(Class<?> clazz, Object params[], String 
signature[]) throws PoolException 
        {
                try 
                {
-                       Object instance = pollInstance(clazz.getName(), params, 
signature);
+                       T instance = pollInstance(clazz.getName(), params, 
signature);
                        
                        // TODO There is a whacky .toString() on the clazz 
object, 
                        // but otherwise it won't compile
@@ -349,7 +350,7 @@ public class DefaultPoolService extends AbstractLogEnabled
         * @return the object or null.
         * @throws PoolException if recycling fails.
         */
-       private Object pollInstance(String className, Object[] params, String[] 
signature) throws PoolException 
+       private <T> T pollInstance(String className, Object[] params, String[] 
signature) throws PoolException 
        {
                PoolBuffer pool = (PoolBuffer) poolRepository.get(className);
                return pool != null ? pool.poll(params, signature, 
factoryService) : null;
diff --git a/src/java/org/apache/fulcrum/pool/PoolBuffer.java 
b/src/java/org/apache/fulcrum/pool/PoolBuffer.java
index 7b36d94..4cb732c 100644
--- a/src/java/org/apache/fulcrum/pool/PoolBuffer.java
+++ b/src/java/org/apache/fulcrum/pool/PoolBuffer.java
@@ -46,7 +46,7 @@ public class PoolBuffer
        private ArrayList<Recycler> recyclers;
 
        /**
-        * Contructs a new pool buffer with a specific capacity.
+        * Constructs a new pool buffer with a specific capacity.
         *
         * @param capacity a capacity.
         */
@@ -70,15 +70,15 @@ public class PoolBuffer
         * Polls for an instance from the pool.
         * 
         * 
-        * @param params         object paramaters
+        * @param params         object parameters
         * @param signature      signature of the class
         * @param factoryService service to add
         * @throws PoolException if service failed to be found
         * @return an instance or null.
         */
-       public Object poll(Object[] params, String[] signature, FactoryService 
factoryService) throws PoolException 
+       public <T> T poll(Object[] params, String[] signature, FactoryService 
factoryService) throws PoolException 
        {
-               Object instance = pool.poll();
+               T instance = pool.poll();
                if (instance != null) 
                {
                        if (arrayCtorRecyclable) 
diff --git a/src/java/org/apache/fulcrum/pool/PoolService.java 
b/src/java/org/apache/fulcrum/pool/PoolService.java
index 7f3f755..a61b298 100644
--- a/src/java/org/apache/fulcrum/pool/PoolService.java
+++ b/src/java/org/apache/fulcrum/pool/PoolService.java
@@ -50,23 +50,25 @@ public interface PoolService
         * Gets an instance of a specified class either from the pool or by
         * instantiating from the class if the pool is empty.
         *
+        * @param <T> type of the instance
         * @param clazz the class.
         * @return the instance.
         * @throws PoolException if recycling fails.
         */
-       public Object getInstance(Class clazz) throws PoolException;
+       public <T> T getInstance(Class<?> clazz) throws PoolException;
 
        /**
         * Gets an instance of a specified class either from the pool or by
         * instantiating from the class if the pool is empty.
         *
+        * @param <T>       type of the instance class
         * @param clazz     the class.
         * @param params    an array containing the parameters of the 
constructor.
         * @param signature an array containing the signature of the 
constructor.
         * @return the instance.
         * @throws PoolException if recycling fails.
         */
-       public Object getInstance(Class clazz, Object params[], String 
signature[]) throws PoolException;
+       public <T> T getInstance(Class<?> clazz, Object params[], String 
signature[]) throws PoolException;
 
        /**
         * Puts a used object back to the pool. Objects implementing the 
Recyclable

Reply via email to