2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import com.google.common.base.MoreObjects;
11 import java.util.Objects;
12 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
15 * Utility methods for ConstraintDefinition implementations.
17 final class ConstraintDefinitions {
18 private ConstraintDefinitions() {
19 throw new UnsupportedOperationException();
22 static int hashCode(final ConstraintDefinition def) {
25 result = prime * result + Objects.hashCode(def.getWhenCondition());
26 result = prime * result + Objects.hashCode(def.getMustConstraints());
27 result = prime * result + Objects.hashCode(def.getMinElements());
28 result = prime * result + Objects.hashCode(def.getMaxElements());
29 result = prime * result + Objects.hashCode(def.isMandatory());
33 static boolean equals(final ConstraintDefinition def, final Object obj) {
37 if (!(obj instanceof ConstraintDefinition)) {
40 final ConstraintDefinition other = (EffectiveConstraintDefinitionImpl) obj;
41 if (def.isMandatory() != other.isMandatory()) {
44 if (!Objects.equals(def.getWhenCondition(), other.getWhenCondition())) {
47 if (!Objects.equals(def.getMustConstraints(), other.getMustConstraints())) {
50 if (!Objects.equals(def.getMinElements(), other.getMinElements())) {
53 if (!Objects.equals(def.getMaxElements(), other.getMaxElements())) {
59 static String toString(final ConstraintDefinition def) {
60 return MoreObjects.toStringHelper(def).omitNullValues()
61 .add("whenCondition", def.getWhenCondition())
62 .add("mustConstraints", def.getMustConstraints())
63 .add("mandatory", def.isMandatory())
64 .add("minElements", def.getMinElements())
65 .add("maxElements", def.getMaxElements()).toString();