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 DC8B97EB7 for ; Sun, 4 Sep 2011 17:02:30 +0000 (UTC) Received: (qmail 21760 invoked by uid 500); 4 Sep 2011 17:02:29 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 21633 invoked by uid 500); 4 Sep 2011 17:02:28 -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 21626 invoked by uid 99); 4 Sep 2011 17:02:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Sep 2011 17:02:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Sep 2011 17:02:26 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E06A32388A33 for ; Sun, 4 Sep 2011 17:02:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1165075 - in /commons/proper/chain/branches/version-2.0-work/src: main/java/org/apache/commons/chain/Context.java main/java/org/apache/commons/chain/impl/ContextBase.java test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java Date: Sun, 04 Sep 2011 17:02:05 -0000 To: commits@commons.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110904170205.E06A32388A33@eris.apache.org> Author: simonetripodi Date: Sun Sep 4 17:02:05 2011 New Revision: 1165075 URL: http://svn.apache.org/viewvc?rev=1165075&view=rev Log: [CHAIN-56] clever Context with generic type auto-cast feature Modified: commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/Context.java commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ContextBase.java commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java Modified: commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/Context.java URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/Context.java?rev=1165075&r1=1165074&r2=1165075&view=diff ============================================================================== --- commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/Context.java (original) +++ commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/Context.java Sun Sep 4 17:02:05 2011 @@ -62,5 +62,19 @@ import java.util.Map; public interface Context extends Map { + /** + * That method enhances the {@link #get(Object)} method that helps users + * avoid the redundant code of type cast/checking when assignments are already known. + * + * It throws {@code ClassCastException} if types are not assignable. + * + * @param the target assignment type + * @param key the key whose associated value is to be returned + * @return the value to which the specified key is mapped, + * or {@code null} if this map contains no mapping for the key + * @see #get(Object) + * @since 2.0 + */ + T retrieve(String key); } Modified: commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ContextBase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ContextBase.java?rev=1165075&r1=1165074&r2=1165075&view=diff ============================================================================== --- commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ContextBase.java (original) +++ commons/proper/chain/branches/version-2.0-work/src/main/java/org/apache/commons/chain/impl/ContextBase.java Sun Sep 4 17:02:05 2011 @@ -351,6 +351,20 @@ public class ContextBase extends Concurr /** + * {@inheritDoc} + */ + public T retrieve(String key) { + Object valueObject = get(key); + if (valueObject == null) { + return null; + } + @SuppressWarnings("unchecked") // will throw ClassCastException if type are not assignable + T value = (T) valueObject; + return value; + } + + + /** *

Override the default Map behavior to call the * put() method individually for each key-value pair * in the specified Map.

Modified: commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java?rev=1165075&r1=1165074&r2=1165075&view=diff ============================================================================== --- commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java (original) +++ commons/proper/chain/branches/version-2.0-work/src/test/java/org/apache/commons/chain/generic/DispatchCommandTestCase.java Sun Sep 4 17:02:05 2011 @@ -137,6 +137,10 @@ public class DispatchCommandTestCase ext return this.wrappedContext.get(o); } + public T retrieve(String key) { + return wrappedContext.retrieve(key); + } + @Override public Object put(String key, Object value) { return this.wrappedContext.put(key, value);