IsTupleFilterEmpty checks whether any of the fields in a TupleFilter are filled. It assumes that a filter is "empty" if all its fields are unset or have zero values.
(filter *base.TupleFilter)
| 109 | // IsTupleFilterEmpty checks whether any of the fields in a TupleFilter are filled. |
| 110 | // It assumes that a filter is "empty" if all its fields are unset or have zero values. |
| 111 | func IsTupleFilterEmpty(filter *base.TupleFilter) bool { |
| 112 | // If the entity type is set, the filter is not empty. |
| 113 | if filter.GetEntity().GetType() != "" { |
| 114 | return false // Entity type is present, therefore filter is not empty. |
| 115 | } |
| 116 | |
| 117 | // If the entity IDs slice is not empty, the filter is not empty. |
| 118 | if len(filter.GetEntity().GetIds()) > 0 { |
| 119 | return false // Entity IDs are present, therefore filter is not empty. |
| 120 | } |
| 121 | |
| 122 | // If the relation is set, the filter is not empty. |
| 123 | if filter.GetRelation() != "" { |
| 124 | return false // Relation is present, therefore filter is not empty. |
| 125 | } |
| 126 | |
| 127 | // If the subject type is set, the filter is not empty. |
| 128 | if filter.GetSubject().GetType() != "" { |
| 129 | return false // Subject type is present, therefore filter is not empty. |
| 130 | } |
| 131 | |
| 132 | // If the subject IDs slice is not empty, the filter is not empty. |
| 133 | if len(filter.GetSubject().GetIds()) > 0 { |
| 134 | return false // Subject IDs are present, therefore filter is not empty. |
| 135 | } |
| 136 | |
| 137 | // If the subject relation is set, the filter is not empty. |
| 138 | if filter.GetSubject().GetRelation() != "" { |
| 139 | return false // Subject relation is present, therefore filter is not empty. |
| 140 | } |
| 141 | |
| 142 | // If none of the above conditions are met, then all fields are unset or have zero values, |
| 143 | // which means the filter is empty. |
| 144 | return true |
| 145 | } |
| 146 | |
| 147 | // IsAttributeFilterEmpty checks if the provided AttributeFilter object is empty. |
| 148 | // An AttributeFilter is considered empty if none of its fields have been set. |
no test coverage detected