INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES

indexing

title: "Objects that may be compared to a total order relation.", "Note: The basic operation is %'<%' (less than); others are defined in terms of this operation and %'is_equal%'."
project: "Eiffel Kernel Library"
revision: "$Revision: 1.1 $"
copyright: "Copyright (C) 1996-2005 Object Tools Group"
license: "http://visual-eiffel.com/license"
cluster: kernel
deferred class COMPARABLE
inherit

ANY
redefine
is_equal
end
feature -- Comparison

infix "<" (other: like Current): BOOLEAN
-- Is current object less than 'other'?
require
other_exists: other /= void
ensure
asymmetric: Result implies not (other < Current)

infix "<=" (other: like Current): BOOLEAN
-- Is current object less than or equal to 'other'?
require
other_exists: other /= void
ensure
definition: Result = (Current < other or is_equal (other))

infix ">=" (other: like Current): BOOLEAN
-- Is current object greater than or equal to 'other'?
require
other_exists: other /= void
ensure
definition: Result = (other <= Current)

infix ">" (other: like Current): BOOLEAN
-- Is current object greater than 'other'?
require
other_exists: other /= void
ensure
definition: Result = (other < Current)

is_equal (other: like Current): BOOLEAN
-- Is 'other' attached to an object considered equal
-- to current object?
ensure
trichotomy: Result = (not (Current < other) and not (other < Current))

max (other: like Current): like Current
-- The greater of current object and 'other'
require
other_exists: other /= void
ensure
current_if_not_smaller: (Current >= other) implies Result.is_equal (Current)
other_if_smaller: (Current < other) implies Result.is_equal (other)

min (other: like Current): like Current
-- The smaller of current object and 'other'
require
other_exists: other /= void
ensure
current_if_not_greater: (Current <= other) implies Result.is_equal (Current)
other_if_greater: (Current > other) implies Result.is_equal (other)

three_way_comparison (other: like Current): INTEGER
-- If current object equal to 'other', 0; if smaller, -1; if greater, 1
require
other_exists: other /= void
ensure
equal_zero: (Result = 0) = is_equal (other)
smaller_negative: (Result = -1) = (Current < other)
greater_positive: (Result = 1) = (Current > other)
feature -- Eiffel/S 1.3 compatibility

compare (other: like Current): INTEGER
obsolete "Eiffel/S 1.3 compatibility, use three_way_comparison"
-- Compare Current with 'other'.
-- '<' <==> Result < 0
-- '>' <==> Result > 0
-- Otherwise Result = 0
invariant

irreflexive_comparison: not (Current < Current)
end -- class COMPARABLE

INDEX CLUSTER FEATURES SHORT FRAMES NO FRAMES