PageRenderTime 79ms CodeModel.GetById 76ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/restbuck_server/src/domain/order.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 104 lines | 88 code | 13 blank | 3 comment | 2 complexity | e4380cf83624c3f80c4cd4c251ba9f44 MD5 | raw file
  1note
  2	description: "Summary description for {ORDER}."
  3	author: ""
  4	date: "$Date$"
  5	revision: "$Revision$"
  6
  7class
  8	ORDER
  9create
 10	make
 11feature -- Initialization
 12	make ( an_id : STRING; a_location:STRING)
 13		do
 14			create {ARRAYED_LIST[ITEM]}items.make (10)
 15			set_id(an_id)
 16			set_location(a_location)
 17			status:="submitted"
 18		ensure
 19			order_created: is_valid_status_states (status)
 20		end
 21
 22feature -- Access
 23 	id : STRING
 24 	location : STRING
 25 	items: LIST[ITEM]
 26	status : STRING
 27	
 28	is_valid_status_states (a_status: STRING) : BOOLEAN
 29		--is `a_status' a valid coffee order state
 30		do
 31			a_status.to_lower
 32			Order_states.compare_objects
 33			Result := Order_states.has (a_status)
 34		end
 35
 36	Order_states : ARRAY[STRING]
 37		-- List of valid status states
 38		once
 39			Result := <<"submitted","pay","payed", "cancel","canceled","prepare","prepared","deliver","completed">>
 40		end
 41
 42	is_valid_transition (a_status : STRING) :BOOLEAN
 43		-- Given the correr order state, determine if the transition is valid
 44		do
 45			a_status.to_lower
 46			if status.same_string ("submitted") then
 47				Result := a_status.same_string ("pay") or  a_status.same_string ("cancel")
 48			elseif status.same_string ("pay") then
 49				Result := a_status.same_string ("payed")
 50			elseif status.same_string ("cancel") then
 51				Result := a_status.same_string ("canceled")
 52			elseif status.same_string ("payed") then
 53				Result := a_status.same_string ("prepared")
 54			elseif status.same_string ("prepared") then
 55				Result := a_status.same_string ("deliver")
 56			elseif status.same_string ("deliver") then
 57				Result := a_status.same_string ("completed")
 58			end
 59		end
 60
 61
 62feature -- element change
 63	set_id (an_id : STRING)
 64		require
 65		 	valid_id :an_id /= Void
 66		do
 67			id := an_id
 68		ensure
 69			id_assigned : id.same_string (an_id)
 70		end
 71
 72	set_location (a_location : STRING)
 73		require
 74			valid_location: a_location /= Void
 75		do
 76			location := a_location
 77		ensure
 78			location_assigned : location.same_string (a_location)
 79		end
 80
 81	set_status (a_status : STRING)
 82		require
 83			valid_status: a_status /= Void and then is_valid_status_states (a_status)
 84			valid_transition : is_valid_transition (a_status)
 85		do
 86			status := a_status
 87		ensure
 88			location_assigned : location.same_string (a_status)
 89		end
 90
 91
 92	add_item (a_item : ITEM)
 93		require
 94			valid_item:  a_item /= Void
 95		do
 96			items.force (a_item)
 97		ensure
 98			has_item : items.has (a_item)
 99		end
100
101invariant
102	order_in_valid_state: is_valid_status_states (status)
103
104end