示例#1
0
文件: gfsm.go 项目: Focinfi/gfsm
// NewStateMachine return a pointer of new StateMachine
func NewStateMachine(states ...string) *StateMachine {
	stateE := make([]gset.Elementer, len(states))
	for i, state := range states {
		stateE[i] = gset.T(state)
	}
	stateSet := gset.NewSet(stateE...)
	return &StateMachine{make(map[string]*Event), stateSet}
}
示例#2
0
文件: gfsm.go 项目: Focinfi/gfsm
// Transition add transition for this event, error will not be nil
// if any state in to or froms does not exit
func (e *Event) Transition(to string, froms ...string) error {
	states := append(froms[:], to)

	for _, state := range states {
		if !e.sm.states.Has(gset.T(state)) {
			return fmt.Errorf("has not state: %s", state)
		}
	}

	e.to = to
	e.froms = froms
	return nil
}
示例#3
0
文件: model.go 项目: Focinfi/apifaker
// Delete deletes the LineItem and its related data with the given id
func (model *Model) Delete(id float64) {
	model.Lock()
	defer model.Unlock()

	li, ok := model.Get(id)

	if !ok {
		return
	}

	li.DeleteRelatedLis(id, model)
	model.Set.Remove(gset.T(id))
	model.dataChanged = true
	model.removeUniqueValues(li)
}
示例#4
0
文件: model.go 项目: Focinfi/apifaker
// Has returns if Model has LineItem with the given id
func (model *Model) Has(id float64) bool {
	return model.Set.Has(gset.T(id))
}