blob: 442d814ed0a35ef4e7da3305242768572f7c1b97 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package labels
// Collection is a collection of labels used for comparing labels against a
// collection of labels
type Collection []Instance
// HasSubsetOf returns true if the input labels are a super set of one labels in a
// collection or if the tag collection is empty
func (c Collection) HasSubsetOf(that Instance) bool {
if len(c) == 0 {
return true
}
// prevent panic when that is nil
if len(that) == 0 {
return false
}
for _, this := range c {
if this.SubsetOf(that) {
return true
}
}
return false
}
// IsSupersetOf returns true if the input labels are a subset set of any set of labels in a
// collection
func (c Collection) IsSupersetOf(that Instance) bool {
if len(c) == 0 {
return len(that) == 0
}
for _, this := range c {
if that.SubsetOf(this) {
return true
}
}
return false
}