whatever
This commit is contained in:
parent
f961d478b6
commit
00a1805879
|
@ -11,12 +11,11 @@ def find_best(container_obj, based_on, compare, type)
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_best_with_extra_parameter(container_obj, based_on, compare, type, extra_based_on, extra_compare, extra_param, based_on_type)
|
|
||||||
|
def find_best_with_extra_parameter(container_obj, based_on, compare, type, extra_based_on, extra_compare, extra_param)
|
||||||
|
|
||||||
result_init = extra_compare == ' > ' ? 'Integer.MIN_VALUE' : 'Integer.MAX_VALUE'
|
|
||||||
|
|
||||||
|
|
||||||
|
result_init = compare == '>' ? 'Integer.MIN_VALUE' : 'Integer.MAX_VALUE'
|
||||||
steffan = extra_compare == ".equals" ? ".equals(#{extra_param}" : " #{extra_compare} #{extra_param}"
|
steffan = extra_compare == ".equals" ? ".equals(#{extra_param}" : " #{extra_compare} #{extra_param}"
|
||||||
|
|
||||||
"#{type} result = null;
|
"#{type} result = null;
|
||||||
|
@ -41,6 +40,19 @@ def find_all(container_obj, based_on, compare, type, parameter)
|
||||||
\t\treturn result;"
|
\t\treturn result;"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_amount_of_variable_based_on(container_obj, based_on, compare, parameter, of_variable)
|
||||||
|
alex = compare=='.equals' ? ".equals(#{parameter})" : " #{compare} #{parameter}"
|
||||||
|
"int result = 0;
|
||||||
|
\t\tfor (var pls : #{container_obj}) {
|
||||||
|
\t\t\tif (pls.get#{based_on}()#{alex}) {
|
||||||
|
\t\t\t\tresult += pls.get#{of_variable}();
|
||||||
|
\t\t\t}
|
||||||
|
\t\t}
|
||||||
|
\t\treturn result;"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_method(container_name, name)
|
def add_method(container_name, name)
|
||||||
"#{container_name}.add(#{name});"
|
"#{container_name}.add(#{name});"
|
||||||
end
|
end
|
||||||
|
|
51
lol.rb
51
lol.rb
|
@ -7,25 +7,23 @@ require_relative 'pdf-parser'
|
||||||
|
|
||||||
# Hi! Steffan was here...
|
# Hi! Steffan was here...
|
||||||
|
|
||||||
prim_class, container, class_fields, container_params, container_methods_maggie = parse "ferry.pdf"
|
prim_class, container, class_fields, container_params, container_methods_maggie = parse "flight.pdf"
|
||||||
|
|
||||||
name = prim_class
|
name = prim_class
|
||||||
container_class = container
|
container_class = container
|
||||||
|
|
||||||
|
|
||||||
container_obj = "ferries"
|
container_obj = "flights"
|
||||||
to_string_template = "0 1 x 2 meter"
|
to_string_template = "0, 1 km/hour, 2 seats"
|
||||||
|
|
||||||
sorting_one = Type.new("String", "Name")
|
sorting_one = Type.new("String", "Airline")
|
||||||
sorting_two = Type.new("int", "Length")
|
sorting_two = Type.new("int", "Seats")
|
||||||
sorting_three = Type.new("int", "Width")
|
|
||||||
|
|
||||||
sorting_two.comparator = "<"
|
sorting_two.comparator = ">"
|
||||||
sorting_three.comparator = "<"
|
|
||||||
|
|
||||||
sorting_filters = [sorting_one, sorting_two, sorting_three]
|
sorting_filters = [sorting_one, sorting_two]
|
||||||
|
|
||||||
print(class_fields)
|
container_fields = [ {:type => "ArrayList<#{name}>", :name => container_obj}]
|
||||||
|
|
||||||
params = [*class_fields.map! {|x| {:type => x.split(" ")[0], :name => x.split(" ")[1].capitalize}}]
|
params = [*class_fields.map! {|x| {:type => x.split(" ")[0], :name => x.split(" ")[1].capitalize}}]
|
||||||
|
|
||||||
|
@ -45,24 +43,26 @@ container_methods = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
container_methods[0][:method_type] = add_method(container_obj, "f")
|
container_methods[0][:method_type] = add_method(container_obj, "f")
|
||||||
container_methods[1][:method_type] = find_all(container_obj, "Length", "<", "#{name}", "maxLength")
|
container_methods[1][:method_type] = find_amount_of_variable_based_on(container_obj, "Airline", ".equals", "airline", "Seats")
|
||||||
container_methods[2][:method_type] = find_best_with_extra_parameter(container_obj, "Length", ">", "#{name}", "Name", ".equals", "Name", "int")
|
container_methods[2][:method_type] = find_best_with_extra_parameter(container_obj, "Speed", ">", "Flight", "Airline", ".equals", "airline" )
|
||||||
container_methods[4][:method_type] = func_find_all(container_obj, "Width", [Filter.new("min", ">="), Filter.new("max", "<=")])
|
container_methods[4][:method_type] = func_find_all(container_obj, "Speed", [Filter.new("min", ">="), Filter.new("max", "<=")])
|
||||||
container_methods[5][:method_type] = find_whatever_of_variable(container_obj, "Name", [Filter.new("Name", ".equals")], "sum", "Length")
|
# find_whatever_of_variable(container_obj, attribute, filter_by, aggregate_func, variable)
|
||||||
|
container_methods[5][:method_type] = find_whatever_of_something(container_obj, "Speed", [Filter.new("minSpeed", ">")], "count")
|
||||||
|
|
||||||
|
container_params.map! do |x|
|
||||||
|
{:type => x.split(" ")[0], :name => x.split(" ")[1].capitalize}
|
||||||
|
end
|
||||||
|
|
||||||
container_params = [{:type => "String", :name => "Name"}]
|
# Hack to clear duplicates, which most definitely won't always work
|
||||||
container_fields = [ {:type => "ArrayList<#{name}>", :name => container_obj}]
|
container_params = container_params|[]
|
||||||
|
|
||||||
driver_methods = [{:name => "smallFerries", :parameters => [{:type => "int"}], :print => true},
|
driver_params = container_params
|
||||||
{:name => "longFerry", :parameters => [{:type => "String"}], :print => true},
|
|
||||||
{:name => "printHarbour", :parameters => [], :print => false},
|
driver_methods = container_methods.slice(1, container_methods.length-1).map do |x|
|
||||||
{:name => "findFerries", :parameters => [{:type => "int"}, {:type => "int"}], :print => true },
|
{:name => x[:name], :parameters => x[:params], :print => !x[:name].start_with?("print")}
|
||||||
{:name => "findLength", :parameters => [{:type => "String"}], :print => true}]
|
end
|
||||||
|
|
||||||
driver_params = [{:type => "String"}]
|
|
||||||
|
|
||||||
def construct_class(name_of_class, parameters, to_string_template, sorting_filters)
|
def construct_class(name_of_class, parameters, to_string_template, sorting_filters)
|
||||||
|
|
||||||
|
@ -184,7 +184,6 @@ def construct_container(name, parameters, given_fields, methods, arraylist_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
constructor_handlers = parameters.map do |x|
|
constructor_handlers = parameters.map do |x|
|
||||||
print(x[:name])
|
|
||||||
"this.#{x[:name]} = #{x[:name]};"
|
"this.#{x[:name]} = #{x[:name]};"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -211,8 +210,6 @@ public class #{name} {
|
||||||
}"
|
}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
file = File.open("#{name}.java", "w")
|
file = File.open("#{name}.java", "w")
|
||||||
file.puts(construct_class name, params, to_string_template, sorting_filters)
|
file.puts(construct_class name, params, to_string_template, sorting_filters)
|
||||||
file.close
|
file.close
|
||||||
|
@ -220,12 +217,10 @@ file.close
|
||||||
another_another_file = File.open("#{container_class}.java", "w")
|
another_another_file = File.open("#{container_class}.java", "w")
|
||||||
another_another_file.puts(construct_container(container_class, container_params, container_fields, container_methods, container_obj))
|
another_another_file.puts(construct_container(container_class, container_params, container_fields, container_methods, container_obj))
|
||||||
another_another_file.close
|
another_another_file.close
|
||||||
puts "fucking please"
|
|
||||||
|
|
||||||
another_file = File.open("TestDriver.java", "w")
|
another_file = File.open("TestDriver.java", "w")
|
||||||
another_file.puts(construct_driver name, params, driver_methods, container_class, driver_params)
|
another_file.puts(construct_driver name, params, driver_methods, container_class, driver_params)
|
||||||
another_file.close
|
another_file.close
|
||||||
|
|
||||||
|
|
||||||
`javac *.java`
|
`javac *.java`
|
||||||
`java TestDriver`
|
`java TestDriver`
|
||||||
|
|
|
@ -14,33 +14,32 @@ def parse(exam_text)
|
||||||
container = content[0][1]
|
container = content[0][1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
container_params = content.slice(2, content.length-1).filter { |x|
|
container_params = content.slice(2, content.length-1).filter { |x|
|
||||||
|
|
||||||
unless x[0].include? "("
|
unless x[0].include? "("
|
||||||
x[0]
|
if x[0].split(" ").length > 1
|
||||||
|
x[0]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
}.map {|x| x[0].strip}
|
}.map {|x| x[0].strip}
|
||||||
|
|
||||||
|
|
||||||
container_methods = content.slice(2, content.length-1).filter { |x|
|
container_methods = content.slice(2, content.length-1).filter { |x|
|
||||||
if x[0].include? "("
|
if x[0].include? "("
|
||||||
x[0]
|
x[0]
|
||||||
end
|
end
|
||||||
}.map {|x| x[0].strip}
|
}.map {|x| x[0].strip}
|
||||||
|
|
||||||
|
|
||||||
class_fields = content.slice(3, content.length-1).filter { |x|
|
class_fields = content.slice(3, content.length-1).filter { |x|
|
||||||
(x.length > 1) and (not x[1].include? "(")
|
(x.length > 1) and (not x[1].include? "(")
|
||||||
}.map {|x| x[1].strip}
|
}.map {|x| x[1].strip}
|
||||||
|
|
||||||
if content[4].length == 1
|
if content[4].length == 1
|
||||||
tmp = content[4][0].strip
|
tmp = content[4][0].strip
|
||||||
class_fields += [tmp]
|
class_fields = [tmp] + class_fields
|
||||||
end
|
end
|
||||||
|
|
||||||
#print(content.slice(0, content.length-1))
|
#print(content.slice(0, content.length-1))
|
||||||
|
|
||||||
|
|
||||||
regex = /\A(\S+) (\w+)\((.*)\)\Z/
|
regex = /\A(\S+) (\w+)\((.*)\)\Z/
|
||||||
|
|
||||||
container_methods.map! do |x|
|
container_methods.map! do |x|
|
||||||
|
@ -49,10 +48,7 @@ def parse(exam_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return prim_class, container, class_fields, container_params, container_methods
|
return prim_class, container, class_fields, container_params, container_methods
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
parse("ferry.pdf")
|
parse("ferry.pdf")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user