Fifth checkpoint

This commit is contained in:
Alexander Munch-Hansen 2019-10-14 13:41:58 +02:00
parent e040269cce
commit 5b8bb1168f
3 changed files with 37 additions and 2 deletions

11
Filter.rb Normal file
View File

@ -0,0 +1,11 @@
class Filter
attr_accessor :value
attr_accessor :comparator
def initialize(value, comp)
@value = value
@comparator = comp
end
end

8
functional_functions.rb Normal file
View File

@ -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

20
lol.rb
View File

@ -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