2019-10-23 11:14:21 +00:00
|
|
|
def annoyed_maggie(attribute, filter_by)
|
2019-10-14 11:41:58 +00:00
|
|
|
filters = filter_by.map do |x|
|
2019-10-17 09:48:54 +00:00
|
|
|
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
|
|
|
"s.get#{attribute}()#{comparator}"
|
2019-10-14 11:41:58 +00:00
|
|
|
end
|
2019-10-23 11:14:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def func_find_all(container_obj, attribute, filter_by)
|
|
|
|
annoyed_maggie(attribute, filter_by)
|
2019-10-14 11:41:58 +00:00
|
|
|
# TODO: Consider also having an "or" here
|
|
|
|
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).collect(Collectors.toList());"
|
|
|
|
|
|
|
|
end
|
2019-10-14 12:08:25 +00:00
|
|
|
|
|
|
|
def find_whatever_of_something(container_obj, attribute, filter_by, aggregate_func)
|
2019-10-23 11:14:21 +00:00
|
|
|
annoyed_maggie(attribute, filter_by)
|
2019-10-14 12:08:25 +00:00
|
|
|
# TODO: Consider also having an "or" here
|
|
|
|
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).#{aggregate_func}();"
|
2019-10-14 12:38:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_whatever_of_variable(container_obj, attribute, filter_by, aggregate_func, variable)
|
2019-10-23 11:14:21 +00:00
|
|
|
annoyed_maggie(attribute, filter_by)
|
2019-10-14 12:38:22 +00:00
|
|
|
# TODO: Consider also having an "or" here
|
|
|
|
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).mapToInt(s -> s.get#{variable}()).#{aggregate_func}();"
|
2019-10-14 12:08:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_one(container_obj, attribute, filter_by)
|
2019-10-23 11:14:21 +00:00
|
|
|
annoyed_maggie(attribute, filter_by)
|
2019-10-14 12:08:25 +00:00
|
|
|
# TODO: Consider also having an "or" here
|
|
|
|
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).findAny().orElse(null);"
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_best_value(container_obj, attribute, filter_by, min_or_max, based_on)
|
2019-10-23 11:14:21 +00:00
|
|
|
annoyed_maggie(attribute, filter_by)
|
2019-10-14 12:08:25 +00:00
|
|
|
# TODO: Consider also having an "or" here
|
|
|
|
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).mapToInt(s -> s.get#{based_on}()).#{min_or_max};"
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_best_object(container_obj, attribute, filter_by, min_or_max, based_on)
|
2019-10-23 11:14:21 +00:00
|
|
|
annoyed_maggie(attribute, filter_by)
|
2019-10-14 12:08:25 +00:00
|
|
|
# TODO: Consider also having an "or" here
|
|
|
|
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).#{min_or_max}(Comparator.comparing(#{based_on.type}.get#{based_on.variable}()));"
|
|
|
|
end
|
|
|
|
|