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