86 lines
1.9 KiB
Ruby
86 lines
1.9 KiB
Ruby
def find_best(container_obj, based_on, compare, type)
|
|
"
|
|
#{type} result = null;
|
|
for (var pls : #{container_obj}) {
|
|
if (result == null || pls.get#{based_on}() #{compare} result.get#{based_on}()) {
|
|
result = pls;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
"
|
|
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"
|
|
|
|
if based_on_type == "int"
|
|
helper_variable = "int result#{based_on} = #{result_init};"
|
|
else
|
|
helper_variable = "String result#{based_on};"
|
|
end
|
|
|
|
|
|
if extra_compare.length > 4
|
|
# TODO: Check if this case is required
|
|
"
|
|
#{type} result = null;
|
|
#{helper_variable}
|
|
for (var pls : #{container_obj}) {
|
|
if ((pls.get#{extra_based_on}()#{extra_compare}(#{extra_param}) && pls.get#{based_on}() #{compare} result.get#{based_on}())) {
|
|
result = pls;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
"
|
|
else
|
|
"
|
|
#{type} result = null;
|
|
#{helper_variable}
|
|
for (var pls : #{container_obj}) {
|
|
if ((pls.get#{extra_based_on}()#{extra_compare}#{extra_param} && pls.get#{based_on}() #{compare} #{result_init}) {
|
|
result = pls;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
"
|
|
end
|
|
end
|
|
|
|
def find_all(container_obj, based_on, compare, type, parameter)
|
|
|
|
if compare.length > 4
|
|
|
|
"
|
|
ArrayList<#{type}> result = new ArrayList<>();
|
|
for (var pls : #{container_obj}) {
|
|
if (pls.get#{based_on}#{compare}(#{parameter}) {
|
|
result.add(pls);
|
|
}
|
|
}
|
|
return result;
|
|
"
|
|
else
|
|
"
|
|
ArrayList<#{type}> result = new ArrayList<>();
|
|
for (var pls : #{container_obj}) {
|
|
if (pls.get#{based_on}() #{compare} #{parameter}) {
|
|
result.add(pls);
|
|
}
|
|
}
|
|
return result;
|
|
"
|
|
end
|
|
end
|
|
|
|
def add_method(container_name, name)
|
|
"
|
|
#{container_name}.add(#{name});
|
|
"
|
|
end
|
|
|