Function to remove specific lines from a file (and return an ArrayList)
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 13
- Forks
- 11
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 6
Description
In combination with listToMD5(), I wrote a Groovy utils function to remove specific lines from a file and return an ArrayList:
// Function to filter certain lines from a file and return an ArrayList
// Remember that the index starts at 0 in Groovy
public static ArrayList excludeLines(String inFilePath, linesToExclude) {
def inputLines = new File(inFilePath).readLines()
if (linesToExclude.size() >= 0){
Set<Integer> setOfLines = (0..inputLines.size()-1) as Set
def newSetOfLines = setOfLines.minus(linesToExclude)
return inputLines.getAt(newSetOfLines)
}
else {
return inputLines
}
}
Test usage:
{ assert listToMD5(UTILS.excludeLines("$outputDir/foo.txt", [1,3,7,8,9,11,12,13,14,15,20,21])) == listToMD5(UTILS.excludeLines("some/other/local.txt", [1,3,7,8,9,11,12,13,14,15,20,21])) },
# or to compare
{ assert snapshot(
listToMD5(UTILS.excludeLines("$outputDir/foo.txt", [1,3,7,8,9,11,12,13,14,15,20,21]))
).match() }
The Groovy code could probably be improved, still, it might be useful this as an nft-utils function.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing nft-utils entry points, especially the UTILS function collection and listToMD5(). Add an excludeLines utility based on the described usage, returning the remaining file lines; verify the two example comparisons produce matching results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- testing-qa, tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100