github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/worker/uniter/relation/listsource.go (about)

     1  // Copyright 2012-2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package relation
     5  
     6  import (
     7  	"github.com/juju/juju/worker/uniter/hook"
     8  )
     9  
    10  type listSource struct {
    11  	NoUpdates
    12  	hooks []hook.Info
    13  }
    14  
    15  func (q *listSource) Empty() bool {
    16  	return len(q.hooks) == 0
    17  }
    18  
    19  func (q *listSource) Next() hook.Info {
    20  	if q.Empty() {
    21  		panic("HookSource is empty")
    22  	}
    23  	return q.hooks[0]
    24  }
    25  
    26  func (q *listSource) Pop() {
    27  	if q.Empty() {
    28  		panic("HookSource is empty")
    29  	}
    30  	q.hooks = q.hooks[1:]
    31  }
    32  
    33  // NewListSource returns a HookSource that generates only the supplied hooks, in
    34  // order; and which cannot be updated.
    35  func NewListSource(list []hook.Info) HookSource {
    36  	source := &listSource{hooks: make([]hook.Info, len(list))}
    37  	copy(source.hooks, list)
    38  	return source
    39  }