From 5b8bb1168f1d4502624ca3dbaf94bd75081fce52 Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Mon, 14 Oct 2019 13:41:58 +0200 Subject: [PATCH] Fifth checkpoint --- Filter.rb | 11 +++++++++++ functional_functions.rb | 8 ++++++++ lol.rb | 20 ++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 Filter.rb create mode 100644 functional_functions.rb diff --git a/Filter.rb b/Filter.rb new file mode 100644 index 0000000..1164bbd --- /dev/null +++ b/Filter.rb @@ -0,0 +1,11 @@ +class Filter + attr_accessor :value + attr_accessor :comparator + + def initialize(value, comp) + @value = value + @comparator = comp + end + +end + diff --git a/functional_functions.rb b/functional_functions.rb new file mode 100644 index 0000000..9994488 --- /dev/null +++ b/functional_functions.rb @@ -0,0 +1,8 @@ +def func_find_all(container_obj, attribute, filter_by) + filters = filter_by.map do |x| + "s.get#{attribute}() #{x.comparator} #{x.value}" + end + # TODO: Consider also having an "or" here + "return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).collect(Collectors.toList());" + +end diff --git a/lol.rb b/lol.rb index 0320305..f6be68b 100644 --- a/lol.rb +++ b/lol.rb @@ -1,6 +1,8 @@ require_relative 'find_algos' require_relative 'sorting_algos' require_relative 'Type' +require_relative 'functional_functions' +require_relative 'Filter' @@ -123,7 +125,7 @@ def construct_driver(class_name, parameters, methods, container_class, container lol.add#{class_name}(tmp5); System.out.println(\"\"); System.out.println(\"Some checkpoint\"); - #{maggie.join "\n System.out.println(\"Some Checkpoint\"); \n"} + #{maggie.join "\n\n System.out.println(\"Some Checkpoint\"); \n\n"} } @@ -227,6 +229,19 @@ container_methods = [ :name => "Name" }], :method_type => find_best_with_extra_parameter("ferries", "Length", " > ", "#{name}", "Name", ".equals", "Name", "int") + }, + { + :return_type => "List<#{name}>", + :name => "findFerries", + :params => [{ + :type => "int", + :name => "min", + }, + { + :type => "int", + :name => "max" + }], + :method_type => func_find_all("ferries", "Width", [Filter.new("min", ">="), Filter.new("max", "<=")]) } ] @@ -243,7 +258,8 @@ another_another_file.close another_file = File.open("TestDriver.java", "w") another_file.puts(construct_driver name, params, [{:name => "smallFerries", :parameters => [{:type => "int"}], :print => true}, {:name => "longFerry", :parameters => [{:type => "String"}], :print => true}, - {:name => "printHarbour", :parameters => [], :print => false}], "Harbour", [{:type => "String"}]) + {:name => "printHarbour", :parameters => [], :print => false}, + {:name => "findFerries", :parameters => [{:type => "int"}, {:type => "int"}], :print => true }], "Harbour", [{:type => "String"}]) another_file.close