--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.MandatoryEffectiveStatement;
+
+abstract class EmptyMandatoryEffectiveStatement implements MandatoryEffectiveStatement {
+ static final EmptyMandatoryEffectiveStatement FALSE = new EmptyMandatoryEffectiveStatement() {
+ @Override
+ public MandatoryStatement getDeclared() {
+ return EmptyMandatoryStatement.FALSE;
+ }
+ };
+
+ static final EmptyMandatoryEffectiveStatement TRUE = new EmptyMandatoryEffectiveStatement() {
+ @Override
+ public MandatoryStatement getDeclared() {
+ return EmptyMandatoryStatement.TRUE;
+ }
+ };
+
+ private EmptyMandatoryEffectiveStatement() {
+ // Hidden
+ }
+
+ @Override
+ public final StatementDefinition statementDefinition() {
+ return getDeclared().statementDefinition();
+ }
+
+ @Override
+ public final Boolean argument() {
+ return getDeclared().argument();
+ }
+
+ @Override
+ public final StatementSource getStatementSource() {
+ return getDeclared().getStatementSource();
+ }
+
+ @Override
+ public final <K, V, N extends IdentifierNamespace<K, V>> V get(final Class<N> namespace, final K identifier) {
+ throw new UnsupportedOperationException("Not implemented yet.");
+ }
+
+ @Override
+ public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(final Class<N> namespace) {
+ throw new UnsupportedOperationException("Not implemented yet.");
+ }
+
+ @Override
+ public final Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return ImmutableList.of();
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Objects;
+import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+
+abstract class EmptyMandatoryStatement implements MandatoryStatement {
+ static final MandatoryStatement FALSE = new EmptyMandatoryStatement() {
+ @Override
+ public Boolean getValue() {
+ return Boolean.FALSE;
+ }
+
+ @Override
+ EffectiveStatement<Boolean, MandatoryStatement> toEffective() {
+ return EmptyMandatoryEffectiveStatement.FALSE;
+ }
+ };
+
+ static final MandatoryStatement TRUE = new EmptyMandatoryStatement() {
+ @Override
+ public Boolean getValue() {
+ return Boolean.TRUE;
+ }
+
+ @Override
+ EffectiveStatement<Boolean, MandatoryStatement> toEffective() {
+ return EmptyMandatoryEffectiveStatement.TRUE;
+ }
+ };
+
+ private EmptyMandatoryStatement() {
+ // Invisible on purpose
+ }
+
+ abstract EffectiveStatement<Boolean, MandatoryStatement> toEffective();
+
+ @Override
+ public final Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public final StatementDefinition statementDefinition() {
+ return Rfc6020Mapping.MANDATORY;
+ }
+
+ @Override
+ public final String rawArgument() {
+ return getValue().toString();
+ }
+
+ @Override
+ public final Boolean argument() {
+ return getValue();
+ }
+
+ @Override
+ public final StatementSource getStatementSource() {
+ return StatementSource.DECLARATION;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(statementDefinition(), getStatementSource(), argument(),
+ rawArgument(), declaredSubstatements(), getValue());
+ }
+
+ @Override
+ public final boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof MandatoryStatement)) {
+ return false;
+ }
+
+ final MandatoryStatement other = (MandatoryStatement) obj;
+
+ return argument().equals(other.argument()) &&
+ rawArgument().equals(other.rawArgument()) &&
+ getValue().equals(other.getValue()) &&
+ statementDefinition().equals(other.statementDefinition()) &&
+ getStatementSource().equals(other.getStatementSource()) &&
+ declaredSubstatements().equals(other.declaredSubstatements());
+ }
+}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.MandatoryEffectiveStatementImpl;
-
+import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.MandatoryEffectiveStatementImpl;
-public class MandatoryStatementImpl extends AbstractDeclaredStatement<Boolean> implements
- MandatoryStatement {
+public class MandatoryStatementImpl extends AbstractDeclaredStatement<Boolean> implements MandatoryStatement {
- protected MandatoryStatementImpl(
- StmtContext<Boolean, MandatoryStatement, ?> context) {
+ protected MandatoryStatementImpl(final StmtContext<Boolean, MandatoryStatement, ?> context) {
super(context);
}
- public static class Definition extends AbstractStatementSupport<Boolean,MandatoryStatement,EffectiveStatement<Boolean,MandatoryStatement>> {
+ public static class Definition extends
+ AbstractStatementSupport<Boolean, MandatoryStatement, EffectiveStatement<Boolean, MandatoryStatement>> {
public Definition() {
super(Rfc6020Mapping.MANDATORY);
}
- @Override public Boolean parseArgumentValue(
- StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ @Override
+ public Boolean parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
return Boolean.valueOf(value);
}
- @Override public MandatoryStatement createDeclared(
- StmtContext<Boolean, MandatoryStatement, ?> ctx) {
- return new MandatoryStatementImpl(ctx);
+ @Override
+ public MandatoryStatement createDeclared(final StmtContext<Boolean, MandatoryStatement, ?> ctx) {
+ final MandatoryStatement ret = new MandatoryStatementImpl(ctx);
+ if (EmptyMandatoryStatement.FALSE.equals(ret)) {
+ return EmptyMandatoryStatement.FALSE;
+ } else if (EmptyMandatoryStatement.TRUE.equals(ret)) {
+ return EmptyMandatoryStatement.TRUE;
+ } else {
+ return ret;
+ }
}
- @Override public EffectiveStatement<Boolean, MandatoryStatement> createEffective(
- StmtContext<Boolean, MandatoryStatement, EffectiveStatement<Boolean, MandatoryStatement>> ctx) {
- return new MandatoryEffectiveStatementImpl(ctx);
+ @Override
+ public EffectiveStatement<Boolean, MandatoryStatement> createEffective(
+ final StmtContext<Boolean, MandatoryStatement, EffectiveStatement<Boolean, MandatoryStatement>> ctx) {
+ final EffectiveStatement<Boolean, MandatoryStatement> ret = new MandatoryEffectiveStatementImpl(ctx);
+ final MandatoryStatement declared = ret.getDeclared();
+ if (declared instanceof EmptyMandatoryStatement && ret.effectiveSubstatements().isEmpty()) {
+ return ((EmptyMandatoryStatement)declared).toEffective();
+ }
+ return ret;
}
}
- @Nonnull @Override
- public Boolean getValue() {
+ @Override
+ @Nonnull public Boolean getValue() {
return argument();
}
}
maxElements = Integer.valueOf(maxElementsArg);
}
- final MandatoryEffectiveStatementImpl firstMandatoryStmt = parent
- .firstEffective(MandatoryEffectiveStatementImpl.class);
+ final MandatoryEffectiveStatement firstMandatoryStmt = parent.firstEffective(MandatoryEffectiveStatement.class);
final boolean mandatory = (firstMandatoryStmt == null) ? minElements > 0 : firstMandatoryStmt.argument();
final Set<MustDefinition> mustSubstatements = ImmutableSet.copyOf(parent.allSubstatementsOfType(
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+
+public interface MandatoryEffectiveStatement extends EffectiveStatement<Boolean, MandatoryStatement> {
+
+}
import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public final class MandatoryEffectiveStatementImpl extends EffectiveStatementBase<Boolean, MandatoryStatement> {
+public final class MandatoryEffectiveStatementImpl extends EffectiveStatementBase<Boolean, MandatoryStatement>
+ implements MandatoryEffectiveStatement {
public MandatoryEffectiveStatementImpl(final StmtContext<Boolean, MandatoryStatement, ?> ctx) {
super(ctx);
}
-}
\ No newline at end of file
+}