mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #7509 from deads2k/deads-has-any
add StringSet.HasAny
This commit is contained in:
commit
c07896ee35
@ -75,6 +75,16 @@ func (s StringSet) HasAll(items ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasAny returns true if any items are contained in the set.
|
||||||
|
func (s StringSet) HasAny(items ...string) bool {
|
||||||
|
for _, item := range items {
|
||||||
|
if s.Has(item) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Difference returns a set of objects that are not in s2
|
// Difference returns a set of objects that are not in s2
|
||||||
// For example:
|
// For example:
|
||||||
// s1 = {1, 2, 3}
|
// s1 = {1, 2, 3}
|
||||||
|
@ -117,3 +117,15 @@ func TestStringSetDifference(t *testing.T) {
|
|||||||
t.Errorf("Unexpected contents: %#v", d.List())
|
t.Errorf("Unexpected contents: %#v", d.List())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStringSetHasAny(t *testing.T) {
|
||||||
|
a := NewStringSet("1", "2", "3")
|
||||||
|
|
||||||
|
if !a.HasAny("1", "4") {
|
||||||
|
t.Errorf("expected true, got false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.HasAny("0", "4") {
|
||||||
|
t.Errorf("expected false, got true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user