note
	description: "[
		Contiguous integer interval that calls an action sequence
		when it changes.
	]"
	legal: "See notice at end of class."
	status: "See notice at end of class."
	keywords: "event, action, linked, list"
	date: "$Date: 2017-03-23 19:18:26 +0000 (Thu, 23 Mar 2017) $"
	revision: "$Revision: 100033 $"

class 
	ACTIVE_INTEGER_INTERVAL

create 
	make

feature -- Initialization

	adapt (other: INTEGER_INTERVAL)
			-- Reset to be the same interval as other.
		require -- from INTEGER_INTERVAL
			other_not_void: other /= Void
		do
			Precursor (other)
			on_change
		ensure -- from INTEGER_INTERVAL
			same_lower: lower = other.lower
			same_upper: upper = other.upper
			same_lower_defined: Lower_defined = other.Lower_defined
			same_upper_defined: Upper_defined = other.Upper_defined
		end
	
feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	make (min_index, max_index: INTEGER_32)
			-- Set up interval to have bounds min_index and
			-- max_index (empty if min_index > max_index)
			-- (from INTEGER_INTERVAL)
		do
			if min_index <= max_index then
				lower := min_index
				upper := max_index
			else
				lower := 1
				upper := 0
			end
		ensure -- from INTEGER_INTERVAL
			lower_defined: Lower_defined
			upper_defined: Upper_defined
			set_if_non_empty: (min_index <= max_index) implies ((lower = min_index) and (upper = max_index))
			empty_if_not_in_order: (min_index > max_index) implies is_empty
		end
	
feature -- Access

	at alias "@" (i: INTEGER_32): INTEGER_32
			-- Entry at index i, if in index interval
			-- Was declared in INTEGER_INTERVAL as synonym of item.
			-- (from INTEGER_INTERVAL)
		require -- from TABLE
			valid_key: valid_index (i)
		do
			Result := i
		end

	generating_type: TYPE [detachable ACTIVE_INTEGER_INTERVAL]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	has alias "" (v: INTEGER_32): BOOLEAN
			-- Does v appear in interval?
			-- Was declared in INTEGER_INTERVAL as synonym of valid_index.
			-- (from INTEGER_INTERVAL)
		require -- from  CONTAINER
			True
		do
			Result := (Upper_defined implies v <= upper) and (Lower_defined implies v >= lower)
		ensure -- from CONTAINER
			not_found_in_empty: Result implies not is_empty
		ensure then -- from INTEGER_INTERVAL
			iff_within_bounds: Result = ((Upper_defined implies v <= upper) and (Lower_defined implies v >= lower))
		end

	item alias "[]" (i: INTEGER_32): INTEGER_32
			-- Entry at index i, if in index interval
			-- Was declared in INTEGER_INTERVAL as synonym of at.
			-- (from INTEGER_INTERVAL)
		require -- from TABLE
			valid_key: valid_index (i)
		require -- from READABLE_INDEXABLE
			valid_index: valid_index (i)
		do
			Result := i
		end

	lower: INTEGER_32
			-- Smallest value in interval.
			-- (from INTEGER_INTERVAL)

	Lower_defined: BOOLEAN = True
			-- Is there a lower bound?
			-- (from INTEGER_INTERVAL)

	new_cursor: INDEXABLE_ITERATION_CURSOR [INTEGER_32]
			-- Fresh cursor associated with current structure
			-- (from READABLE_INDEXABLE)
		require -- from  ITERABLE
			True
		do
			create {READABLE_INDEXABLE_ITERATION_CURSOR [INTEGER_32]} Result.make (Current);
			Result.start
		ensure -- from ITERABLE
			result_attached: Result /= Void
		end

	upper: INTEGER_32
			-- Largest value in interval.
			-- (from INTEGER_INTERVAL)

	Upper_defined: BOOLEAN = True
			-- Is there an upper bound?
			-- (from INTEGER_INTERVAL)

	valid_index (v: INTEGER_32): BOOLEAN
			-- Does v appear in interval?
			-- Was declared in INTEGER_INTERVAL as synonym of has.
			-- (from INTEGER_INTERVAL)
		require -- from  READABLE_INDEXABLE
			True
		require -- from  TABLE
			True
		do
			Result := (Upper_defined implies v <= upper) and (Lower_defined implies v >= lower)
		ensure -- from READABLE_INDEXABLE
			only_if_in_index_set: Result implies (lower <= v and v <= upper)
		ensure then -- from INTEGER_INTERVAL
			iff_within_bounds: Result = ((Upper_defined implies v <= upper) and (Lower_defined implies v >= lower))
		end
	
feature -- Measurement

	additional_space: INTEGER_32
			-- Proposed number of additional items
			-- (from RESIZABLE)
		do
			Result := (capacity // 2).max (Minimal_increase)
		ensure -- from RESIZABLE
			at_least_one: Result >= 1
		end

	capacity: INTEGER_32
			-- Maximum number of items in interval
			-- (here the same thing as count)
			-- (from INTEGER_INTERVAL)
		do
			check
				terminal: Upper_defined and Lower_defined
			end
			Result := count
		ensure -- from BOUNDED
			capacity_non_negative: Result >= 0
		end

	count: INTEGER_32
			-- Number of items in interval
			-- (from INTEGER_INTERVAL)
		require -- from  FINITE
			True
		require -- from  SET
			True
		do
			check
				finite: Upper_defined and Lower_defined
			end
			if Upper_defined and Lower_defined then
				Result := upper - lower + 1
			end
		ensure -- from FINITE
			count_non_negative: Result >= 0
		ensure then -- from INTEGER_INTERVAL
			definition: Result = upper - lower + 1
		end

	Growth_percentage: INTEGER_32 = 50
			-- Percentage by which structure will grow automatically
			-- (from RESIZABLE)

	index_set: INTEGER_INTERVAL
			-- Range of acceptable indexes.
			-- (here: the interval itself)
			-- (from INTEGER_INTERVAL)
		require -- from  READABLE_INDEXABLE
			True
		do
			Result := Current
		ensure -- from READABLE_INDEXABLE
			not_void: Result /= Void
			empty_if_not_in_order: (lower > upper) implies Result.is_empty
			same_lower_if_not_empty: (lower <= upper) implies Result.lower = lower
			same_upper_if_not_empty: (lower <= upper) implies Result.upper = upper
		ensure then -- from INTEGER_INTERVAL
			index_set_is_range: Result ~ Current
		end

	Minimal_increase: INTEGER_32 = 5
			-- Minimal number of additional items
			-- (from RESIZABLE)

	occurrences (v: INTEGER_32): INTEGER_32
			-- Number of times v appears in structure
			-- (from INTEGER_INTERVAL)
		require -- from  BAG
			True
		do
			if has (v) then
				Result := 1
			end
		ensure -- from BAG
			non_negative_occurrences: Result >= 0
		ensure then -- from INTEGER_INTERVAL
			one_iff_in_bounds: Result = 1 implies has (v)
			zero_otherwise: Result /= 1 implies Result = 0
		end
	
feature {NONE} -- Measurement

	estimated_count_of (other: ITERABLE [INTEGER_32]): INTEGER_32
			-- Estimated number of elements in other.
			-- (from CONTAINER)
		do
			if attached {FINITE [INTEGER_32]} other as f then
				Result := f.count
			elseif attached {READABLE_INDEXABLE [INTEGER_32]} other as r then
				Result := r.upper - r.lower + 1
			end
		ensure -- from CONTAINER
			instance_free: class
			non_negative_result: Result >= 0
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	frozen is_deep_equal alias "≡≡≡" (other: ACTIVE_INTEGER_INTERVAL): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: ACTIVE_INTEGER_INTERVAL): BOOLEAN
			-- Is array made of the same items as other?
			-- (from INTEGER_INTERVAL)
		require -- from ANY
			other_not_void: other /= Void
		do
			Result := (Lower_defined implies (other.Lower_defined and lower = other.lower)) and (Upper_defined implies (other.Upper_defined and upper = other.upper))
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		ensure then -- from INTEGER_INTERVAL
			iff_same_bounds: Result = ((Lower_defined implies (other.Lower_defined and lower = other.lower)) and (Upper_defined implies (other.Upper_defined and upper = other.upper)))
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "" (other: ACTIVE_INTEGER_INTERVAL): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	all_cleared: BOOLEAN
			-- Are all items set to default values?
			-- (from INTEGER_INTERVAL)
		do
			Result := (lower = 0) and (upper = 0)
		ensure then -- from INTEGER_INTERVAL
			iff_at_zero: Result = ((lower = 0) and (upper = 0))
		end

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	empty: BOOLEAN
		obsolete "ELKS 2000: Use `is_empty' instead. [2017-05-31]"
			-- Is there no element?
			-- (from CONTAINER)
		do
			Result := is_empty
		end

	extendible: BOOLEAN
			-- May new items be added?
			-- Answer: yes
			-- (from INTEGER_INTERVAL)
		do
			Result := True
		end

	full: BOOLEAN
			-- Is structure full?
			-- (from BOUNDED)
		do
			Result := count = capacity
		end

	is_empty: BOOLEAN
			-- Is structure empty?
			-- (from FINITE)
		require -- from  CONTAINER
			True
		do
			Result := count = 0
		end

	is_inserted (v: INTEGER_32): BOOLEAN
			-- Has v been inserted by the most recent insertion?
			-- (By default, the value returned is equivalent to calling 
			-- has (v). However, descendants might be able to provide more
			-- efficient implementations.)
			-- (from COLLECTION)
		do
			Result := has (v)
		end

	object_comparison: BOOLEAN
			-- Must search operations use equal rather than =
			-- for comparing references? (Default: no, use =.)
			-- (from CONTAINER)

	prunable: BOOLEAN
			-- May individual items be removed?
			-- Answer: no
			-- (from INTEGER_INTERVAL)
		do
			Result := False
		end

	resizable: BOOLEAN
			-- May capacity be changed? (Answer: yes.)
			-- (from RESIZABLE)
		do
			Result := True
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end
	
feature -- Status setting

	compare_objects
			-- Ensure that future search operations will use equal
			-- rather than = for comparing references.
			-- (from CONTAINER)
		require -- from CONTAINER
			changeable_comparison_criterion: changeable_comparison_criterion
		do
			object_comparison := True
		ensure -- from CONTAINER
				object_comparison
		end

	compare_references
			-- Ensure that future search operations will use =
			-- rather than equal for comparing references.
			-- (from CONTAINER)
		require -- from CONTAINER
			changeable_comparison_criterion: changeable_comparison_criterion
		do
			object_comparison := False
		ensure -- from CONTAINER
			reference_comparison: not object_comparison
		end
	
feature -- Element change

	extend (v: INTEGER_32)
			-- Make sure that interval goes all the way
			-- to v (up or down).
		require -- from COLLECTION
			extendible: extendible
		do
			put (v)
		ensure -- from COLLECTION
			item_inserted: is_inserted (v)
		ensure then -- from SET
			in_set_already: old has (v) implies (count = old count)
			added_to_set: not old has (v) implies (count = old count + 1)
		ensure then -- from INTEGER_INTERVAL
			extended_down: lower = (old lower).min (v)
			extended_up: upper = (old upper).max (v)
		end

	fill (other: CONTAINER [INTEGER_32])
			-- Fill with as many items of other as possible.
			-- The representations of other and current structure
			-- need not be the same.
			-- (from COLLECTION)
		require -- from COLLECTION
			other_not_void: other /= Void
			extendible: extendible
		local
			lin_rep: LINEAR [INTEGER_32]
		do
			lin_rep := other.linear_representation
			from
				lin_rep.start
			until
				not extendible or else lin_rep.off
			loop
				extend (lin_rep.item);
				lin_rep.forth
			end
		end

	put (v: INTEGER_32)
			-- Make sure that interval goes all the way
			-- to v (up or down).
		local
			l_change: BOOLEAN
		do
			l_change := v < lower or else v > upper
			Precursor (v)
			if l_change then
				on_change
			end
		ensure then -- from INTEGER_INTERVAL
			extended_down: lower = (old lower).min (v)
			extended_up: upper = (old upper).max (v)
		end
	
feature -- Removal

	changeable_comparison_criterion: BOOLEAN
			-- May object_comparison be changed?
			-- (Answer: only if set empty; otherwise insertions might
			-- introduce duplicates, destroying the set property.)
			-- (from SET)
		require -- from  CONTAINER
			True
		do
			Result := is_empty
		ensure then -- from SET
			only_on_empty: Result = is_empty
		end

	prune_all (v: INTEGER_32)
			-- Remove all occurrences of v.
			-- (Reference or object equality,
			-- based on object_comparison.)
			-- (from COLLECTION)
		require -- from COLLECTION
			prunable: prunable
		do
			from
			until
				not has (v)
			loop
				prune (v)
			end
		ensure -- from COLLECTION
			no_more_occurrences: not has (v)
		end

	wipe_out
			-- Remove all items.
			-- (from INTEGER_INTERVAL)
		require -- from COLLECTION
			prunable: prunable
		do
			lower := 1
			upper := 0
		ensure -- from COLLECTION
			wiped_out: is_empty
		end
	
feature -- Resizing

	automatic_grow
			-- Change the capacity to accommodate at least
			-- Growth_percentage more items.
			-- (from RESIZABLE)
		require -- from RESIZABLE
			resizable: resizable
		do
			grow (capacity + additional_space)
		ensure -- from RESIZABLE
			increased_capacity: capacity >= old capacity + old additional_space
		end

	grow (i: INTEGER_32)
			-- Ensure that capacity is at least i.
			-- (from INTEGER_INTERVAL)
		require -- from RESIZABLE
			resizable: resizable
		do
			if capacity < i then
				resize (lower, lower + i - 1)
			end
		ensure -- from RESIZABLE
			new_capacity: capacity >= i
		ensure then -- from INTEGER_INTERVAL
			no_loss_from_bottom: lower <= old lower
			no_loss_from_top: upper >= old upper
		end

	resize (min_index, max_index: INTEGER_32)
			-- Rearrange interval to go from at most
			-- min_index to at least max_index,
			-- encompassing previous bounds.
		local
			l_change: BOOLEAN
		do
			l_change := lower /= min_index or else upper /= max_index
			Precursor (min_index, max_index)
			if l_change then
				on_change
			end
		end

	resize_exactly (min_index, max_index: INTEGER_32)
			-- Rearrange interval to go from
			-- min_index to max_index.
		local
			l_change: BOOLEAN
		do
			l_change := lower /= min_index or else upper /= max_index
			Precursor (min_index, max_index)
			if l_change then
				on_change
			end
		end

	trim
			-- Decrease capacity to the minimum value.
			-- Apply to reduce allocated storage.
			-- (from INTEGER_INTERVAL)
		do
			check
				minimal_capacity: capacity = count
			end
		ensure -- from RESIZABLE
			same_count: count = old count
			minimal_capacity: capacity = count
		end
	
feature -- Conversion

	as_array: ARRAY [INTEGER_32]
			-- Plain array containing interval's items
			-- (from INTEGER_INTERVAL)
		require -- from INTEGER_INTERVAL
			finite: Upper_defined and Lower_defined
		local
			i, nb: INTEGER_32
		do
			from
				i := lower
				nb := upper
				create Result.make_filled (0, i, nb)
			until
				i > nb
			loop
				Result.put (i, i)
				i := i + 1
			end
		ensure -- from INTEGER_INTERVAL
			same_lower: Result.lower = lower
			same_upper: Result.upper = upper
		end

	linear_representation: LINEAR [INTEGER_32]
			-- Representation as a linear structure
			-- (from INTEGER_INTERVAL)
		do
			check
				terminal: Upper_defined and Lower_defined
			end
			Result := as_array.linear_representation
		end

	to_c: ANY
		obsolete "No replacement. [2017-05-31]"
			-- Address of actual sequence of values,
			-- for passing to external (non-Eiffel) routines.
			-- (from INTEGER_INTERVAL)
		do
			Result := Current
			check
					False
			end
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: like Current)
			-- Reset to be the same interval as other.
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		do
			if other /= Current then
				Precursor (other)
				on_change
			end
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: ACTIVE_INTEGER_INTERVAL)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: ACTIVE_INTEGER_INTERVAL
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: ACTIVE_INTEGER_INTERVAL)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: ACTIVE_INTEGER_INTERVAL
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	subinterval (start_pos, end_pos: INTEGER_32): ACTIVE_INTEGER_INTERVAL
			-- Interval made of items of current array within
			-- bounds start_pos and end_pos.
			-- (from INTEGER_INTERVAL)
		do
			create Result.make (start_pos, end_pos)
		end

	frozen twin: ACTIVE_INTEGER_INTERVAL
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached ACTIVE_INTEGER_INTERVAL
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen default: detachable ACTIVE_INTEGER_INTERVAL
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature -- Inapplicable

	bag_put (v: INTEGER_32)
			-- Ensure that structure includes v.
			-- (from TABLE)
		require -- from COLLECTION
			extendible: extendible
		do
		ensure -- from COLLECTION
			item_inserted: is_inserted (v)
		end

	indexable_put (v: INTEGER_32; k: INTEGER_32)
			-- Associate value v with key k.
			-- Not applicable here.
			-- (from INTEGER_INTERVAL)
		require -- from TABLE
			valid_key: valid_index (k)
		require -- from TABLE
			valid_key: valid_index (k)
		do
		ensure -- from TABLE
			inserted: item (k) = v
		end

	prune (v: INTEGER_32)
			-- Remove one occurrence of v if any.
			-- Not applicable here.
			-- (from INTEGER_INTERVAL)
		require -- from COLLECTION
			prunable: prunable
		do
		ensure then -- from SET
			removed_count_change: old has (v) implies (count = old count - 1)
			not_removed_no_count_change: not old has (v) implies (count = old count)
			item_deleted: not has (v)
		end
	
feature {NONE} -- Implementation

	on_change
			-- Called when interval changes.
		do
			if attached opo_change_actions as a then
				a.call
			end
		end

	opo_change_actions: detachable ACTION_SEQUENCE
			-- Once per object implementation for change_actions
	
feature -- Event handling

	change_actions: ACTION_SEQUENCE
			-- Actions performed when interval changes.
		do
			Result := opo_change_actions
			if Result = Void then
				create Result
				opo_change_actions := Result
			end
		ensure
			not_void: Result /= Void
		end
	
feature -- Iteration

	do_all (action: PROCEDURE [INTEGER_32])
			-- Apply action to every item of current interval.
			-- (from INTEGER_INTERVAL)
		require -- from INTEGER_INTERVAL
			action_exists: action /= Void
			finite: Upper_defined and Lower_defined
		local
			i, nb: INTEGER_32
		do
			from
				i := lower
				nb := upper
			until
				i > nb
			loop
				action.call ([i])
				i := i + 1
			end
		end

	exists (condition: FUNCTION [INTEGER_32, BOOLEAN]): BOOLEAN
			-- Does at least one of  interval's values
			-- satisfy condition?
			-- (from INTEGER_INTERVAL)
		require -- from INTEGER_INTERVAL
			finite: Upper_defined and Lower_defined
			condition_not_void: condition /= Void
		local
			i: INTEGER_32
		do
			from
				i := lower
			until
				i > upper or else condition.item ([i])
			loop
				i := i + 1
			end
			Result := i <= upper
		ensure -- from INTEGER_INTERVAL
			consistent_with_count: Result = (hold_count (condition) > 0)
		end

	exists1 (condition: FUNCTION [INTEGER_32, BOOLEAN]): BOOLEAN
			-- Does exactly one of  interval's values
			-- satisfy condition?
			-- (from INTEGER_INTERVAL)
		require -- from INTEGER_INTERVAL
			finite: Upper_defined and Lower_defined
			condition_not_void: condition /= Void
		do
			Result := hold_count (condition) = 1
		ensure -- from INTEGER_INTERVAL
			consistent_with_count: Result = (hold_count (condition) = 1)
		end

	for_all (condition: FUNCTION [INTEGER_32, BOOLEAN]): BOOLEAN
			-- Do all interval's values satisfy condition?
			-- (from INTEGER_INTERVAL)
		require -- from INTEGER_INTERVAL
			finite: Upper_defined and Lower_defined
			condition_not_void: condition /= Void
		local
			i: INTEGER_32
		do
			from
				Result := True
				i := lower
			until
				(i > upper) or else (not condition.item ([i]))
			loop
				i := i + 1
			end
			Result := i > upper
		ensure -- from INTEGER_INTERVAL
			consistent_with_count: Result = (hold_count (condition) = count)
		end

	hold_count (condition: FUNCTION [INTEGER_32, BOOLEAN]): INTEGER_32
			-- Number of  interval's values that
			-- satisfy condition
			-- (from INTEGER_INTERVAL)
		require -- from INTEGER_INTERVAL
			finite: Upper_defined and Lower_defined
			condition_not_void: condition /= Void
		local
			i: INTEGER_32
		do
			from
				i := lower
			until
				i > upper
			loop
				if condition.item ([i]) then
					Result := Result + 1
				end
				i := i + 1
			end
		ensure -- from INTEGER_INTERVAL
			non_negative: Result >= 0
		end
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		do
			Result := tagged_out
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
invariant
		-- from INTEGER_INTERVAL
	count_definition: Upper_defined and Lower_defined implies count = upper - lower + 1
	not_infinite: Upper_defined and Lower_defined

		-- from RESIZABLE
	increase_by_at_least_one: Minimal_increase >= 1

		-- from BOUNDED
	valid_count: count <= capacity
	full_definition: full = (count = capacity)

		-- from FINITE
	empty_definition: is_empty = (count = 0)

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

		-- from READABLE_INDEXABLE
	consistent_boundaries: lower <= upper or else lower = upper + 1

note
	library: "EiffelBase: Library of reusable components for Eiffel."
	copyright: "Copyright (c) 1984-2017, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class ACTIVE_INTEGER_INTERVAL

Generated by ISE EiffelStudio