2 * Copyright (c) 2017 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.spi.source;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
16 * An implicit sub-statement, which is implied to be always present in its parent, even if it does not appear
19 * @author Robert Varga
22 public final class ImplicitSubstatement implements StatementSourceReference {
24 private final StatementSourceReference parentRef;
26 private ImplicitSubstatement(final StatementSourceReference parentRef) {
27 this.parentRef = requireNonNull(parentRef);
31 * Create a new {@link ImplicitSubstatement}.
33 * @param parentRef Parent source reference
34 * @return A new reference
35 * @throws NullPointerException if parentRef is null
37 public static ImplicitSubstatement of(final StatementSourceReference parentRef) {
38 return new ImplicitSubstatement(parentRef);
42 public StatementSource getStatementSource() {
43 return StatementSource.CONTEXT;
47 public int hashCode() {
48 return parentRef.hashCode();
52 public boolean equals(final Object obj) {
53 return obj instanceof ImplicitSubstatement && parentRef.equals(((ImplicitSubstatement) obj).parentRef);
57 public String toString() {
58 return parentRef.toString();