📄 groovy-reference-card.tex
字号:
\methodDetail{ cltn. }{ sort}{([comparator]) * }{ sorts collection into a list, optionally using a {\em comparator\/}}\methodDetail{ cltn. }{ sort}{() \{closure\} * }{ sorts collection into a list using closure as comparator}\methodDetail{ }{ }{ }{ }\methodSummary{ cltn. }{ asImmutable}{() }{ create an immutable collection }\methodSummary{ cltn. }{ asSynchronized}{() }{ create a synchronized collection }\methodSummary{ list. }{ flatten}{() }{ flattens list }\methodDetail{ list. }{ intersect}{(cltn) }{ returns intersection of list and collection }\methodDetail{ cltn. }{ join}{(separator) * }{ concatenate all the elements of {\em cltn\/} into a string }\methodDetail{ list. }{ pop}{() * }{ remove and return last item from list }%todo: what happened to push() :-)\methodSummary{ cltn. }{ reverse}{() }{ reverses order of collection or string }\methodDetail{ map. }{ subMap}{(keys) }{ returns a map of the given keys }\methodSummary{ cltn. }{ toList}{() }{ turns any collection into a list }}\vskip 0.75 in\subsection{Strings}\methodDetailHeader{\methodDetail{ str }{ $++$}{ }{ increment the number at end of string}\methodDetail{ str }{ $--$}{ }{ reduce the number at end of string}\methodSummary{ str }{ $+$}{ obj }{ concatenate {\em str\/} and {\em obj\/} together}\methodDetail{ str }{ $-$}{ obj }{ remove the first {\em obj\/} from {\em str\/}}%\methodDetailHeader{ num }{ + str }{ concatenate str to the end of num }\methodSummary{ str }{ \textless\textless}{ value }{ }%\methodDetail{ strBuff }{ \textless\textless}{ value }{ }%center and centre :-) !!!!\methodDetail{ str. }{ padRight}{(size,[padding]) }{ left justifies string padded out to {\em size\/}} \methodDetail{ str. }{ center}{(size, [padding]) }{ centers a string padded out to {\em size\/}}% name change for padLeft?\methodDetail{ str. }{ padLeft}{(size,[padding]) }{ right justifies string padded out to {\em size\/}} \methodDetail{ str. }{ contains}{(str2) * }{ true if {\em str} contains {\em str2}}\methodDetail{ str. }{ eachMatch}{(regex) \{closure\} * }{ apply {\em closure\/} to each match of the specified {\em regex\/} }%leftshift\methodSummary{ str. }{ toCharacter}{() }{ }\methodSummary{ str. }{ toList}{() }{ }\methodSummary{ str. }{ toLong}{() }{ }\methodSummary{ str. }{ toURL}{() }{ }\methodSummary{ str. }{ tokenize}{([token]) * }{ }}\subsection{Input/output}%todo: unify method names{\scriptsize {\em Note: url in this sense {\em can\/} include urls, files, streams and readers\/}}\methodDetailHeader{\methodDetail{ dir. }{ eachFile}{() \{closure\} }{ apply {\em closure\/} to each file in {\em dir\/}}\methodDetail{ dir. }{ eachFileRecurse}{() \{closure\} }{ apply {\em closure\/} to each file in {\em dir\/} recursively}\methodDetail{ }{ }{ }{ }\methodSummary{ url. }{ eachByte}{() \{closure\} }{ apply {\em closure\/} to each byte in {\em file\/}}\methodDetail{ url. }{ eachLine}{() \{closure\} }{ apply {\em closure\/} to each line of input}%\methodDetail{ file. }{ newInputStream}{() }{ obtain Stream to read from {\em file\/}}%\methodDetail{ file. }{ newReader}{([charset]) }{ obtain Reader from {\em file}}\methodSummary{ file. }{ readBytes}{() }{ read bytes from {\em file\/}}\methodDetail{ in. }{ readLine}{() }{ read a single, whole line from {\em in\/}}\methodDetail{ file. }{ readLines}{() }{ obtain List of lines from {\em file}}\methodDetail{ url. }{ getText}{([charset]) }{ fetch all available text from resource }\methodDetail{ file. }{ splitEachLine}{(regEx) \{closure\} }{ read in each line of {\em file\/}, apply {\em closure\/} to data delimited by {\em regEx\/}}%\methodDetail{ file. }{ withInputStream}{() \{closure\} }{ apply {\em closure\/} to a new InputStream on {\em file\/}, then close}\methodDetail{ url. }{ withReader}{() \{closure\} }{ apply {\em closure\/} to {\em in\/}, then close {\em in\/}}%\methodDetail{ in. }{ withStream}{() \{closure\} }{ apply {\em closure\/} to {\em in\/}, then close {\em in\/}}\methodDetail{ }{ }{ }{ }\methodDetail{ out }{ \textless\textless}{ obj }{ append {\em obj\/} to stream, process or socket}\methodSummary{ file. }{ append}{(text, [charset]) }{ append {\em text\/} at end of {\em file\/} with {\em charset\/} encoding}%\methodSummary{ file. }{ asWritable}{([charset]) * }{ wrap {\em file\/} as Writable }\methodSummary{ bytes. }{ encodeBase64}{() }{ wraps {\em file\/} in Writable with contents encoded as Base64}\methodSummary{ str. }{ decodeBase64}{() }{ unwraps bytes from Base64 encoded {\em str\/}}\methodDetail{ in. }{ filterLine}{([out]) \{closure\} }{ read from {\em in\/} and write each line to {\em out\/} only if {\em closure\/}}%\methodDetail{ file. }{ newOutputStream}{() }{ obtain Stream to write to {\em file\/}}%\methodDetail{ file. }{ newPrintWriter}{([charset]) }{ obtain PrintWriter to {\em file\/}}%\methodDetail{ file. }{ newWriter}{([charset],[append]) }{ obtain Writer to {\em file\/}}% todo: transformChar(out) could be more in line with eachByte?\methodSummary{ in. }{ transformChar}{(out) \{closure\} }{ read {\em in\/} and apply {\em closure\/} to each character being written {\em out\/}} \methodDetail{ in. }{ transformLine}{(out) \{closure\} }{ read {\em in\/} and apply {\em closure\/} to each line being written {\em out\/}} \methodSummary{ file. }{ withOutputStream}{() \{closure\} }{ apply {\em closure\/} to a new OutputStream on {\em file\/}, then close}\methodSummary{ file. }{ withPrintWriter}{() \{closure\} }{ apply {\em closure\/} to a new PrintWriter on {\em file\/}, then close}\methodSummary{ out. }{ withStream}{() \{closure\} }{ apply {\em closure\/} to {\em out\/}, then close {\em out\/}}\methodSummary{ skt. }{ withStreams}{() \{closure\} }{ apply {\em closure\/} to [in,out], then close them}\methodSummary{ out. }{ withWriter}{([charset]) \{closure\} }{ apply {\em closure\/} to {\em out\/} using {\em charset\/}, then close {\em out\/}}\methodDetail{ file. }{ withWriterAppend}{(charset) \{closure\} }{ apply {\em closure\/} to a new appending Writer on {\em file\/}, then close}\methodSummary{ file. }{ write}{(text, [charset]) * }{ write {\em text\/} to {\em file\/} using {\em charset\/}}\methodSummary{ out. }{ writeLine}{(line) }{ write {\em line\/} and append a newline}}\subsection{Misc}\methodDetailHeader{\methodSummary{ date }{ $++$}{ }{ add one day to the date }\methodSummary{ date }{ $--$}{ }{ subtract one day from the date }\methodSummary{ date }{ $+$}{ days }{ add {\em days\/} to the date }\methodSummary{ date }{ $-$}{ days }{ subtract {\em days\/} from the date }\methodDetail{ obj. }{ dump}{() * }{ returns a detailed dump string of {\em obj\/}}\methodDetail{ obj. }{ inspect}{() * }{ returns the groovy expression used to create this instance of {\em obj}}\methodSummary{ obj. }{ invokeMethod}{(method, args) * }{ invokes {\em method\/} on {\em obj\/} }\methodSummary{ obj. }{ print}{(obj) * }{ print an object }\methodSummary{ obj. }{ print}{(out) * }{ print this object to {\em out} }\methodSummary{ obj. }{ println}{(object) * }{ print an object and then terminate line }\methodSummary{ obj. }{ println}{(out) * }{ print this object to {\em out} and then terminate line }\methodDetail{ num. }{ step}{(endNum, stepNum) \{closure\} }{ iterates {\em closure\/} starting at this number, stepping up to {\em endNum} }\methodDetail{ num. }{ times}{() \{closure\} * }{ iterates {\em closure\/} num times }%todo: upTo() instead of upto()\methodDetail{ num. }{ upto}{(endNum) \{closure\} }{ iterates {\em closure\/} starting at this number, up to {\em endNum} }\methodDetail{ obj. }{ use}{(categoryClass) \{closure\} * }{ attach {\em closure\/} to specified class }\methodDetail{ obj. }{ use}{(categoryClassList) \{closure\} * }{ attach {\em closure\/} to specified classes }\methodSummary{ ps. }{ waitForOrKill}{(milliSecs) }{ wait for process to finish, or stop after specified {\em milliSecs} }\methodSummary{ ps. }{ getText}{() }{ }%Static methods shown with \em\methodSummary{ Thd.}{ {\em start}}{() \{closure\} }{ }\methodSummary{ Thd.}{ {\em startDaemon}}{() \{closure\} }{ }\methodSummary{ Mtr.}{ {\em getLastMatcher}}{() }{ }}\section{Groovy Developers Kit}\subsection{Groovy SQL}%START% sql = Sql.newInstance(%END\methodSummaryHeader{%\methodSummary{ }{ newInstance}{(url,[props],[driver]) }\methodSummary{ }{ Sql}{(datasource\textbar connection\textbar sql)}{ }\methodSummary{ }{ newInstance}{(url,[user],[pass],[driver]) }{ }\methodSummary{ sql. }{ call}{(str,[params]) }{ }\methodSummary{ sql. }{ eachRow}{(str,[params]) \{closure\}}{ }\methodSummary{ sql. }{ execute}{(str,[params]) }{ }\methodSummary{ sql. }{ executeUpdate}{(str,[params]) }{ }\methodSummary{ sql. }{ close}{() }{ }}\section{Snippets}\begin{tabbing} jezjezjez \= jez-repeated-for-tab-settings-only \kill {\bf Builder}\>{\scriptsize Markup, Node, StreamingMarkup, DOM, }\\{\scriptsize Ant, JavaDoc, Swt, JFace, Swing}\\\verb+farm = new NodeBuilder().farm(){animal(type:'pig')}+\\{\bf GPath} \>{\scriptsize walks the tree}\\\verb+farm.animal.collect{it['@type']}.contains('pig')+\\\end{tabbing}%\section{Sample Groovy Builder}%{\scriptsize Builders are provided to construct these tree structures: {\em Markup, Node, StreamingMarkup, DOM, Ant, JavaDoc, Swt, JFace, Swing}}%\begin{verbatim}%builder = new NodeBuilder()%%farm = builder.farm(type:'livestock', acres:30) {% animal(type:'pig')% animal(type:'sheep')% tractor(wheelbase:90)%}%%assert farm.animal.collect{it['@type']}.contains('pig')%%\end{verbatim}\section{Sample Groovy code}\begin{verbatim}package com.exampleimport org.example.Cow/** * This is a sample of Groovy */class HighlandCow extends Cow { void mooAtPeople() { sql = Sql.newInstance("jdbc:foo:bar") sql.eachRow("select * from PERSON") { println("Och-Aye ${it.firstname}") } }} \end{verbatim}\section{Tools}\subsection{Ant task}\begin{verbatim}<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="my.classpath"/><groovyc destdir="${build.classes.dir}" srcdir="${src.dir}" listfiles="true"> <classpath refid="my.classpath"/></groovyc>\end{verbatim}\subsection{Command Line Tools} \toolDetailHeader{\toolDetail{ \textgreater }{ groovy }{ [options] cheese.groovy [args] }{ interpret and execute specified groovy script }\toolDetail{ \textgreater }{ groovyc }{ [options] cheese.groovy }{ compiles specified groovy script }\toolDetail{ \textgreater }{ groovysh }{ }{ begins an interactive groovy session }\toolDetail{ \textgreater }{ groovyConsole }{ }{ begins a GUI based groovy session }%\toolDetail{ \textgreater }{ grok }{ }{ groovy javadoc }}\rule{0.3\linewidth}{0.25pt}\scriptsizeCopyright \copyright\ 2004 Jeremy Rayner\verb!$Revision: 1.6 $, $Date: 2005/09/05 18:12:51 $.!http://javanicus.com/\end{multicols}\end{document}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -