From e72634637c39e43348b74970764ef61cca6d6acf Mon Sep 17 00:00:00 2001 From: Magdalena Kalin Date: Wed, 23 Oct 2019 13:14:21 +0200 Subject: [PATCH] Another maggie method --- functional_functions.rb | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/functional_functions.rb b/functional_functions.rb index aec2faa..014cf02 100644 --- a/functional_functions.rb +++ b/functional_functions.rb @@ -1,54 +1,43 @@ -def func_find_all(container_obj, attribute, filter_by) +def annoyed_maggie(attribute, filter_by) filters = filter_by.map do |x| comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}" "s.get#{attribute}()#{comparator}" end +end + +def func_find_all(container_obj, attribute, filter_by) + annoyed_maggie(attribute, filter_by) # TODO: Consider also having an "or" here "return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).collect(Collectors.toList());" end def find_whatever_of_something(container_obj, attribute, filter_by, aggregate_func) - filters = filter_by.map do |x| - comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}" - "s.get#{attribute}()#{comparator}" - end + annoyed_maggie(attribute, filter_by) # TODO: Consider also having an "or" here "return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).#{aggregate_func}();" end def find_whatever_of_variable(container_obj, attribute, filter_by, aggregate_func, variable) - filters = filter_by.map do |x| - comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}" - "s.get#{attribute}()#{comparator}" - end + annoyed_maggie(attribute, filter_by) # TODO: Consider also having an "or" here "return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).mapToInt(s -> s.get#{variable}()).#{aggregate_func}();" end def find_one(container_obj, attribute, filter_by) - filters = filter_by.map do |x| - comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}" - "s.get#{attribute}()#{comparator}" - end + annoyed_maggie(attribute, filter_by) # 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) - filters = filter_by.map do |x| - comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}" - "s.get#{attribute}()#{comparator}" - end + annoyed_maggie(attribute, filter_by) # 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) - filters = filter_by.map do |x| - comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}" - "s.get#{attribute}()#{comparator}" - end + annoyed_maggie(attribute, filter_by) # 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