- While I agree that being able to sort objects is
important, I'd rather
see this in a patched version of the $sorttool instead of a separate
component; I've checked it and we'd just have to change the way
getComparable works. Doing this means that we're going to reuse a tool
that we're already supposed to be using for general sorting, and we'd
get as benefits the ability to specify a sort direction, and the ability
to mix properties and other object metadata, like owner document or
object number.
I agree that the functionality in ObjectSort should go into $sorttool, but
I have no influence over the development of XWiki, so I advertised it as a
contrib project.
What is getComparable by the way?
- Even as it is right now, I don't like that the
script service only has
a getInstance method and then exposes the internal object.
I thought that if I put just getInstance in the script service, I could
reduce redundancy in the code.
But I'm only a starting programmer. There are certainly better designs than
mine.
- I don't think that both sort and sortCopy are
needed. Only the method
that sorts a copy and returns it should be available.
If only the method that sort a copy and returns it is available, there can
be increased memory usage, so I introduced an in-place sort method, too.
Why do you think an in-place sort method should not be available?
- sortCopyByProps should also be called just sort,
since the type of
parameters passed will be enough for the right method to be called
(polymorphism). And I'm actually wondering if we need both methods or
not, since sorting by just one property could be done by passing a list
with just one member.
You're right. I thought
$services.objectsort.getInstance().sortByProps($doc.getObjects("Class"),
["port", "day:asc", "hour:desc"]) was possible but
$services.objectsort.getInstance().sortByProps($doc.getObjects("Class"),
"port") wasn't possible because I thought String couldn't be cast to
List<String>.
However,
$services.objectsort.getInstance().sortByProps($doc.getObjects("Class"),
"port") just worked out of box.
I'll remove sort and sortCopy and rename sortByProps and sortCopyByProps to
sort and sortByProps, respectively.