indexing
	description: "Intervals between absolute values"
	status: "See notice at end of class"
	date: "$Date$"
	revision: "$Revision$"

class interface
	INTERVAL [G -> ABSOLUTE]

create 

	make (s, e: G)
			-- Sets start_bound and end_bound to s and e respectively.
		require
			start_exists: s /= void
			end_exists: e /= void
			start_before_end: s <= e
		ensure
			start_bound_set: start_bound /= void and then deep_equal (start_bound, s)
			end_bound_set: end_bound /= void and then deep_equal (end_bound, e)

feature -- Initialization

	make (s, e: G)
			-- Sets start_bound and end_bound to s and e respectively.
		require
			start_exists: s /= void
			end_exists: e /= void
			start_before_end: s <= e
		ensure
			start_bound_set: start_bound /= void and then deep_equal (start_bound, s)
			end_bound_set: end_bound /= void and then deep_equal (end_bound, e)
	
feature -- Access

	end_bound: G
			-- End bound of the current interval

	start_bound: G
			-- Start bound of the current interval
	
feature -- Measurement

	duration: DURATION
			-- Length of the interval
	
feature -- Comparison

	includes (other: like Current): BOOLEAN
			-- Does current interval include other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	intersects (other: like Current): BOOLEAN
			-- Does current interval intersect other?
		require
			other_exists: other /= void

	is_equal (other: like Current): BOOLEAN
			-- Is current interval equal to other?
		require -- from ANY
			other_not_void: other /= void
		ensure -- from ANY
			symmetric: Result implies other.is_equal (Current)
			consistent: standard_is_equal (other) implies Result

	is_included_by (other: like Current): BOOLEAN
			-- Is current interval included by other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	is_met_by (other: like Current): BOOLEAN
			-- Is current interval met by other?
		require
			other_exists: other /= void
		ensure
			symmetry: Result = other.meets (Current)

	is_overlapped_by (other: like Current): BOOLEAN
			-- Is current interval overlapped by other?
		require
			other_exists: other /= void
		ensure
			symmetry: Result = other.overlaps (Current)

	is_strict_included_by (other: like Current): BOOLEAN
			-- Is current interval strictly included by other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	meets (other: like Current): BOOLEAN
			-- Does current interval meet other?
		require
			other_exists: other /= void
		ensure
			symmetry: Result = other.is_met_by (Current)
			result_definition: Result = (Current <= other and intersects (other))

	overlaps (other: like Current): BOOLEAN
			-- Does current interval overlap other?
		require
			other_exists: other /= void
		ensure
			result_defition: Result = (strict_before (other.end_bound) and has (other.start_bound))
			symmetry: Result = other.is_overlapped_by (Current)

	strict_includes (other: like Current): BOOLEAN
			-- Does current interval strictly include other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	infix "<" (other: like Current): BOOLEAN
			-- Is current interval strictly before other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	infix "<=" (other: like Current): BOOLEAN
			-- Is current interval before other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	infix ">" (other: like Current): BOOLEAN
			-- Is current interval after other?
		require -- from PART_COMPARABLE
			other_exists: other /= void

	infix ">=" (other: like Current): BOOLEAN
			-- Is current interval after other?
		require -- from PART_COMPARABLE
			other_exists: other /= void
	
feature -- Status report

	after (v: G): BOOLEAN
			-- Is the current interval after v?
		require
			exists: v /= void
		ensure
			result_definition: Result = (start_bound >= v)

	before (v: G): BOOLEAN
			-- Is the current interval before v?
		require
			exists: v /= void
		ensure
			result_definition: Result = (end_bound <= v)

	empty: BOOLEAN
			-- Is current interval empty?
		ensure
			result_definition: Result = duration.is_equal (duration.zero)

	has (v: G): BOOLEAN
			-- Does current interval have v between its bounds?
		require
			exists: v /= void
		ensure
			result_definition: Result xor not ((start_bound <= v) and then (end_bound >= v))

	strict_after (v: G): BOOLEAN
			-- Is the current interval strictly after v?
		require
			exists: v /= void
		ensure
			result_definition: Result = (start_bound > v)

	strict_before (v: G): BOOLEAN
			-- Is the current interval strictly before v?
		require
			exists: v /= void
		ensure
			result_definition: Result xor (not (end_bound < v))
	
feature -- Element change

	set_end_bound (e: G)
			-- Set end_bound to e.
		require
			end_bound_exists: e /= void
			end_after_start_bound: e >= start_bound
		ensure
			end_bound_set: equal (end_bound, e)

	set_start_bound (s: G)
			-- Set start_bound to s.
		require
			start_bound_exists: s /= void
			start_before_end_bound: s <= end_bound
		ensure
			start_bound_set: equal (start_bound, s)
	
feature -- Basic operations

	gather (other: like Current): like Current
			-- Union of other and current interval if other meets
			-- current interval
		require
			other_exist: other /= void
			meeting_interval: meets (other)
		ensure
			result_exist: Result /= void
			result_same_as_union: Result.is_equal (union (other))

	intersection (other: like Current): like Current
			-- Intersection with other
		require
			other_exists: other /= void
		ensure
			intersects_validity: intersects (other) implies Result /= void
			result_is_included_by_current: intersects (other) implies includes (Result)
			result_is_included_by_other: intersects (other) implies other.includes (Result)

	union (other: like Current): like Current
			-- Union with other
		require
			other_exists: other /= void
			intersects: intersects (other)
		ensure
			result_exists: Result /= void
			result_includes_current: Result.includes (Current)
			result_includes_other: Result.includes (other)
	
feature -- Output

	out: STRING
			-- Printable representation of the current interval
	
invariant

	start_bound_exists: start_bound /= void
	end_bound_exists: end_bound /= void
	start_bound_before_end_bound: start_bound <= end_bound
	current_intersection: intersection (Current).is_equal (Current)
	current_union: union (Current).is_equal (Current)
	has_bounds: has (start_bound) and has (end_bound)
	between_bound: after (start_bound) and before (end_bound)
		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

end -- class INTERVAL