History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-644
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Jeremy Rayner
Reporter: Jeremy Rayner
Votes: 4
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

New Groovy JDK methods - to improve consistency

Created: 04/Oct/04 04:13 PM   Updated: 14/Apr/08 01:23 AM
Component/s: groovy-jdk
Affects Version/s: 1.0-beta-7
Fix Version/s: 1.6

Time Tracking:
Not Specified

Environment: All


 Description  « Hide
From my August 2004 email:

I've been having a quick look at the Groovy JDK, i.e. DefaultGroovyMethods
and DefaultGroovyStaticMethods

As there are so many methods in these classes, it can be a little hard to
take in all at once. So I've knocked up a quick script (in groovy),
that collates
the methods against the objects to which they become attached.

hacky script -> http://javanicus.com/groovy/MungGroovySourceCode.groovy

The result is a pretty table, with the methods down the left hand side,
and the Classes to which they are attached along the top. Where a method
has been implemented, at the crossover, I have placed a small graphic,
which if you hover your cursor over, will give you a bit more detail
about the method.

http://javanicus.com/groovy/GroovyJDKCrossReference.html

I've had a quick look for methods that I thought would be defined and
from my quick inspection of abs() thru to leftShift() so far, I believe
that the following candidates are available
(this is by no means an exhaustive list...)

  • Some possible missing (non static) methods

Collection.asImmutable()
Object.asImmutable()
Object.asSynchronized()
Set.count()
Byte[].eachByte()
File.filterLine()
InputStream.filterLine()
List.findIndexOf()
Collection.flatten()
Date.getAt() // to get the year etc... (In conjunction with a Calendar?)
Reader.getText()
Collection.intersect()
BufferedWriter <<
Object[] <<
CharSequence <<
File <<
Map << // another Map
Process << // to the process.out
Socket << // to the socket.out
Object[].max()
Object[].min()
Collection.minus()
Map.minus() // could compare RHS with key || value
Object[].minus()

URL.newInputStream()
URL.newReader()
CharSequence.padLeft()
CharSequence.padRight()
Object[].pop()

CharSequence.putAt()
Collection.putAt() // !always ordered, but we have
Collection.getAt()
Date.putAt() // e.g. easy acces to day component of date
Matcher.putAt()
InputStream.readBytes()

URL.readBytes()
URL.readLines()
CharSequence.reverse()
Object[].reverse()
SortedMap.reverse()

SortedSet.reverse()
Collection.reverseEach() // like Collection.each() this could be indeterminate...
Map.reverseEach() // we have Map.each()...
Matcher.reverseEach()
Object.reverseEach()

Object[].reverseEach() // perhaps foo.reverseEach() should be foo.reverse().each()
Object.rightShift() // so you can do things like... foo >> log
Object[].sort()
InputStream.splitEachLine()

URL.splitEachLine()
OutputStream.withWriterAppend()
BufferedWriter.write()
OutputStream.write()
File.writeLine()
OutputStream.writeLine()

  • and I'm not quite sure what the difference between append() and << is
    supposed to be, perhaps File.append() will become File <<
  • As we have eachByte(), would it not be a good idea to also have eachCharacter() for the Readers...

thanks

Jeremy.

P.S. This is based entirely on existing methods and existing Owner Objects,
would be nice to think of what other Objects and methods we could include,
(current owner objects come from java.lang., java.util.,
java.util.regex., java.io. and java.net.*)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King - 03/Mar/07 12:16 AM
Script needs updating to 1.0, I think there was one def I needed to add and a handful of '|' to '->' closure symbols to change.

Paul King - 03/Mar/07 12:18 AM
flatten() and minus() have been added for Set

Paul King - 22/Feb/08 11:42 PM
crossed off ones that are added up to 1.5.4

Paul King - 17/Mar/08 05:05 PM
added URL.newReader()

Alexandru Popescu - 17/Mar/08 09:18 PM
Probably this has been discussed in the past, but I've been starting to wonder if it wouldn't make sense to split the DefaultGroovy(Static)Methods into multiple smaller units. To me the DefaultGroovy(Static)Methods look like default wired categories, and I think it may help to have smaller, fine grained units for this. What do you think?

./alex

.w( the_mindstorm )p.


Paul King - 21/Mar/08 04:49 AM
include minus() for Object[]

Paul King - 14/Apr/08 01:23 AM
Round out eachLine() and splitEachLine() variations plus add lines() for String and File.