Wednesday, March 2, 2011

jython + Google Guava's base.CaseFormat

I was trying to research Google Collections for use in jython and stumbled upon Solid Craft's blog and his description of Guava base's CaseFormat utility.  Where I work we're a Java shop, and use of camelCase infiltrates all code, even jython code.  CaseFormat provides functionality for changing these variable names to a number of different formats.

$ /usr/local/jdk-1.7.0/bin/java -jar jython.jar
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.7.0-internal
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> # get downloaded jar into sys.path
>>> sys.path.append('/home/carl/Downloads/guava-r08/guava-r08.jar')
>>> from import CaseFormat as cf
>>> dir(cf)
>>> varname = 'someVariable'
>>>, varname)
>>>, varname)
>>>, varname)

For cycling through a file full of camel case or underscored variable names, even by hand in the interpreter, this could save some time and typing.

No comments:

Post a Comment