@@ -172,15 +172,15 @@ func (s *sharedEntryAttributes) GetDeviations(ch chan<- *types.DeviationEntry, a
172172 // if s is a presence container but has active childs, it should not be treated as a presence
173173 // container, hence the leafvariants should not be processed. For presence container with
174174 // childs the TypedValue.empty_val in the presence container is irrelevant.
175- if s .schema .GetContainer ().GetIsPresence () && len (s .filterActiveChoiceCaseChilds ( )) > 0 {
175+ if s .schema .GetContainer ().GetIsPresence () && len (s .GetChilds ( DescendMethodActiveChilds )) > 0 {
176176 return
177177 }
178178
179179 // calculate Deviation on the LeafVariants
180180 s .leafVariants .GetDeviations (ch , activeCase )
181181
182182 // get all active childs
183- activeChilds := s .filterActiveChoiceCaseChilds ( )
183+ activeChilds := s .GetChilds ( DescendMethodActiveChilds )
184184
185185 // iterate through all childs
186186 for cName , c := range s .getChildren () {
@@ -332,7 +332,7 @@ func (s *sharedEntryAttributes) GetListChilds() ([]Entry, error) {
332332 for level := 0 ; level < len (keys ); level ++ {
333333 for _ , e := range actualEntries {
334334 // add all children
335- for _ , c := range e .getChildren ( ) {
335+ for _ , c := range e .GetChilds ( DescendMethodAll ) {
336336 newEntries = append (newEntries , c )
337337 }
338338 }
@@ -369,7 +369,7 @@ func (s *sharedEntryAttributes) FilterChilds(keys map[string]string) ([]Entry, e
369369 // therefor we need to go through the processEntries List
370370 // and collect all the matching childs
371371 for _ , entry := range processEntries {
372- childs := entry .getChildren ( )
372+ childs := entry .GetChilds ( DescendMethodAll )
373373 matchEntry , childExists := childs [keyVal ]
374374 // so if such child, that matches the given filter value exists, we append it to the results
375375 if childExists {
@@ -380,7 +380,7 @@ func (s *sharedEntryAttributes) FilterChilds(keys map[string]string) ([]Entry, e
380380 // this is basically the wildcard case, so go through all childs and add them
381381 result = []Entry {}
382382 for _ , entry := range processEntries {
383- childs := entry .getChildren ( )
383+ childs := entry .GetChilds ( DescendMethodAll )
384384 for _ , v := range childs {
385385 // hence we add all the existing childs to the result list
386386 result = append (result , v )
@@ -430,7 +430,7 @@ func (s *sharedEntryAttributes) Walk(ctx context.Context, v EntryVisitor) error
430430 }
431431
432432 // trigger the execution on all childs
433- for _ , c := range s .childs . GetAll ( ) {
433+ for _ , c := range s .GetChilds ( v . Config (). descendMethod ) {
434434 err := c .Walk (ctx , v )
435435 if err != nil {
436436 return err
@@ -533,7 +533,7 @@ func (s *sharedEntryAttributes) canDelete() bool {
533533 }
534534
535535 // handle containers
536- for _ , c := range s .filterActiveChoiceCaseChilds ( ) {
536+ for _ , c := range s .GetChilds ( DescendMethodActiveChilds ) {
537537 canDelete := c .canDelete ()
538538 if ! canDelete {
539539 s .cacheCanDelete = utils .BoolPtr (false )
@@ -560,7 +560,7 @@ func (s *sharedEntryAttributes) shouldDelete() bool {
560560 // but a real delete should only be added if there is at least one shouldDelete() == true
561561 shouldDelete := false
562562
563- activeChilds := s .filterActiveChoiceCaseChilds ( )
563+ activeChilds := s .GetChilds ( DescendMethodActiveChilds )
564564 // if we have no active childs, we can and should delete.
565565 if len (s .choicesResolvers ) > 0 && len (activeChilds ) == 0 {
566566 canDelete = true
@@ -607,7 +607,7 @@ func (s *sharedEntryAttributes) remainsToExist() bool {
607607
608608 // handle containers
609609 childsRemain := false
610- for _ , c := range s .filterActiveChoiceCaseChilds ( ) {
610+ for _ , c := range s .GetChilds ( DescendMethodActiveChilds ) {
611611 childsRemain = c .remainsToExist ()
612612 if childsRemain {
613613 break
@@ -757,7 +757,7 @@ func (s *sharedEntryAttributes) NavigateSdcpbPath(ctx context.Context, pathElems
757757 }
758758 return entry .NavigateSdcpbPath (ctx , pathElems [1 :], false )
759759 default :
760- e , exists := s .filterActiveChoiceCaseChilds ( )[pathElems [0 ].Name ]
760+ e , exists := s .GetChilds ( DescendMethodActiveChilds )[pathElems [0 ].Name ]
761761 if ! exists {
762762 pth := & sdcpb.Path {Elem : pathElems }
763763 e , err = s .tryLoadingDefault (ctx , utils .ToStrings (pth , false , false ))
@@ -830,7 +830,7 @@ func (s *sharedEntryAttributes) Navigate(ctx context.Context, path []string, isR
830830 }
831831 return parent .Navigate (ctx , path [1 :], false , dotdotSkipKeys )
832832 default :
833- e , exists := s .filterActiveChoiceCaseChilds ( )[path [0 ]]
833+ e , exists := s .GetChilds ( DescendMethodActiveChilds )[path [0 ]]
834834 if ! exists {
835835 e , err = s .tryLoadingDefault (ctx , append (s .Path (), path ... ))
836836 if err != nil {
@@ -885,7 +885,7 @@ func (s *sharedEntryAttributes) GetHighestPrecedence(result LeafVariantSlice, on
885885 }
886886
887887 // continue with childs. Childs are part of choices, process only the "active" (highes precedence) childs
888- for _ , c := range s .filterActiveChoiceCaseChilds ( ) {
888+ for _ , c := range s .GetChilds ( DescendMethodActiveChilds ) {
889889 result = c .GetHighestPrecedence (result , onlyNewOrUpdated , includeDefaults )
890890 }
891891 return result
@@ -950,7 +950,7 @@ func (s *sharedEntryAttributes) Validate(ctx context.Context, resultChan chan<-
950950 // recurse the call to the child elements
951951 wg := sync.WaitGroup {}
952952 defer wg .Wait ()
953- for _ , c := range s .filterActiveChoiceCaseChilds ( ) {
953+ for _ , c := range s .GetChilds ( DescendMethodActiveChilds ) {
954954 wg .Add (1 )
955955 valFunc := func (x Entry ) {
956956 x .Validate (ctx , resultChan , statChan , vCfg )
@@ -1182,7 +1182,7 @@ func (s *sharedEntryAttributes) ImportConfig(ctx context.Context, t importer.Imp
11821182 return err
11831183 }
11841184 // if the child does not exist, create it
1185- if keyChild , exists = actualEntry .getChildren ( )[keyElemValue ]; ! exists {
1185+ if keyChild , exists = actualEntry .GetChilds ( DescendMethodAll )[keyElemValue ]; ! exists {
11861186 keyChild , err = newEntry (ctx , actualEntry , keyElemValue , s .treeContext )
11871187 if err != nil {
11881188 return err
@@ -1335,7 +1335,7 @@ func (s *sharedEntryAttributes) validateMandatoryWithKeys(ctx context.Context, l
13351335 // iterate over the attributes make sure any of these exists
13361336 for _ , attr := range attributes {
13371337 // first check if the mandatory value is set via the intent, e.g. part of the tree already
1338- v , existsInTree = s .filterActiveChoiceCaseChilds ( )[attr ]
1338+ v , existsInTree = s .GetChilds ( DescendMethodActiveChilds )[attr ]
13391339 // if exists and remains to Exist
13401340 if existsInTree && v .remainsToExist () {
13411341 // set success to true and break the loop
@@ -1358,7 +1358,7 @@ func (s *sharedEntryAttributes) validateMandatoryWithKeys(ctx context.Context, l
13581358 return
13591359 }
13601360
1361- for _ , c := range s .filterActiveChoiceCaseChilds ( ) {
1361+ for _ , c := range s .GetChilds ( DescendMethodActiveChilds ) {
13621362 c .validateMandatoryWithKeys (ctx , level - 1 , attributes , choiceName , resultChan )
13631363 }
13641364}
@@ -1411,7 +1411,7 @@ func (s *sharedEntryAttributes) FinishInsertionPhase(ctx context.Context) error
14111411
14121412 // recurse the call to all (active) entries within the tree.
14131413 // Thereby already using the choiceCaseResolver via filterActiveChoiceCaseChilds()
1414- for _ , child := range s .filterActiveChoiceCaseChilds ( ) {
1414+ for _ , child := range s .GetChilds ( DescendMethodActiveChilds ) {
14151415 err = child .FinishInsertionPhase (ctx )
14161416 if err != nil {
14171417 return err
@@ -1473,31 +1473,59 @@ func (s *sharedEntryAttributes) populateChoiceCaseResolvers(_ context.Context) e
14731473 return nil
14741474}
14751475
1476- // filterActiveChoiceCaseChilds returns the list of child elements. In case the Entry is
1477- // a container with a / multiple choices, the list of childs is filtered to only return the
1478- // cases that have the highest precedence.
1479- func (s * sharedEntryAttributes ) filterActiveChoiceCaseChilds () map [string ]Entry {
1476+ func (s * sharedEntryAttributes ) GetChilds (d DescendMethod ) EntryMap {
14801477 if s .schema == nil {
14811478 return s .childs .GetAll ()
14821479 }
14831480
1484- skipAttributesList := s .choicesResolvers .GetSkipElements ()
1485- // if there are no items that should be skipped, take a shortcut
1486- // and simply return all childs straight away
1487- if len (skipAttributesList ) == 0 {
1481+ switch d {
1482+ case DescendMethodAll :
14881483 return s .childs .GetAll ()
1489- }
1490- result := map [string ]Entry {}
1491- // optimization option: sort the slices and forward in parallel, lifts extra burden that the contains call holds.
1492- for childName , child := range s .childs .GetAll () {
1493- if slices .Contains (skipAttributesList , childName ) {
1494- continue
1484+ case DescendMethodActiveChilds :
1485+ skipAttributesList := s .choicesResolvers .GetSkipElements ()
1486+ // if there are no items that should be skipped, take a shortcut
1487+ // and simply return all childs straight away
1488+ if len (skipAttributesList ) == 0 {
1489+ return s .childs .GetAll ()
1490+ }
1491+ result := map [string ]Entry {}
1492+ // optimization option: sort the slices and forward in parallel, lifts extra burden that the contains call holds.
1493+ for childName , child := range s .childs .GetAll () {
1494+ if slices .Contains (skipAttributesList , childName ) {
1495+ continue
1496+ }
1497+ result [childName ] = child
14951498 }
1496- result [ childName ] = child
1499+ return result
14971500 }
1498- return result
1501+ return nil
14991502}
15001503
1504+ // // filterActiveChoiceCaseChilds returns the list of child elements. In case the Entry is
1505+ // // a container with a / multiple choices, the list of childs is filtered to only return the
1506+ // // cases that have the highest precedence.
1507+ // func (s *sharedEntryAttributes) filterActiveChoiceCaseChilds() map[string]Entry {
1508+ // if s.schema == nil {
1509+ // return s.childs.GetAll()
1510+ // }
1511+
1512+ // skipAttributesList := s.choicesResolvers.GetSkipElements()
1513+ // // if there are no items that should be skipped, take a shortcut
1514+ // // and simply return all childs straight away
1515+ // if len(skipAttributesList) == 0 {
1516+ // return s.childs.GetAll()
1517+ // }
1518+ // result := map[string]Entry{}
1519+ // // optimization option: sort the slices and forward in parallel, lifts extra burden that the contains call holds.
1520+ // for childName, child := range s.childs.GetAll() {
1521+ // if slices.Contains(skipAttributesList, childName) {
1522+ // continue
1523+ // }
1524+ // result[childName] = child
1525+ // }
1526+ // return result
1527+ // }
1528+
15011529// StringIndent returns the sharedEntryAttributes in its string representation
15021530// The string is intented according to the nesting level in the yang model
15031531func (s * sharedEntryAttributes ) StringIndent (result []string ) []string {
0 commit comments