Created
October 28, 2013 17:19
-
-
Save wytten/7200849 to your computer and use it in GitHub Desktop.
Add a method to File class: A variation of eachLine that accepts a stopClosure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Add a method to File class: A variation of eachLine that accepts a stopClosure | |
| */ | |
| File.metaClass.eachLineBreak = { stopClosure, workClosure -> | |
| for (Iterator iter = delegate.iterator(); iter.hasNext();) { | |
| def value = iter.next() | |
| if (stopClosure.call(value)) { | |
| break | |
| } else { | |
| workClosure.call(value) | |
| } | |
| } | |
| } | |
| /* | |
| * STOP_CONDITION can be used to limit the processing for testing purposes | |
| */ | |
| //def STOP_CONDITION = { false } | |
| def STOP_CONDITION = { retriever.getQueryFoundCount() == 10000 } | |
| def count = 0 | |
| long start = System.currentTimeMillis() | |
| new File(FILENAME).eachLineBreak( STOP_CONDITION ) { | |
| count++ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment