Skip to content

Commit

Permalink
Allow to pass String to isExistsWhere and deleteWhere methods
Browse files Browse the repository at this point in the history
Add isExistsWithIndex as alias for isExists for index(es) input
  • Loading branch information
dolfinus committed Oct 12, 2019
1 parent f58d33e commit c3c49bc
Showing 1 changed file with 67 additions and 35 deletions.
102 changes: 67 additions & 35 deletions src/org/camunda/latera/bss/utils/CSV.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1059,21 +1059,16 @@ class CSV {
}

/**
Checks if line with index exist in CSV. Alias
<p>
Example:
<pre>
{@code
String data =
"""
a;b;c
1;2;3
"""
def csv = new CSV(data)
assert csv.isExist(0) // by index
assert !csv.isExist(1)
}</pre>
Checks if lines with indexes from list exist in CSV.
Alias for #isExists(List)
@see #isExists(List)
*/
Boolean isExistsWithIndex(List indexes) {
return isExists(indexes)
}

/**
Checks if line with index exist in CSV.
@param input Integer of line index to search
@returns True if there is any line in data which corresponds to condition, false otherwise.
@see #isExists(Map)
Expand All @@ -1082,6 +1077,15 @@ class CSV {
return isExists([index])
}

/**
Checks if line with index exist in CSV.
Alias for #isExists(Integer)
@see #isExists(Integer)
*/
Boolean isExistsWithIndex(Integer index) {
return isExists(index)
}

/**
Checks if some line or lines exist in CSV.
<p>
Expand Down Expand Up @@ -1131,29 +1135,30 @@ class CSV {
}

/**
Delete line or lines correspords to condition.
<p>
Example:
<pre>
{@code
String data =
"""
a;b;c
1;2;3
"""
def csv = new CSV(data)
csv.deleteLines(where: [a: 1]) // by column name and value
assert csv.dataMap == []
def csv = new CSV(data)
csv.deleteLines(where: [1]) // by line or its part
assert csv.dataMap == []
Checks if some line or lines exist in CSV.
@param input String line or its part
@returns True if there is any line in data which corresponds to condition, false otherwise.
*/
Boolean isExistsWhere(CharSequence where) {
return isExistsWhere(parseLine(where))
}

def csv = new CSV(data)
csv.deleteLines(indexes: [0]) // by index
assert csv.dataMap == []
}</pre>
/**
in operator overload. Checks if some line or lines exist in CSV.
@param input Map[String,Object] or List[Object] query format Integer line intex to search.
@returns True if there is any line with this value of column, false otherwise.
@see #isExists(Map)
@see #isExistsWhere(Map)
*/
Boolean isCase(def item) {
if (isMap(item) || isString(item)) {
return isExistsWhere(item)
}
return isExistsWithIndex(item)
}

/**
Delete line or lines correspords to condition.
@param input Map with 'where' query in Map[String,Object] or List[Object] format or 'indexes' in List[Integer] format to search.
@returns List[List] of data.
*/
Expand Down Expand Up @@ -1299,6 +1304,33 @@ class CSV {
return deleteLines(where: where)
}

/**
Delete line by full content or lines by some part.
@param input Map[String,Object] to search and delete.
@returns List[List] of data.
*/
List deleteLinesWhere(CharSequence where) {
return deleteLinesWhere(parseLine(where))
}

/**
- operator overload, Delete line or lines correspords to condition.
@param input Integer, List[Integer] or Map to search.
@see #deleteLines
*/
CSV minus(def item) {
if (isInteger(item)) {
deleteLinesByIndex(item)
} else if (isList(item)) {
deleteLinesByIndex(item)
} else if (isMap(item) || isString(item)) {
deleteLinesWhere(item)
}
deleteLinesByIndex([item])
return this
}

/**
Get String CSV interpretation.
<p>
Expand Down

0 comments on commit c3c49bc

Please sign in to comment.