go.temporal.io/server/common/predicates/and.go

121 LOC · 59 covered · 62 uncovered · 27 ranges · 61 concepts · 18 introducers · 29 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the fileTestMergeWithSlice_SameRange · 0 introduced LOCTestMergeWithSlice_SameR…slice.go ×1 · 8 introduced LOCslice.go ×1TestMergeWithSlice_SameMaxKey · 0 introduced LOCTestMergeWithSlice_SameM…TestMergeWithSlice_SameMinKey · 0 introduced LOCTestMergeWithSlice_SameM…slice.go ×1 · 5 introduced LOCslice.go ×1slice.go ×2 · 7 introduced LOCslice.go ×2slice.go ×2 · 26 introduced LOCslice.go ×2slice.go ×6 · 23 introduced LOCslice.go ×6slice.go ×1 · 2 introduced LOCslice.go ×1slice.go ×1 · 7 introduced LOCslice.go ×1slice.go ×1 · 4 introduced LOCslice.go ×1convert.go ×4 · 22 introduced LOCconvert.go ×4TestConvertPredicate_And · 0 introduced LOCTestConvertPredicate_AndTestConvertPredicate_Or · 0 introduced LOCTestConvertPredicate_OrTestMergeByPredicate_DifferentPredicateType · 0 introduced LOCTestMergeByPredicate_Dif…TestSplitByPredicate_DifferentPredicateType · 0 introduced LOCTestSplitByPredicate_Dif…convert.go ×10 · 56 introduced LOCconvert.go ×10predicates.go ×7 · 35 introduced LOCpredicates.go ×7predicates.go ×3 · 36 introduced LOCpredicates.go ×3predicates.go ×1 · 1 introduced LOCpredicates.go ×1predicates.go ×1 · 1 introduced LOCpredicates.go ×1and.go ×1 · 2 introduced LOCand.go ×1or.go ×1 · 2 introduced LOCor.go ×1and.go ×2 · 4 introduced LOCand.go ×2and.go ×1 · 1 introduced LOCand.go ×1TestUniversal_Equals · 0 introduced LOCTestUniversal_Equalsempty.go ×1 · 4 introduced LOCempty.go ×1not.go ×1 · 6 introduced LOCnot.go ×1and.go ×2 · 2 introduced LOCand.go ×2or.go ×2 · 4 introduced LOCor.go ×2and.go ×2 · 6 introduced LOCand.go ×2TestAnd_Duplication · 0 introduced LOCTestAnd_DuplicationTestAnd_Normal · 0 introduced LOCTestAnd_NormalTestOr_Duplication · 0 introduced LOCTestOr_DuplicationTestOr_Normal · 0 introduced LOCTestOr_Normaland.go ×1 · 2 introduced LOCand.go ×1or.go ×2 · 4 introduced LOCor.go ×2and.go ×2 · 6 introduced LOCand.go ×2and.go ×2 · 6 introduced LOCand.go ×2or.go ×1 · 1 introduced LOCor.go ×1or.go ×2 · 6 introduced LOCor.go ×2and.go ×1 · 2 introduced LOCand.go ×1or.go ×1 · 2 introduced LOCor.go ×1or.go ×1 · 5 introduced LOCor.go ×1TestAnd_None · 0 introduced LOCTestAnd_NoneTestOr_All · 0 introduced LOCTestOr_Alland.go ×1 · 4 introduced LOCand.go ×1and.go ×1 · 2 introduced LOCand.go ×1or.go ×1 · 4 introduced LOCor.go ×1and.go ×1 · 2 introduced LOCand.go ×1and.go ×1 · 2 introduced LOCand.go ×1or.go ×1 · 2 introduced LOCor.go ×1and.go ×1 · 1 introduced LOCand.go ×1or.go ×1 · 2 introduced LOCor.go ×1or.go ×1 · 1 introduced LOCor.go ×1and.go ×3 · 7 introduced LOCand.go ×3or.go ×1 · 2 introduced LOCor.go ×1and.go ×1 · 1 introduced LOCand.go ×1or.go ×2 · 5 introduced LOCor.go ×2and.go ×1 · 1 introduced LOCand.go ×1and.go ×3 · 8 introduced LOCand.go ×3TestAnd_All · introduced test · go.temporal.io/server/common/predicates/TestAndSuite/TestAnd_AllTestAnd_AllTestAnd_Duplication · introduced test · go.temporal.io/server/common/predicates/TestAndSuite/TestAnd_DuplicationTestAnd_DuplicationTestAnd_Equals · introduced test · go.temporal.io/server/common/predicates/TestAndSuite/TestAnd_EqualsTestAnd_EqualsTestAnd_None · introduced test · go.temporal.io/server/common/predicates/TestAndSuite/TestAnd_NoneTestAnd_NoneTestAnd_Normal · introduced test · go.temporal.io/server/common/predicates/TestAndSuite/TestAnd_NormalTestAnd_NormalTestAnd_Size · introduced test · go.temporal.io/server/common/predicates/TestAndSuite/TestAnd_SizeTestAnd_SizeTestEmpty_Equals · introduced test · go.temporal.io/server/common/predicates/TestNoneSuite/TestEmpty_EqualsTestEmpty_EqualsTestNot_Equals · introduced test · go.temporal.io/server/common/predicates/TestNotSuite/TestNot_EqualsTestNot_EqualsTestOr_All · introduced test · go.temporal.io/server/common/predicates/TestOrSuite/TestOr_AllTestOr_AllTestOr_Duplication · introduced test · go.temporal.io/server/common/predicates/TestOrSuite/TestOr_DuplicationTestOr_DuplicationTestOr_Equals · introduced test · go.temporal.io/server/common/predicates/TestOrSuite/TestOr_EqualsTestOr_EqualsTestOr_None · introduced test · go.temporal.io/server/common/predicates/TestOrSuite/TestOr_NoneTestOr_NoneTestOr_Normal · introduced test · go.temporal.io/server/common/predicates/TestOrSuite/TestOr_NormalTestOr_NormalTestOr_Size · introduced test · go.temporal.io/server/common/predicates/TestOrSuite/TestOr_SizeTestOr_SizeTestUniversal_Equals · introduced test · go.temporal.io/server/common/predicates/TestUniversalSuite/TestUniversal_EqualsTestUniversal_EqualsTestConvertPredicate_And · introduced test · go.temporal.io/server/service/history/queues/TestConvertSuite/TestConvertPredicate_AndTestConvertPredicate_AndTestConvertPredicate_Not · introduced test · go.temporal.io/server/service/history/queues/TestConvertSuite/TestConvertPredicate_NotTestConvertPredicate_NotTestConvertPredicate_Or · introduced test · go.temporal.io/server/service/history/queues/TestConvertSuite/TestConvertPredicate_OrTestConvertPredicate_OrTestMergeByPredicate_DifferentPredicateType · introduced test · go.temporal.io/server/service/history/queues/TestScopeSuite/TestMergeByPredicate_DifferentPredicateTypeTestMergeByPredicate_Dif…TestSplitByPredicate_DifferentPredicateType · introduced test · go.temporal.io/server/service/history/queues/TestScopeSuite/TestSplitByPredicate_DifferentPredicateTypeTestSplitByPredicate_Dif…TestCompactWithSlice · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestCompactWithSliceTestCompactWithSliceTestMergeWithSlice_DifferentMinMaxKey · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestMergeWithSlice_DifferentMinMaxKeyTestMergeWithSlice_Diffe…TestMergeWithSlice_MaxPredicateSizeApplied · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestMergeWithSlice_MaxPredicateSizeAppliedTestMergeWithSlice_MaxPr…TestMergeWithSlice_SameMaxKey · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestMergeWithSlice_SameMaxKeyTestMergeWithSlice_SameM…TestMergeWithSlice_SameMinKey · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestMergeWithSlice_SameMinKeyTestMergeWithSlice_SameM…TestMergeWithSlice_SameRange · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestMergeWithSlice_SameRangeTestMergeWithSlice_SameR…TestSplitByPredicate · introduced test · go.temporal.io/server/service/history/queues/TestSliceSuite/TestSplitByPredicateTestSplitByPredicateTestAndPredicates · introduced test · go.temporal.io/server/service/history/tasks/TestPredicateSuite/TestAndPredicatesTestAndPredicatesTestOrPredicates · introduced test · go.temporal.io/server/service/history/tasks/TestPredicateSuite/TestOrPredicatesTestOrPredicatesFocused file · go.temporal.io/server/common/predicates/and.go · 121 LOCpredicates/and.go

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package predicates
2
3 import (
4 "fmt"
5 )
6
7 type (
8 AndImpl[T any] struct {
9 // TODO: see if we can somehow order arbitrary predicats and store a sorted list
10 Predicates []Predicate[T]
11 }
12 )
13
14 func And[T any](
15 predicates ...Predicate[T],
16 > ) Predicate[T] { and.go ×3
17 > if len(predicates) < 2 {
18 panic(fmt.Sprintf("And requires at least 2 predicates, got %v", len(predicates)))
19 }
20
21 > flattened := make([]Predicate[T], 0, len(predicates)) and.go ×3
22 > for _, p := range predicates {
23 > switch p := p.(type) {
24 > case *AndImpl[T]: and.go ×1
25 > flattened = appendPredicates(flattened, p.Predicates...)
26 > case *UniversalImpl[T]: and.go ×1
27 > continue
28 > case *EmptyImpl[T]: and.go ×1
29 > return p
30 > default: and.go ×3
31 > flattened = appendPredicates(flattened, p)
32 }
33 }
34
35 > switch len(flattened) { and.go ×1
36 > case 0: and.go ×1
37 > return Universal[T]()
38 > case 1: and.go ×1
39 > return flattened[0]
40 > default: and.go ×1
41 > return &AndImpl[T]{
42 > Predicates: flattened,
43 > }
44 }
45 }
46
47 > func (a *AndImpl[T]) Test(t T) bool { and.go ×2
48 > for _, p := range a.Predicates {
49 > if !p.Test(t) {
50 > return false
51 > }
52 }
53
54 > return true and.go ×2
55 }
56
57 func (a *AndImpl[T]) Equals(
58 predicate Predicate[T],
59 > ) bool { and.go ×2
60 > andPredicate, ok := predicate.(*AndImpl[T])
61 > if !ok {
62 > return false and.go ×1
63 > }
64
65 > return predicatesEqual(a.Predicates, andPredicate.Predicates) and.go ×2
66 }
67
68 > func (a *AndImpl[T]) Size() int { and.go ×2
69 > size := EmptyPredicateProtoSize
70 > for _, p := range a.Predicates {
71 > size += p.Size()
72 > }
73
74 > return size and.go ×2
75 }
76
77 // appendPredicates adds new predicates to the slice of existing predicates
78 // dropping any duplicated predicates where duplication is determined by Predicate.Equals.
79 // appendPredicates assumes that there's no duplication in new predicates.
80 func appendPredicates[T any](
81 current []Predicate[T],
82 new ...Predicate[T],
83 > ) []Predicate[T] { and.go ×3
84 > result := current
85 >
86 > AppendLoop:
87 > for _, newPredicate := range new {
88 > for _, currentPredicate := range current {
89 > if currentPredicate.Equals(newPredicate) { and.go ×1
90 > continue AppendLoop and.go ×1
91 }
92 }
93
94 > result = append(result, newPredicate) and.go ×3
95 }
96
97 > return result and.go ×3
98 }
99
100 // predicatesEqual assumes there's no duplication in the given slices of predicates
101 func predicatesEqual[T any](
102 this []Predicate[T],
103 that []Predicate[T],
104 > ) bool { and.go ×2
105 > if len(this) != len(that) {
106 return false
107 }
108
109 > MatchLoop: and.go ×2
110 > for _, thisPredicate := range this {
111 > for _, thatPredicate := range that {
112 > if thisPredicate.Equals(thatPredicate) {
113 > continue MatchLoop and.go ×2
114 }
115 }
116
117 > return false and.go ×1
118 }
119
120 > return true and.go ×2
121 }