More beautify
This commit is contained in:
parent
c81e3d7399
commit
f5911f4cb6
|
@ -13,11 +13,8 @@ end
|
|||
|
||||
def find_best_with_extra_parameter(container_obj, based_on, compare, type, extra_based_on, extra_compare, extra_param, based_on_type)
|
||||
|
||||
if extra_compare == " > "
|
||||
result_init = "Integer.MIN_VALUE"
|
||||
else
|
||||
result_init = "Integer.MAX_VALUE"
|
||||
end
|
||||
|
||||
result_init = extra_compare == " > " ? "Integer.MIN_VALUE" : "Integer.MAX_VALUE"
|
||||
|
||||
if based_on_type == "int"
|
||||
helper_variable = "int result#{based_on} = #{result_init};"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
def func_find_all(container_obj, attribute, filter_by)
|
||||
filters = filter_by.map do |x|
|
||||
"s.get#{attribute}() #{x.comparator} #{x.value}"
|
||||
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
||||
"s.get#{attribute}()#{comparator}"
|
||||
end
|
||||
# TODO: Consider also having an "or" here
|
||||
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).collect(Collectors.toList());"
|
||||
|
@ -8,18 +9,18 @@ def func_find_all(container_obj, attribute, filter_by)
|
|||
end
|
||||
|
||||
def find_whatever_of_something(container_obj, attribute, filter_by, aggregate_func)
|
||||
# TODO: Fix comparator to work for strings, such that I use .equals instead of ==
|
||||
filters = filter_by.map do |x|
|
||||
"s.get#{attribute}() #{x.comparator} #{x.value}"
|
||||
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
||||
"s.get#{attribute}()#{comparator}"
|
||||
end
|
||||
# TODO: Consider also having an "or" here
|
||||
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).#{aggregate_func}();"
|
||||
end
|
||||
|
||||
def find_whatever_of_variable(container_obj, attribute, filter_by, aggregate_func, variable)
|
||||
# TODO: Fix comparator to work for strings, such that I use .equals instead of ==
|
||||
filters = filter_by.map do |x|
|
||||
"s.get#{attribute}() #{x.comparator} #{x.value}"
|
||||
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
||||
"s.get#{attribute}()#{comparator}"
|
||||
end
|
||||
# TODO: Consider also having an "or" here
|
||||
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).mapToInt(s -> s.get#{variable}()).#{aggregate_func}();"
|
||||
|
@ -27,7 +28,8 @@ end
|
|||
|
||||
def find_one(container_obj, attribute, filter_by)
|
||||
filters = filter_by.map do |x|
|
||||
"s.get#{attribute}() #{x.comparator} #{x.value}"
|
||||
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
||||
"s.get#{attribute}()#{comparator}"
|
||||
end
|
||||
# TODO: Consider also having an "or" here
|
||||
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).findAny().orElse(null);"
|
||||
|
@ -35,7 +37,8 @@ end
|
|||
|
||||
def find_best_value(container_obj, attribute, filter_by, min_or_max, based_on)
|
||||
filters = filter_by.map do |x|
|
||||
"s.get#{attribute}() #{x.comparator} #{x.value}"
|
||||
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
||||
"s.get#{attribute}()#{comparator}"
|
||||
end
|
||||
# TODO: Consider also having an "or" here
|
||||
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).mapToInt(s -> s.get#{based_on}()).#{min_or_max};"
|
||||
|
@ -43,7 +46,8 @@ end
|
|||
|
||||
def find_best_object(container_obj, attribute, filter_by, min_or_max, based_on)
|
||||
filters = filter_by.map do |x|
|
||||
"s.get#{attribute}() #{x.comparator} #{x.value}"
|
||||
comparator = x.comparator == ".equals" ? ".equals(#{x.value})" : "#{x.comparator} #{x.value}"
|
||||
"s.get#{attribute}()#{comparator}"
|
||||
end
|
||||
# TODO: Consider also having an "or" here
|
||||
"return #{container_obj}.stream().filter(s -> #{filters.join "&&"}).#{min_or_max}(Comparator.comparing(#{based_on.type}.get#{based_on.variable}()));"
|
||||
|
|
30
lol.rb
30
lol.rb
|
@ -14,6 +14,10 @@ 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")
|
||||
|
||||
sorting_two.comparator = "<"
|
||||
sorting_three.comparator = "<"
|
||||
|
||||
sorting_filters = [sorting_one, sorting_two, sorting_three]
|
||||
|
||||
def construct_class(name_of_class, parameters, to_string_template, sorting_filters)
|
||||
|
@ -74,9 +78,6 @@ def construct_driver(class_name, parameters, methods, container_class, container
|
|||
end.join ","
|
||||
end
|
||||
|
||||
|
||||
|
||||
methods_to_print = ""
|
||||
maggie = methods.map do |x|
|
||||
if x[:print]
|
||||
"System.out.println(lol.#{x[:name]}(#{args x[:parameters]}));"
|
||||
|
@ -85,7 +86,7 @@ def construct_driver(class_name, parameters, methods, container_class, container
|
|||
end
|
||||
end
|
||||
|
||||
driver_string = "
|
||||
"
|
||||
public class TestDriver {
|
||||
|
||||
public TestDriver(){}
|
||||
|
@ -150,7 +151,7 @@ def construct_container(name, parameters, given_fields, methods, arraylist_name)
|
|||
"this.#{x[:name]} = #{x[:name]};"
|
||||
end
|
||||
|
||||
container_string = "
|
||||
"
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -172,19 +173,9 @@ def construct_container(name, parameters, given_fields, methods, arraylist_name)
|
|||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"
|
||||
|
||||
container_string
|
||||
|
||||
}"
|
||||
end
|
||||
|
||||
file = File.open("#{name}.java", "w")
|
||||
params = [{:type => "String", :name => "Name"}, {:type => "int", :name => "Length"}, {:type => "int", :name => "Width"}]
|
||||
file.puts(construct_class name, params, to_string_template, sorting_filters)
|
||||
file.close
|
||||
|
||||
|
||||
container_methods = [
|
||||
{
|
||||
|
@ -234,12 +225,15 @@ container_methods = [
|
|||
:type => "String",
|
||||
:name => "Name"
|
||||
}],
|
||||
:method_type => find_whatever_of_variable(container_obj, "Name", [Filter.new("Name", "==")], "sum", "Length")
|
||||
:method_type => find_whatever_of_variable(container_obj, "Name", [Filter.new("Name", ".equals")], "sum", "Length")
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
file = File.open("#{name}.java", "w")
|
||||
params = [{:type => "String", :name => "Name"}, {:type => "int", :name => "Length"}, {:type => "int", :name => "Width"}]
|
||||
file.puts(construct_class name, params, to_string_template, sorting_filters)
|
||||
file.close
|
||||
|
||||
another_another_file = File.open("#{container_class}.java", "w")
|
||||
another_another_file.puts(construct_container(container_class, [{:type => "String", :name => "Name"}], [ {:type => "ArrayList<#{name}>", :name => container_obj}], container_methods, container_obj))
|
||||
|
|
Loading…
Reference in New Issue
Block a user