github.com/elfadel/cilium@v1.6.12/pkg/labels/arraylist.go (about)

     1  // Copyright 2018 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package labels
    16  
    17  // LabelArrayList is an array of LabelArrays. It is primarily intended as a
    18  // simple collection
    19  type LabelArrayList []LabelArray
    20  
    21  // DeepCopy returns a deep copy of the LabelArray, with each element also copied.
    22  func (ls LabelArrayList) DeepCopy() LabelArrayList {
    23  	if ls == nil {
    24  		return nil
    25  	}
    26  
    27  	o := make(LabelArrayList, 0, len(ls))
    28  	for _, v := range ls {
    29  		o = append(o, v.DeepCopy())
    30  	}
    31  	return o
    32  }
    33  
    34  // GetModel returns the LabelArrayList as a [][]string. Each member LabelArray
    35  // becomes a []string.
    36  func (ls LabelArrayList) GetModel() [][]string {
    37  	res := make([][]string, 0, len(ls))
    38  	for _, v := range ls {
    39  		res = append(res, v.GetModel())
    40  	}
    41  	return res
    42  }