Populate ietf-restconf operations container
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / QNameWithFlagsEffectiveStatementState.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects.ToStringHelper;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
16
17 /**
18  * Simple {@link EffectiveStatementState} for use with typical {@link SchemaTreeEffectiveStatement}s. It differentiates
19  * on QName and an {@code int} flags field.
20  */
21 @Beta
22 public final class QNameWithFlagsEffectiveStatementState extends EffectiveStatementState {
23     private final QName qname;
24     private final int flags;
25
26     public QNameWithFlagsEffectiveStatementState(final QName qname, final int flags) {
27         this.qname = requireNonNull(qname);
28         this.flags = flags;
29     }
30
31     @Override
32     public int hashCode() {
33         return qname.hashCode() * 31 + Integer.hashCode(flags);
34     }
35
36     @Override
37     public boolean equals(final Object obj) {
38         if (obj == this) {
39             return true;
40         }
41         if (!(obj instanceof QNameWithFlagsEffectiveStatementState)) {
42             return false;
43         }
44         final var other = (QNameWithFlagsEffectiveStatementState) obj;
45         return flags == other.flags && qname.equals(other.qname);
46     }
47
48     @Override
49     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
50         return helper.add("qname", qname).add("flags", flags);
51     }
52 }