+1

-igor

On Tue, Apr 14, 2009 at 11:36 PM, Juergen Donnerstag
<[email protected]> wrote:
> I'll to suggest the following improvement (generics)
>
> Today:
> protected List<IBehavior> getBehvavior(Class<? extends IBehavior> type)
> Which leads to code like WindowClosedBehavior behavior =
> (WindowClosedBehavior)getBehaviors(WindowClosedBehavior.class).get(0);
> Though we provide the type as parameter, we still have to cast the return 
> value
>
> That can improved as follows
> protected <M extends IBehavior> List<M> getBehaviors(Class<M> type)
> which than allows for (no more extra casting)
> WindowClosedBehavior behavior = 
> getBehaviors(WindowClosedBehavior.class).get(0);
>
> Regarding the implemention nothing changes except for types
>       �...@suppresswarnings("unchecked")
>        protected <M extends IBehavior> List<M> getBehaviors(Class<M> type)
>        {
>                List<IBehavior> behaviors = getBehaviorsRawList();
>                if (behaviors == null)
>                {
>                        return Collections.emptyList();
>                }
>
>                List<M> subset = new ArrayList<M>(behaviors.size()); // avoid 
> growing
>                for (Iterator<IBehavior> i = behaviors.iterator(); 
> i.hasNext();)
>                {
>                        Object behavior = i.next();
>                        if (behavior != null && (type == null ||
> type.isAssignableFrom(behavior.getClass())))
>                        {
>                                subset.add((M)behavior);
>                        }
>                }
>                return Collections.unmodifiableList(subset);
>        }
>
> Making that change didn't require any other change to any other Wicket
> code incl tests
>
> Any objections?
>
> Juergen
>

Reply via email to