func (as *AttributeSource) Clear() {
	for state := as.currentState(); state != nil; state = state.next {
		state.attribute.Clear()
	}
}
/*
Resets all Attributes in this AttributeSource by calling
AttributeImpl.clear() on each Attribute implementation.
package util
import (
	"reflect"
)
type Attribute interface {
}
type AttributeImpl interface {
	Interfaces() []string
	Clone() AttributeImpl
	Clear()
	CopyTo(target AttributeImpl)
}
type AttributeFactory interface {
	Create(string) AttributeImpl
}
type AttributeState struct {
	attribute AttributeImpl
	next      *AttributeState
}
func (s *AttributeState) Clone() *AttributeState {
	ans := new(AttributeState)
	ans.attribute = s.attribute.Clone()
	if s.next != nil {
		ans.next = s.next.Clone()
	}
	return ans
}
type AttributeSource struct {
	attributes     map[string]AttributeImpl
	attributeImpls map[reflect.Type]AttributeImpl
	_currentState  []*AttributeState
	factory        AttributeFactory
}
func NewAttributeSourceFrom(input *AttributeSource) *AttributeSource {
	assert2(input != nil, "input AttributeSource must not be null")
	return &AttributeSource{
		attributes:     input.attributes,
		attributeImpls: input.attributeImpls,
		_currentState:  input._currentState,
		factory:        input.factory,
	}
}
func NewAttributeSourceWith(factory AttributeFactory) *AttributeSource {
	return &AttributeSource{
		attributes:     make(map[string]AttributeImpl),
		attributeImpls: make(map[reflect.Type]AttributeImpl),
		_currentState:  make([]*AttributeState, 1),
		factory:        factory,
	}
}
func (as *AttributeSource) AddImpl(att AttributeImpl) {
	typ := reflect.TypeOf(att)
	if _, ok := as.attributeImpls[typ]; ok {
		return
	}
	for _, curInterface := range att.Interfaces() {
		if _, ok := as.attributes[curInterface]; !ok {
			as._currentState[0] = nil
			as.attributes[curInterface] = att
			as.attributeImpls[typ] = att
		}
	}
}
func (as *AttributeSource) hasAny() bool {
	return len(as.attributes) > 0
}
func (as *AttributeSource) Has(s string) bool {
	_, ok := as.attributes[s]
	return ok
}
func (as *AttributeSource) Add(s string) Attribute {
	attImpl, ok := as.attributes[s]
	if !ok {
		attImpl = as.factory.Create(s)
		as.AddImpl(attImpl)
	}
	return attImpl
}
func (as *AttributeSource) Get(s string) Attribute {
	return as.attributes[s]
}
func (as *AttributeSource) currentState() *AttributeState {
	s := as._currentState[0]
	if s != nil || !as.hasAny() {
		return s
	}
	s = new(AttributeState)
	var c *AttributeState
	for _, v := range as.attributeImpls {
		if c == nil {
			c = s
			c.attribute = v
		} else {
			c.next = &AttributeState{attribute: v}
			c = c.next
		}
	}
	return s
}
func (as *AttributeSource) CaptureState() (state *AttributeState) {
	if state = as.currentState(); state != nil {
		state = state.Clone()
	}
	return
}
func (as *AttributeSource) RestoreState(state *AttributeState) {
	if state == nil {
		return
	}
	for {
		targetImpl, ok := as.attributeImpls[reflect.TypeOf(state.attribute)]
		assert2(ok,
			"State contains AttributeImpl of type %v that is not in in this AttributeSource",
			reflect.TypeOf(state.attribute).Name())
		state.attribute.CopyTo(targetImpl)
		state = state.next
		if state == nil {
			break
		}
	}
}