浏览代码

IsEmpty helper function on Asset set Range

Sean Holcomb 4 年之前
父节点
当前提交
f3bd7922b4
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      pkg/kubecost/asset.go

+ 15 - 0
pkg/kubecost/asset.go

@@ -2970,6 +2970,21 @@ func (asr *AssetSetRange) InsertRange(that *AssetSetRange) error {
 	return err
 }
 
+// IsEmpty returns false if AssetSetRange contains a single AssetSet that is not empty
+func (asr *AssetSetRange) IsEmpty() bool {
+	if asr == nil || asr.Length() == 0 {
+		return true
+	}
+	asr.RLock()
+	defer asr.RUnlock()
+	for _, asset := range asr.assets {
+		if !asset.IsEmpty() {
+			return false
+		}
+	}
+	return true
+}
+
 func (asr *AssetSetRange) MarshalJSON() ([]byte, error) {
 	asr.RLock()
 	defer asr.RUnlock()