You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Shinobu Kawai <sh...@gmail.com> on 2005/03/28 18:56:57 UTC
FYI: ListTool as a replacement for ArrayTool
Hi all,
I've put List support back to ArrayTool and renamed it "ListTool".
Anybody interested, please take a look here:
http://wiki.apache.org/jakarta-velocity/ListTool
New features:
- List support for all the existing methods. Cloning a List returns
an ArrayList with the same elements because I couldn't think of a way
to make a clone from an arbitrary List.
- size() method. Does the same thing as the length() method.
- isList() method. Checks if the given argument is a List or not.
Any comments welcome. :)
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Shinobu Kawai <sh...@gmail.com>.
> agreed on all points. yet, i'll add this last thought... on these
> methods we're talking about throwing out, rather than just send them
> into ether, perhaps we can keep them around on the wiki here or
> somewhere in case someone does need/want them. then i'll just check
> in a trimmed-down version for now.
OK, cool. I'll get back when I'm done with the changes.
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Nathan Bubna <nb...@gmail.com>.
agreed on all points. yet, i'll add this last thought... on these
methods we're talking about throwing out, rather than just send them
into ether, perhaps we can keep them around on the wiki here or
somewhere in case someone does need/want them. then i'll just check
in a trimmed-down version for now.
On Mon, 28 Mar 2005 18:00:09 -0800, Shinobu Kawai
<sh...@gmail.com> wrote:
> Hi Nathan,
>
> > > clone() isn't public in List, so I guess I'll need to skip the first
> > > step.
> >
> > oh yeah. hmm. so why are we putting it in this tool by default? is
> > this something you are (or someone else is) using (or has requested)?
> > if not, then i think we shouldn't be trying to implement it yet.
> > YAGNI, ya know?
>
> Let's see, I know it wasn't in the original version...
> This method was originally in the PublicFieldUberspect. I moved it
> here with the length method to put all the array stuff in ArrayTool.
> (Did you know you can't call array.clone() inside VTL?) Anyways, I
> haven't heard of anyone actually using/needing it, so I guess I can
> throw it away for now. YAGNI.
>
> > > Which brings up another question: Do we want support for other List
> > > methods, like contains() and isEmpty()? (These two are the only ones
> > > I've ever called from a template.)
> >
> > good question. and i think the answer is yes. i don't use contains()
> > much, but i do use $list.isEmpty() a lot. if we're gonna offer this
> > as (among other things) a way to hide the difference between arrays
> > and lists in a template, then we should probably support these.
>
> Okay, I'll put them in. Other methods available upon request. ;)
>
> > > Arrays.asList() only works for Object arrays. We might be getting
> > > primitive arrays as well. I used to have a whole bunch of
> > > instanceof's.
> >
> > ah. yeah, that makes sense. i figured i was missing something. my
> > only question, then, is should we have this return fixed-size lists
> > like Arrays.asList() does? honest question. my first instinct is to
> > say that it should, but i'm really not sure if that's important (or
> > even just worth the effort) here.
>
> I also wonder if anybody wants this method. I was only using it
> internally at first. Now, I'm not using it anywhere. YAGNI applies
> here, too.
>
> Best regards,
> -- Shinobu
>
> --
> Shinobu Kawai <sh...@gmail.com>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Nathan,
> > clone() isn't public in List, so I guess I'll need to skip the first
> > step.
>
> oh yeah. hmm. so why are we putting it in this tool by default? is
> this something you are (or someone else is) using (or has requested)?
> if not, then i think we shouldn't be trying to implement it yet.
> YAGNI, ya know?
Let's see, I know it wasn't in the original version...
This method was originally in the PublicFieldUberspect. I moved it
here with the length method to put all the array stuff in ArrayTool.
(Did you know you can't call array.clone() inside VTL?) Anyways, I
haven't heard of anyone actually using/needing it, so I guess I can
throw it away for now. YAGNI.
> > Which brings up another question: Do we want support for other List
> > methods, like contains() and isEmpty()? (These two are the only ones
> > I've ever called from a template.)
>
> good question. and i think the answer is yes. i don't use contains()
> much, but i do use $list.isEmpty() a lot. if we're gonna offer this
> as (among other things) a way to hide the difference between arrays
> and lists in a template, then we should probably support these.
Okay, I'll put them in. Other methods available upon request. ;)
> > Arrays.asList() only works for Object arrays. We might be getting
> > primitive arrays as well. I used to have a whole bunch of
> > instanceof's.
>
> ah. yeah, that makes sense. i figured i was missing something. my
> only question, then, is should we have this return fixed-size lists
> like Arrays.asList() does? honest question. my first instinct is to
> say that it should, but i'm really not sure if that's important (or
> even just worth the effort) here.
I also wonder if anybody wants this method. I was only using it
internally at first. Now, I'm not using it anywhere. YAGNI applies
here, too.
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Nathan Bubna <nb...@gmail.com>.
On Mon, 28 Mar 2005 17:13:34 -0800, Shinobu Kawai
<sh...@gmail.com> wrote:
> Hi Nathan,
>
> > > - List support for all the existing methods. Cloning a List returns
> > > an ArrayList with the same elements because I couldn't think of a way
> > > to make a clone from an arbitrary List.
> >
> > if you want to really make a thorough attempt at a true clone, you
> > might follow the basic pattern that LinkTool.duplicate() does. (try
> > clone(), try to get a new instance of the same class, then give and
> > use a simple instance like ArrayList)
>
> clone() isn't public in List, so I guess I'll need to skip the first
> step.
oh yeah. hmm. so why are we putting it in this tool by default? is
this something you are (or someone else is) using (or has requested)?
if not, then i think we shouldn't be trying to implement it yet.
YAGNI, ya know?
> Or should I just go ahead and use reflection? I really don't
> like reflection that much, because it makes everything so complicated.
> But I guess it's fine if it's hidden inside a tool.
yeah, reflection is pretty heavily used in Velocity; i don't think we
should be too afraid of it in tools. *if* we're gonna keep this
method, that is. :)
> > > - size() method. Does the same thing as the length() method.
> >
> > hmm. if we're generally trying to hide the difference between Lists
> > and arrays in templates, i think we should pick one of these and drop
> > the other. i'm thinking size() is the one to keep.
>
> Well, if _I_ were to keep only one, it would be size(), too.
>
> Which brings up another question: Do we want support for other List
> methods, like contains() and isEmpty()? (These two are the only ones
> I've ever called from a template.)
good question. and i think the answer is yes. i don't use contains()
much, but i do use $list.isEmpty() a lot. if we're gonna offer this
as (among other things) a way to hide the difference between arrays
and lists in a template, then we should probably support these.
> > i would prefer to see the list(obj) and array(obj) methods follow the
> > pattern of type-conversion methods in the other tools and be called
> > toList() and toArray().
>
> That'll be easy. :)
>
> > also, out of curiousity, in your toList() method, why don't you just
> > use java.util.Arrays.asList()? is Eric Fixler's refactoring superior
> > for some reason?
>
> Arrays.asList() only works for Object arrays. We might be getting
> primitive arrays as well. I used to have a whole bunch of
> instanceof's.
ah. yeah, that makes sense. i figured i was missing something. my
only question, then, is should we have this return fixed-size lists
like Arrays.asList() does? honest question. my first instinct is to
say that it should, but i'm really not sure if that's important (or
even just worth the effort) here.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Nathan,
> > - List support for all the existing methods. Cloning a List returns
> > an ArrayList with the same elements because I couldn't think of a way
> > to make a clone from an arbitrary List.
>
> if you want to really make a thorough attempt at a true clone, you
> might follow the basic pattern that LinkTool.duplicate() does. (try
> clone(), try to get a new instance of the same class, then give and
> use a simple instance like ArrayList)
clone() isn't public in List, so I guess I'll need to skip the first
step. Or should I just go ahead and use reflection? I really don't
like reflection that much, because it makes everything so complicated.
But I guess it's fine if it's hidden inside a tool.
> > - size() method. Does the same thing as the length() method.
>
> hmm. if we're generally trying to hide the difference between Lists
> and arrays in templates, i think we should pick one of these and drop
> the other. i'm thinking size() is the one to keep.
Well, if _I_ were to keep only one, it would be size(), too.
Which brings up another question: Do we want support for other List
methods, like contains() and isEmpty()? (These two are the only ones
I've ever called from a template.)
> i would prefer to see the list(obj) and array(obj) methods follow the
> pattern of type-conversion methods in the other tools and be called
> toList() and toArray().
That'll be easy. :)
> also, out of curiousity, in your toList() method, why don't you just
> use java.util.Arrays.asList()? is Eric Fixler's refactoring superior
> for some reason?
Arrays.asList() only works for Object arrays. We might be getting
primitive arrays as well. I used to have a whole bunch of
instanceof's.
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Nathan Bubna <nb...@gmail.com>.
On Mon, 28 Mar 2005 08:56:57 -0800, Shinobu Kawai
<sh...@gmail.com> wrote:
> Hi all,
>
> I've put List support back to ArrayTool and renamed it "ListTool".
>
> Anybody interested, please take a look here:
> http://wiki.apache.org/jakarta-velocity/ListTool
>
> New features:
> - List support for all the existing methods. Cloning a List returns
> an ArrayList with the same elements because I couldn't think of a way
> to make a clone from an arbitrary List.
if you want to really make a thorough attempt at a true clone, you
might follow the basic pattern that LinkTool.duplicate() does. (try
clone(), try to get a new instance of the same class, then give and
use a simple instance like ArrayList)
> - size() method. Does the same thing as the length() method.
hmm. if we're generally trying to hide the difference between Lists
and arrays in templates, i think we should pick one of these and drop
the other. i'm thinking size() is the one to keep.
> - isList() method. Checks if the given argument is a List or not.
ok, for those who really must know the difference in template, i
suppose this is fine.
> Any comments welcome. :)
i would prefer to see the list(obj) and array(obj) methods follow the
pattern of type-conversion methods in the other tools and be called
toList() and toArray().
also, out of curiousity, in your toList() method, why don't you just
use java.util.Arrays.asList()? is Eric Fixler's refactoring superior
for some reason?
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Shinobu Kawai <sh...@gmail.com>.
> Ok, now it's split to two: ListTool and ExtendedListTool.
> http://wiki.apache.org/jakarta-velocity/ListTool
>
> ListTool
> - get/set/size
> - isList/isArray
> - isEmpty
> - contains
>
> ExtendedListTool
Forgot to say, these features are available in addition to the
features of ListTool. :)
> - length
> - clone
> - toArray/toList
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Shinobu Kawai <sh...@gmail.com>.
Ok, now it's split to two: ListTool and ExtendedListTool.
http://wiki.apache.org/jakarta-velocity/ListTool
ListTool
- get/set/size
- isList/isArray
- isEmpty
- contains
ExtendedListTool
- length
- clone
- toArray/toList
Any comments welcome. :)
Best regards,
-- Shinobu
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Nathan Bubna <nb...@gmail.com>.
not a bad thought. but make sure you take a look at the SortTool
(only in VelocityTools 1.2-dev), before you get into this. we don't
want to duplicate effort needlessly.
On Tue, 29 Mar 2005 14:21:53 -0800, Eric Fixler <fi...@fixler.com> wrote:
> Hi Shinobu. I just wrote a plug in for Blojsom to use ArrayTool there
> (and now you have to go and change the name ;-)
>
> I was thinking about adding some sort of sort ability, essentially a
> passthrough to Arrays.sort()
>
> Any interest/ideas around this?
>
> thanks
> eric
>
>
> On Mar 28, 2005, at 8:56, Shinobu Kawai wrote:
>
> > Hi all,
> >
> > I've put List support back to ArrayTool and renamed it "ListTool".
> >
> > Anybody interested, please take a look here:
> > http://wiki.apache.org/jakarta-velocity/ListTool
> >
> >
> --------------------------------------------------------------
> Eric Fixler
> fix@fixler.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
Re: FYI: ListTool as a replacement for ArrayTool
Posted by Eric Fixler <fi...@fixler.com>.
Hi Shinobu. I just wrote a plug in for Blojsom to use ArrayTool there
(and now you have to go and change the name ;-)
I was thinking about adding some sort of sort ability, essentially a
passthrough to Arrays.sort()
Any interest/ideas around this?
thanks
eric
On Mar 28, 2005, at 8:56, Shinobu Kawai wrote:
> Hi all,
>
> I've put List support back to ArrayTool and renamed it "ListTool".
>
> Anybody interested, please take a look here:
> http://wiki.apache.org/jakarta-velocity/ListTool
>
>
--------------------------------------------------------------
Eric Fixler
fix@fixler.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org