60 lines
1.6 KiB
Ruby
60 lines
1.6 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)
|
|
|
|
|
|
result_init = compare == '>' ? 'Integer.MIN_VALUE' : 'Integer.MAX_VALUE'
|
|
steffan = extra_compare == ".equals" ? ".equals(#{extra_param}" : " #{extra_compare} #{extra_param}"
|
|
|
|
"#{type} result = null;
|
|
\t\tint result_maggie = #{result_init};
|
|
\t\tfor (var pls : #{container_obj}) {
|
|
\t\t\tif (pls.get#{extra_based_on}()#{steffan}) && pls.get#{based_on}() #{compare} result_maggie) {
|
|
\t\t\t\tresult = pls;
|
|
\t\t\t\tresult_maggie = pls.get#{based_on}();
|
|
\t\t\t}
|
|
\t\t}
|
|
\t\treturn result;"
|
|
end
|
|
|
|
def find_all(container_obj, based_on, compare, type, parameter)
|
|
alex = compare=='.equals' ? ".equals(#{parameter})" : " #{compare} #{parameter}"
|
|
"ArrayList<#{type}> result = new ArrayList<>();
|
|
\t\tfor (var pls : #{container_obj}) {
|
|
\t\t\tif (pls.get#{based_on}()#{alex}) {
|
|
\t\t\t\tresult.add(pls);
|
|
\t\t\t}
|
|
\t\t}
|
|
\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
|
|
|