commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1102070 - /commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/Digester.java
Date Wed, 11 May 2011 20:26:04 GMT
Author: simonetripodi
Date: Wed May 11 20:26:04 2011
New Revision: 1102070

URL: http://svn.apache.org/viewvc?rev=1102070&view=rev
Log:
Digester stack APIs now use Generics

Modified:
    commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/Digester.java

Modified: commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/Digester.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/Digester.java?rev=1102070&r1=1102069&r2=1102070&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/Digester.java
(original)
+++ commons/sandbox/digester3/trunk/src/main/java/org/apache/commons/digester3/Digester.java
Wed May 11 20:26:04 2011
@@ -2675,10 +2675,10 @@ public class Digester extends DefaultHan
      * Return the top object on the stack without removing it.  If there are
      * no objects on the stack, return <code>null</code>.
      */
-    public Object peek() {
+    public <T> T peek() {
 
         try {
-            return (stack.peek());
+            return this.<T>npeSafeCast(stack.peek());
         } catch (EmptyStackException e) {
             log.warn("Empty stack (returning null)");
             return (null);
@@ -2695,7 +2695,7 @@ public class Digester extends DefaultHan
      * @param n Index of the desired element, where 0 is the top of the stack,
      *  1 is the next element down, and so on.
      */
-    public Object peek(int n) {
+    public <T> T peek(int n) {
 
         int index = (stack.size() - 1) - n;
         if (index < 0) {
@@ -2703,7 +2703,7 @@ public class Digester extends DefaultHan
             return (null);
         }
         try {
-            return (stack.get(index));
+            return this.<T>npeSafeCast(stack.get(index));
         } catch (EmptyStackException e) {
             log.warn("Empty stack (returning null)");
             return (null);
@@ -2716,10 +2716,10 @@ public class Digester extends DefaultHan
      * Pop the top object off of the stack, and return it.  If there are
      * no objects on the stack, return <code>null</code>.
      */
-    public Object pop() {
+    public <T> T pop() {
 
         try {
-            Object popped = stack.pop();
+            T popped = this.<T>npeSafeCast(stack.pop());
             if (stackAction != null) {
                 popped = stackAction.onPop(this, null, popped);
             }
@@ -2737,7 +2737,7 @@ public class Digester extends DefaultHan
      *
      * @param object The new object
      */
-    public void push(Object object) {
+    public  <T>void push(T object) {
 
         if (stackAction != null) {
             object = stackAction.onPush(this, null, object);
@@ -2758,7 +2758,7 @@ public class Digester extends DefaultHan
      *
      * @since 1.6
      */
-    public void push(String stackName, Object value) {
+    public <T> void push(String stackName, T value) {
         if (stackAction != null) {
             value = stackAction.onPush(this, stackName, value);
         }
@@ -2784,8 +2784,8 @@ public class Digester extends DefaultHan
      *
      * @since 1.6
      */
-    public Object pop(String stackName) {
-        Object result = null;
+    public <T> T pop(String stackName) {
+        T result = null;
         Stack<Object> namedStack = stacksByName.get(stackName);
         if (namedStack == null) {
             if (log.isDebugEnabled()) {
@@ -2794,7 +2794,7 @@ public class Digester extends DefaultHan
             throw new EmptyStackException();
         }
         
-        result = namedStack.pop();
+        result = this.<T>npeSafeCast(namedStack.pop());
         
         if (stackAction != null) {
             result = stackAction.onPop(this, stackName, result);
@@ -2817,8 +2817,8 @@ public class Digester extends DefaultHan
      *
      * @since 1.6
      */
-    public Object peek(String stackName) {
-        return peek(stackName, 0);
+    public <T> T peek(String stackName) {
+        return this.<T>npeSafeCast(peek(stackName, 0));
     }
 
     /**
@@ -2836,8 +2836,8 @@ public class Digester extends DefaultHan
      *
      * @since 1.6
      */
-    public Object peek(String stackName, int n) {
-        Object result = null;
+    public <T> T peek(String stackName, int n) {
+        T result = null;
         Stack<Object> namedStack = stacksByName.get(stackName);
         if (namedStack == null ) {
             if (log.isDebugEnabled()) {
@@ -2850,7 +2850,7 @@ public class Digester extends DefaultHan
         if (index < 0) {
             throw new EmptyStackException();
         }
-        result = namedStack.get(index);
+        result = this.<T>npeSafeCast(namedStack.get(index));
 
         return result;
     }



Mime
View raw message