2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.model.api.meta;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.common.QName;
20 * Default implementation of the {@link StatementDefinition} contract. Instances of this class should be used as
21 * well-known singletons.
23 * @author Robert Varga
25 * @param <A> Argument type
26 * @param <D> Declared statement representation
27 * @param <E> Effective statement representation
31 public final class DefaultStatementDefinition<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
32 extends AbstractStatementDefinition {
33 private final Class<E> effectiveRepresentation;
34 private final Class<D> declaredRepresentation;
36 DefaultStatementDefinition(final QName statementName, final Class<D> declaredRepresentation,
37 final Class<E> effectiveRepresentation, final boolean argumentYinElement,
38 final @Nullable QName argumentName) {
39 super(statementName, argumentYinElement, argumentName);
40 this.declaredRepresentation = requireNonNull(declaredRepresentation);
41 this.effectiveRepresentation = requireNonNull(effectiveRepresentation);
43 checkArgument(declaredRepresentation.isInterface(), "Declared representation %s is not an interface",
44 declaredRepresentation);
45 checkArgument(effectiveRepresentation.isInterface(), "Effective representation %s is not an interface",
46 effectiveRepresentation);
49 public static <A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
50 DefaultStatementDefinition<A, D, E> of(final QName statementName, final Class<D> declaredRepresentation,
51 final Class<E> effectiveRepresentation) {
52 return new DefaultStatementDefinition<>(statementName, declaredRepresentation, effectiveRepresentation, false,
56 public static <A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
57 DefaultStatementDefinition<A, D, E> of(final QName statementName, final Class<D> declaredRepresentation,
58 final Class<E> effectiveRepresentation, final QName argumentName) {
59 return of(statementName, declaredRepresentation, effectiveRepresentation, argumentName, false);
62 public static <A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
63 DefaultStatementDefinition<A, D, E> of(final QName statementName, final Class<D> declaredRepresentation,
64 final Class<E> effectiveRepresentation, final QName argumentName,
65 final boolean argumentYinElement) {
66 return new DefaultStatementDefinition<>(statementName, declaredRepresentation, effectiveRepresentation,
67 argumentYinElement, requireNonNull(argumentName));
71 public Class<? extends DeclaredStatement<?>> getDeclaredRepresentationClass() {
72 return declaredRepresentation;
76 public Class<? extends EffectiveStatement<?, ?>> getEffectiveRepresentationClass() {
77 return effectiveRepresentation;
81 protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
82 return super.addToStringAttributes(helper)
83 .add("declared", declaredRepresentation)
84 .add("effective", effectiveRepresentation);