intprog_hackery/lol.rb

232 lines
6.5 KiB
Ruby
Raw Normal View History

2019-10-13 12:08:50 +00:00
require_relative 'find_algos'
require_relative 'sorting_algos'
2019-10-14 10:54:53 +00:00
require_relative 'Type'
2019-10-14 11:41:58 +00:00
require_relative 'functional_functions'
require_relative 'Filter'
2019-10-21 18:16:37 +00:00
require_relative 'pdf-parser'
2019-10-14 10:54:53 +00:00
2019-10-13 12:08:50 +00:00
# Hi! Steffan was here...
2019-10-21 18:16:37 +00:00
prim_class, container, class_fields, container_params, container_methods_maggie = parse "ferry.pdf"
name = prim_class
container_class = container
2019-10-14 12:38:22 +00:00
container_obj = "ferries"
2019-10-17 09:03:11 +00:00
to_string_template = "0 1 x 2 meter"
sorting_one = Type.new("String", "Name")
sorting_two = Type.new("int", "Length")
sorting_three = Type.new("int", "Width")
2019-10-17 09:48:54 +00:00
sorting_two.comparator = "<"
sorting_three.comparator = "<"
2019-10-17 09:28:05 +00:00
sorting_filters = [sorting_one, sorting_two, sorting_three]
2019-10-14 10:54:53 +00:00
2019-10-21 18:16:37 +00:00
print(class_fields)
params = [*class_fields.map! {|x| {:type => x.split(" ")[0], :name => x.split(" ")[1].capitalize}}]
container_methods = [
*container_methods_maggie.map! {|x|
{
:return_type => x.type,
:name => x.name.start_with?("print") ? x.name + "pls" : x.name ,
:params => [*x.parameters.split(",").map! {|y|
{
:type => y.split(" ")[0].strip,
:name => y.split(" ")[1].strip
}
}],
:method_type => nil
}
}
]
container_methods[0][:method_type] = add_method(container_obj, "f")
container_methods[1][:method_type] = find_all(container_obj, "Length", "<", "#{name}", "maxLength")
container_methods[2][:method_type] = find_best_with_extra_parameter(container_obj, "Length", ">", "#{name}", "Name", ".equals", "Name", "int")
container_methods[4][:method_type] = func_find_all(container_obj, "Width", [Filter.new("min", ">="), Filter.new("max", "<=")])
container_methods[5][:method_type] = find_whatever_of_variable(container_obj, "Name", [Filter.new("Name", ".equals")], "sum", "Length")
container_params = [{:type => "String", :name => "Name"}]
container_fields = [ {:type => "ArrayList<#{name}>", :name => container_obj}]
driver_methods = [{:name => "smallFerries", :parameters => [{:type => "int"}], :print => true},
{:name => "longFerry", :parameters => [{:type => "String"}], :print => true},
{:name => "printHarbour", :parameters => [], :print => false},
{:name => "findFerries", :parameters => [{:type => "int"}, {:type => "int"}], :print => true },
{:name => "findLength", :parameters => [{:type => "String"}], :print => true}]
driver_params = [{:type => "String"}]
2019-10-17 09:03:11 +00:00
def construct_class(name_of_class, parameters, to_string_template, sorting_filters)
sorting_string = compare_to(sorting_filters)
2019-10-14 10:54:53 +00:00
2019-10-17 11:44:22 +00:00
fields = parameters.map do |x|
"\tprivate #{x[:type]} #{x[:name]};"
2019-10-13 12:08:50 +00:00
end
2019-10-17 09:28:05 +00:00
constructor_parameters = parameters.map { |x| "#{x[:type]} #{x[:name]}"}.join ","
2019-10-13 12:08:50 +00:00
2019-10-17 09:28:05 +00:00
getters = parameters.map do |x|
2019-10-17 11:44:22 +00:00
"\tpublic #{x[:type]} get#{x[:name]}(){
\t\treturn #{x[:name]};
\t}"
2019-10-17 09:28:05 +00:00
end.join "\n"
2019-10-13 12:08:50 +00:00
lol = parameters.map do |x|
2019-10-17 11:44:22 +00:00
"\t\tthis.#{x[:name]} = #{x[:name]};"
2019-10-13 12:08:50 +00:00
end
(0...parameters.length).each do |x|
2019-10-21 18:16:37 +00:00
to_string_template.sub! "#{x}", "\" + #{parameters[x][:name]} + \""
2019-10-13 12:08:50 +00:00
end
"
2019-10-17 11:44:22 +00:00
public class #{name_of_class} implements Comparable<#{name_of_class}> {
#{fields.join "\n"}
2019-10-13 12:08:50 +00:00
2019-10-17 11:44:22 +00:00
\tpublic #{name_of_class}(#{constructor_parameters}) {
#{lol.join("\n")}
\t}
2019-10-13 12:08:50 +00:00
2019-10-17 11:44:22 +00:00
#{getters}
2019-10-13 12:08:50 +00:00
2019-10-17 11:44:22 +00:00
\tpublic String toString() {
\t\treturn " + '"' + "#{to_string_template}" + '"' + ";
\t}
2019-10-13 12:08:50 +00:00
2019-10-17 11:44:22 +00:00
\tpublic int compareTo(#{name_of_class} other) {
#{sorting_string}
\t}
}"
2019-10-13 12:08:50 +00:00
end
def construct_driver(class_name, parameters, methods, container_class, container_params)
2019-10-17 11:44:22 +00:00
args = lambda {|parameters|
2019-10-17 09:34:45 +00:00
parameters.map do |x|
2019-10-13 12:08:50 +00:00
type = x[:type]
2019-10-17 09:34:45 +00:00
type == "int" ? "#{rand(max=100)}" : "\"#{(0...10).map { ('a'..'z').to_a[rand(26)] }.join}\""
end.join ","
2019-10-17 11:44:22 +00:00
}
2019-10-13 12:08:50 +00:00
maggie = methods.map do |x|
2019-10-14 10:54:53 +00:00
if x[:print]
2019-10-17 11:44:22 +00:00
"System.out.println(lol.#{x[:name]}(#{args.call x[:parameters]}));"
2019-10-14 10:54:53 +00:00
else
2019-10-17 11:44:22 +00:00
"lol.#{x[:name]}(#{args.call x[:parameters]});"
2019-10-14 10:54:53 +00:00
end
2019-10-13 12:08:50 +00:00
end
2019-10-17 11:44:22 +00:00
"public class TestDriver {
\tpublic TestDriver(){}
\tpublic static void test() {
\t\tvar tmp1 = new #{class_name}(#{args.call parameters});
\t\tvar tmp2 = new #{class_name}(#{args.call parameters});
\t\tvar tmp3 = new #{class_name}(#{args.call parameters});
\t\tvar tmp4 = new #{class_name}(#{args.call parameters});
\t\tvar tmp5 = new #{class_name}(#{args.call parameters});
\t\tSystem.out.println(tmp1);
\t\tSystem.out.println(tmp2);
\t\tSystem.out.println(tmp3);
\t\tSystem.out.println(tmp4);
\t\tSystem.out.println(tmp5);
\t\t#{container_class} lol = new #{container_class}(#{args.call container_params});
\t\tlol.add#{class_name}(tmp1);
\t\tlol.add#{class_name}(tmp2);
\t\tlol.add#{class_name}(tmp3);
\t\tlol.add#{class_name}(tmp4);
\t\tlol.add#{class_name}(tmp5);
\t\tSystem.out.println(\"\");
\t\tSystem.out.println(\"Some checkpoint\");
\t\t#{maggie.join "\n\n\t\tSystem.out.println(\"Some Checkpoint\"); \n\t\t"}
\t}
\tpublic static void main(String[] args) {
\t\tTestDriver.test();
\t}
}"
2019-10-13 12:08:50 +00:00
end
def construct_container(name, parameters, given_fields, methods, arraylist_name)
fields = ""
parameters.each do |x|
2019-10-17 11:44:22 +00:00
fields += "\tprivate #{x[:type]} #{x[:name]};\n"
2019-10-13 12:08:50 +00:00
end
given_fields.each do |x|
2019-10-17 11:44:22 +00:00
fields += "\tprivate #{x[:type]} #{x[:name]};\n"
2019-10-13 12:08:50 +00:00
end
maggie = methods.map do |x|
"
2019-10-17 11:44:22 +00:00
\tpublic #{x[:return_type]} #{x[:name]} (#{x[:params].map {|y| "#{y[:type]} #{y[:name]}"}.join ","}) {
\t\t#{x[:method_type]}
\t}
"
2019-10-13 12:08:50 +00:00
end
construtor_params = parameters.map do |x|
"#{x[:type]} #{x[:name]}"
end
constructor_handlers = parameters.map do |x|
print(x[:name])
"this.#{x[:name]} = #{x[:name]};"
end
2019-10-17 11:44:22 +00:00
"import java.util.*;
import java.util.stream.Collectors;
2019-10-13 12:08:50 +00:00
2019-10-17 11:44:22 +00:00
public class #{name} {
#{fields}
2019-10-13 12:08:50 +00:00
2019-10-17 11:44:22 +00:00
\tpublic #{name}(#{construtor_params.join ","}) {
\t\t#{constructor_handlers.join "\n"}
\t\tthis.#{arraylist_name} = new ArrayList<>();
\t}
#{maggie.join ""}
2019-10-14 10:54:53 +00:00
2019-10-17 11:44:22 +00:00
\tpublic void print#{name}() {
\t\tSystem.out.println(\"#{name}\");
\t\tCollections.sort(#{arraylist_name});
2019-10-14 10:54:53 +00:00
2019-10-17 11:44:22 +00:00
\t\tfor (var i : #{arraylist_name}) {
\t\t\tSystem.out.println(i);
\t\t}
\t}
}"
2019-10-13 12:08:50 +00:00
end
2019-10-14 10:54:53 +00:00
2019-10-17 09:48:54 +00:00
file = File.open("#{name}.java", "w")
file.puts(construct_class name, params, to_string_template, sorting_filters)
file.close
2019-10-14 10:54:53 +00:00
2019-10-13 12:08:50 +00:00
another_another_file = File.open("#{container_class}.java", "w")
2019-10-21 18:16:37 +00:00
another_another_file.puts(construct_container(container_class, container_params, container_fields, container_methods, container_obj))
2019-10-13 12:08:50 +00:00
another_another_file.close
2019-10-21 18:16:37 +00:00
puts "fucking please"
2019-10-13 12:08:50 +00:00
another_file = File.open("TestDriver.java", "w")
2019-10-21 18:16:37 +00:00
another_file.puts(construct_driver name, params, driver_methods, container_class, driver_params)
2019-10-13 12:08:50 +00:00
another_file.close
`javac *.java`
`java TestDriver`