|
| 1 | +/* |
| 2 | +Copyright 2019 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package schema |
| 18 | + |
| 19 | +// Equals returns true iff the two Schemas are equal. |
| 20 | +func (a Schema) Equals(b Schema) bool { |
| 21 | + if len(a.Types) != len(b.Types) { |
| 22 | + return false |
| 23 | + } |
| 24 | + for i := range a.Types { |
| 25 | + if !a.Types[i].Equals(b.Types[i]) { |
| 26 | + return false |
| 27 | + } |
| 28 | + } |
| 29 | + return true |
| 30 | +} |
| 31 | + |
| 32 | +// Equals returns true iff the two TypeRefs are equal. |
| 33 | +// |
| 34 | +// Note that two typerefs that have an equivalent type but where one is |
| 35 | +// inlined and the other is named, are not considered equal. |
| 36 | +func (a TypeRef) Equals(b TypeRef) bool { |
| 37 | + if (a.NamedType == nil) != (b.NamedType == nil) { |
| 38 | + return false |
| 39 | + } |
| 40 | + if a.NamedType != nil { |
| 41 | + if *a.NamedType != *b.NamedType { |
| 42 | + return false |
| 43 | + } |
| 44 | + //return true |
| 45 | + } |
| 46 | + return a.Inlined.Equals(b.Inlined) |
| 47 | +} |
| 48 | + |
| 49 | +// Equals returns true iff the two TypeDefs are equal. |
| 50 | +func (a TypeDef) Equals(b TypeDef) bool { |
| 51 | + if a.Name != b.Name { |
| 52 | + return false |
| 53 | + } |
| 54 | + return a.Atom.Equals(b.Atom) |
| 55 | +} |
| 56 | + |
| 57 | +// Equals returns true iff the two Atoms are equal. |
| 58 | +func (a Atom) Equals(b Atom) bool { |
| 59 | + if (a.Scalar == nil) != (b.Scalar == nil) { |
| 60 | + return false |
| 61 | + } |
| 62 | + if (a.List == nil) != (b.List == nil) { |
| 63 | + return false |
| 64 | + } |
| 65 | + if (a.Map == nil) != (b.Map == nil) { |
| 66 | + return false |
| 67 | + } |
| 68 | + switch { |
| 69 | + case a.Scalar != nil: |
| 70 | + return *a.Scalar == *b.Scalar |
| 71 | + case a.List != nil: |
| 72 | + return a.List.Equals(*b.List) |
| 73 | + case a.Map != nil: |
| 74 | + return a.Map.Equals(*b.Map) |
| 75 | + } |
| 76 | + return true |
| 77 | +} |
| 78 | + |
| 79 | +// Equals returns true iff the two Maps are equal. |
| 80 | +func (a Map) Equals(b Map) bool { |
| 81 | + if !a.ElementType.Equals(b.ElementType) { |
| 82 | + return false |
| 83 | + } |
| 84 | + if a.ElementRelationship != b.ElementRelationship { |
| 85 | + return false |
| 86 | + } |
| 87 | + if len(a.Fields) != len(b.Fields) { |
| 88 | + return false |
| 89 | + } |
| 90 | + for i := range a.Fields { |
| 91 | + if !a.Fields[i].Equals(b.Fields[i]) { |
| 92 | + return false |
| 93 | + } |
| 94 | + } |
| 95 | + if len(a.Unions) != len(b.Unions) { |
| 96 | + return false |
| 97 | + } |
| 98 | + for i := range a.Unions { |
| 99 | + if !a.Unions[i].Equals(b.Unions[i]) { |
| 100 | + return false |
| 101 | + } |
| 102 | + } |
| 103 | + return true |
| 104 | +} |
| 105 | + |
| 106 | +// Equals returns true iff the two Unions are equal. |
| 107 | +func (a Union) Equals(b Union) bool { |
| 108 | + if (a.Discriminator == nil) != (b.Discriminator == nil) { |
| 109 | + return false |
| 110 | + } |
| 111 | + if a.Discriminator != nil { |
| 112 | + if *a.Discriminator != *b.Discriminator { |
| 113 | + return false |
| 114 | + } |
| 115 | + } |
| 116 | + if a.DeduceInvalidDiscriminator != b.DeduceInvalidDiscriminator { |
| 117 | + return false |
| 118 | + } |
| 119 | + if len(a.Fields) != len(b.Fields) { |
| 120 | + return false |
| 121 | + } |
| 122 | + for i := range a.Fields { |
| 123 | + if !a.Fields[i].Equals(b.Fields[i]) { |
| 124 | + return false |
| 125 | + } |
| 126 | + } |
| 127 | + return true |
| 128 | +} |
| 129 | + |
| 130 | +// Equals returns true iff the two UnionFields are equal. |
| 131 | +func (a UnionField) Equals(b UnionField) bool { |
| 132 | + if a.FieldName != b.FieldName { |
| 133 | + return false |
| 134 | + } |
| 135 | + if a.DiscriminatorValue != b.DiscriminatorValue { |
| 136 | + return false |
| 137 | + } |
| 138 | + return true |
| 139 | +} |
| 140 | + |
| 141 | +// Equals returns true iff the two StructFields are equal. |
| 142 | +func (a StructField) Equals(b StructField) bool { |
| 143 | + if a.Name != b.Name { |
| 144 | + return false |
| 145 | + } |
| 146 | + return a.Type.Equals(b.Type) |
| 147 | +} |
| 148 | + |
| 149 | +// Equals returns true iff the two Lists are equal. |
| 150 | +func (a List) Equals(b List) bool { |
| 151 | + if !a.ElementType.Equals(b.ElementType) { |
| 152 | + return false |
| 153 | + } |
| 154 | + if a.ElementRelationship != b.ElementRelationship { |
| 155 | + return false |
| 156 | + } |
| 157 | + if len(a.Keys) != len(b.Keys) { |
| 158 | + return false |
| 159 | + } |
| 160 | + for i := range a.Keys { |
| 161 | + if a.Keys[i] != b.Keys[i] { |
| 162 | + return false |
| 163 | + } |
| 164 | + } |
| 165 | + return true |
| 166 | +} |
0 commit comments