github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/analysis/attributeFactory.go (about) 1 package analysis 2 3 import ( 4 "github.com/balzaczyy/golucene/core/util" 5 ) 6 7 type myAttributeFactorySPI interface { 8 Create() interface{} 9 } 10 11 /* 12 Expert: AttributeFactory returning an instance of the given clazz for 13 the attributes it implements. For all other attributes it calls the 14 given delegate factory as fallback. This clas can be used to prefer a 15 specific AttributeImpl which combines multiple attributes over 16 separate classes. 17 */ 18 type myAttributeFactory struct { 19 delegate util.AttributeFactory 20 clazz map[string]bool 21 ctor func() util.AttributeImpl 22 } 23 24 func (f *myAttributeFactory) Create(name string) util.AttributeImpl { 25 if _, ok := f.clazz[name]; ok { 26 return f.ctor() 27 } 28 return f.delegate.Create(name) 29 } 30 31 /* 32 Returns an AttributeFactory returning an instance of the given clazz 33 for the attributes it implements. The given clazz must have a public 34 no-arg contructor. For all other attributes it calls the given 35 delegate factory as fallback. This method can be used to prefer a 36 specific AttributeImpl which combines multiple attributes over 37 separate classes. 38 39 Please save instances created by this method in a global field, 40 because on each call, this does 41 */ 42 func assembleAttributeFactory(factory util.AttributeFactory, 43 clazz map[string]bool, ctor func() util.AttributeImpl) util.AttributeFactory { 44 return &myAttributeFactory{factory, clazz, ctor} 45 }