Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Re: GEF: Using List<?> or Vector<?>

gef
Discussion topic

Back to topic list

Re: GEF: Using List&lt;?&gt; or Vector&lt;?&gt;

Reply

Author dthompson
Full name Dave Thompson
Date 2008-11-28 12:00:44 PST
Message Christian López Espínola wrote:
> Added Bob to CC
>
> On Fri, Nov 28, 2008 at 5:57 PM, Dave Thompson <argouml at davet dot org> wrote:
>
>> Christian López Espínola wrote:
>>
>>> On Fri, Nov 28, 2008 at 5:22 PM, Dave Thompson <argouml at davet dot org> wrote:
>>>
>>>
>>>> I originally tried List<FigModifyingMode>, but it gave me the error:
>>>>
>>>> The type List is not generic; it cannot be parameterized with arguments
>>>>
>>>>
>>>>
>>> <FigModifyingMode>In GEF we often see a bad pattern:
>>>
>>> import some.package.*;
>>>
>>> The problem is that the compiler thinks that List is java.awt.List.
>>> If we fix the imports by importing only the needed classes, or
>>> specifically say java.util.List, the problem is solved.
>>>
>>>
>> Hi Christian,
>>
>> You are right - thanks! When I do this though, I get compile errors because
>> List.lastElement() is not a valid method.
>> I think we'd have to change:
>>
>> _modes.lastElement();
>>
>> to something like:
>>
>> _modes.get(_modes.size()-1);
>>
>
> This would be OK if we assert that the size is > 0
>
>
>
>> Is this ok to do?
>>
>> Also, is a Vector used for some reason here, e.g. to maintain tighter
>> control over the order with it being a stack? Or is it something to do with
>> it being serializable?
>>
>> I also notice that there is a subclass of Vector called Stack, which might
>> be even more appropriate than Vector in this instance.
>> http://java.sun.com/​javase/6/docs/api/ja​va/util/Stack.html
>>
>
> And even more appropiate would be a Deque, that is recommended in
> Stack javadoc page.
> BTW, this would be a major change. We should be very careful before
> doing these kind of changes, but go ahead!
>
> I'd recommend starting writing some unit tests while refactoring GEF.
>
>
>
>> Regards,
>>
>> Dave
>>
>>
I seem to have got stuck with this. There is no clone() or equivalent
method for List, so I've ended up with code that seems unnecessarily
complex.

List<FigModifyingMode> modes = new ArrayList<FigModi​fyingMode>(_modes​).

Also, when I change the internal type of _modes from Vector to
List<FigModifyingMode>, I then have problems with ModeChangeEvent.java,
which wants a Vector for it's constructor. I think this means I need to
add a new constructor that accepts a List instead, and deprecate the
constructor that has a Vector as an argument, OR within
ModeManager.fireModeChanged() create a new Vector from the
List<FigModifyingMode>, and pass this.

The ModeChangeEvent, seems to apply to "Mode"s in the more general case,
rather than FigModifyingMode so I've tried to make it's constructor use
List<Mode>, which, Mode being a superclass of FigModifyingMode, I
thought would be accepted. Not so it seems, and my code doesn't compile.

I've not committed these changes because I'm not comfortable with them;
I've attached a patch instead. I feel like I'm just stirring things up,
without improving anything, and probably proving that I don't fully
understand the depths of generics. Specifically, I am not sure if is a
good idea to move away from Vector if the replacement (I assume
ArrayList) doesn't have the methods we need, and increases the risk of
an ArrayIndexOutOfBoundsException. Can't we just update the API, i.e.
deprecate any accessors or constructors that use Vector, create
replacements that use List<?>, but internally keep using Vector? I
think I will put my work on this on hold until I understand the
refactoring process better. (After all, this is only a distraction from
my work on argouml issue 1048).

Regards, Dave

« Previous message in topic | 1 of 3 | Next message in topic »

Messages

Show all messages in topic

Re: GEF: Using List&lt;?&gt; or Vector&lt;?&gt; dthompson Dave Thompson 2008-11-28 12:00:44 PST
     Re: [gef-dev] Re: GEF: Using List&lt;?&gt; or Vector&lt;?&gt; bobtarling Bob Tarling 2008-11-28 12:22:19 PST
         Re: [gef-dev] Re: GEF: Using List&lt;?&gt; or Vector&lt;?&gt; dthompson Dave Thompson 2008-11-28 12:39:46 PST
Messages per page: