note description: "Compares projects lexicographically according to their names" author: "Dennis Rietmann" date: "$Date$" revision: "$Revision$" class PROJECT_COMPARATOR inherit KL_PART_COMPARATOR[DS_HASH_TABLE[ANY, STRING]] create make feature {NONE} -- Creation make (a_logger: like logger) -- Initializes the comparator with `a_logger' for error logging do logger := a_logger end feature -- Comparison less_than (u, v: DS_HASH_TABLE[ANY, STRING]): BOOLEAN -- u,v: The projects to compare lexicographically according to their names local l_project_name_1: STRING l_project_name_2: STRING l_pid_1: INTEGER_REF -- should be INTEGER but how to do this in Eiffel? l_pid_2: INTEGER_REF do l_project_name_1 ?= u.item ("name") l_pid_1 ?= u.item ("project_id") check project_name_1_ok: l_project_name_1 /= Void end l_project_name_2 ?= v.item ("name") l_pid_2 ?= v.item ("project_id") check project_name_2_ok: l_project_name_2 /= Void end if l_project_name_1 /= Void and l_project_name_2 /= Void then -- bothe are not void Result := l_project_name_1 < l_project_name_2 elseif l_project_name_1 /= Void then -- error: name2 is Void, we use the pid for comparison logger.error ("project name 2 is Void (pid: " + l_pid_2.out + ") compared with project " + l_project_name_1 + "(pid: " + l_pid_1.out + ")") Result := l_pid_1 < l_pid_2 elseif l_project_name_2 /= Void then -- error: name1 is Void, we use the pid for comparison logger.error ("project name 1 is Void (pid: " + l_pid_1.out + ") compared with project " + l_project_name_2 + "(pid: " + l_pid_2.out + ")") Result := l_pid_1 < l_pid_2 else -- both are Void, we use the pid for comparison logger.error ("project name 1 and 2 are Void (pid: " + l_pid_1.out + ") compared with (pid: " + l_pid_2.out + ")") Result := l_pid_1 < l_pid_2 end end feature {NONE} -- Logging logger: L4E_LOGGER end