*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
-import static java.util.Objects.requireNonNull;
-
import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNull;
@Beta
-public abstract class AbstractBooleanDeclaredStatement extends AbstractDeclaredStatement<Boolean> {
- private final @NonNull Boolean argument;
-
+public abstract class AbstractBooleanDeclaredStatement extends AbstractDeclaredStatement.ArgumentToString<Boolean> {
protected AbstractBooleanDeclaredStatement(final Boolean argument) {
- this.argument = requireNonNull(argument);
- }
-
- @Override
- public final @NonNull Boolean argument() {
- return argument;
- }
-
- @Override
- public final String rawArgument() {
- return argument.toString();
+ super(argument);
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
import java.util.Collection;
return argument;
}
}
+
+ public abstract static class ArgumentToString<A> extends AbstractDeclaredStatement<A> {
+ private final @NonNull A argument;
+
+ protected ArgumentToString(final A argument) {
+ this.argument = requireNonNull(argument);
+ }
+
+ @Override
+ public final @NonNull A argument() {
+ return argument;
+ }
+
+ @Override
+ public final String rawArgument() {
+ return argument.toString();
+ }
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.rfc7950.stmt;
+
+import com.google.common.annotations.Beta;
+
+@Beta
+public abstract class AbstractIntegerDeclaredStatement extends AbstractDeclaredStatement<Integer> {
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.rfc7950.stmt;
+
+import com.google.common.annotations.Beta;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableList;
+import java.util.concurrent.ExecutionException;
+import org.eclipse.jdt.annotation.NonNull;
+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.parser.spi.meta.StmtContext;
+
+/**
+ * A {@link BaseStatementSupport} specialized for global interning. This base class is useful when the argument can be
+ * reasonably interned and it dominates the {@link EffectiveStatement} implementation. Typical examples include
+ * {@code position} and {@code value} statements, which typically do not have substatements and are based on simple
+ * types.
+ */
+@Beta
+public abstract class BaseInternedStatementSupport<A, D extends DeclaredStatement<A>,
+ E extends EffectiveStatement<A, D>> extends BaseStatementSupport<A, D, E> {
+ private final LoadingCache<A, D> declaredCache = CacheBuilder.newBuilder().weakValues()
+ .build(new CacheLoader<A, D>() {
+ @Override
+ public D load(final A key) {
+ return createEmptyDeclared(key);
+ }
+ });
+ private final LoadingCache<D, E> effectiveCache = CacheBuilder.newBuilder().weakValues()
+ .build(new CacheLoader<D, E>() {
+ @Override
+ public E load(final D key) throws ExecutionException {
+ return createEmptyEffective(key);
+ }
+ });
+
+ protected BaseInternedStatementSupport(final StatementDefinition publicDefinition) {
+ super(publicDefinition);
+ }
+
+ @Override
+ protected final D createEmptyDeclared(final StmtContext<A, D, ?> ctx) {
+ return declaredCache.getUnchecked(ctx.coerceStatementArgument());
+ }
+
+ protected abstract @NonNull D createEmptyDeclared(@NonNull A argument);
+
+ @Override
+ protected final E createEmptyEffective(final StmtContext<A, D, E> ctx, final D declared) {
+ return effectiveCache.getUnchecked(declared);
+ }
+
+ protected abstract @NonNull E createEmptyEffective(@NonNull D declared);
+
+ @Override
+ protected final D createDeclared(final StmtContext<A, D, ?> ctx,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return createDeclared(ctx.coerceStatementArgument(), substatements);
+ }
+
+ protected abstract @NonNull D createDeclared(@NonNull A argument,
+ ImmutableList<? extends DeclaredStatement<?>> substatements);
+}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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,
import org.opendaylight.yangtools.yang.model.api.stmt.PositionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement;
-final class PositionEffectiveStatementImpl extends DeclaredEffectiveStatementBase<Long, PositionStatement>
+abstract class AbstractPositionEffectiveStatement
+ extends AbstractDeclaredEffectiveStatement.DefaultArgument<Long, PositionStatement>
implements PositionEffectiveStatement {
- PositionEffectiveStatementImpl(final StmtContext<Long, PositionStatement, ?> ctx) {
- super(ctx);
+ AbstractPositionEffectiveStatement(final PositionStatement declared) {
+ super(declared);
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.rfc7950.stmt.position;
+
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.ArgumentToString;
+
+abstract class AbstractPositionStatement extends ArgumentToString<Long> implements PositionStatement {
+ AbstractPositionStatement(final Long argument) {
+ super(argument);
+ }
+
+ @Override
+ public StatementDefinition statementDefinition() {
+ return YangStmtMapping.POSITION;
+ }
+}
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.position;
import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class PositionStatementImpl extends AbstractDeclaredStatement<Long> implements PositionStatement {
- PositionStatementImpl(final StmtContext<Long, PositionStatement, ?> context) {
- super(context);
+final class EmptyPositionEffectiveStatement extends AbstractPositionEffectiveStatement {
+ EmptyPositionEffectiveStatement(final PositionStatement declared) {
+ super(declared);
}
}
--- /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.rfc7950.stmt.position;
+
+final class EmptyPositionStatement extends AbstractPositionStatement {
+ EmptyPositionStatement(final Long argument) {
+ super(argument);
+ }
+}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.position;
+import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.stmt.PositionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseInternedStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public final class PositionStatementSupport
- extends AbstractStatementSupport<Long, PositionStatement, PositionEffectiveStatement> {
+ extends BaseInternedStatementSupport<Long, PositionStatement, PositionEffectiveStatement> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
YangStmtMapping.POSITION).build();
private static final PositionStatementSupport INSTANCE = new PositionStatementSupport();
}
@Override
- public PositionStatement createDeclared(final StmtContext<Long, PositionStatement, ?> ctx) {
- return new PositionStatementImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
@Override
- public PositionEffectiveStatement createEffective(
- final StmtContext<Long, PositionStatement, PositionEffectiveStatement> ctx) {
- return new PositionEffectiveStatementImpl(ctx);
+ protected PositionStatement createDeclared(final Long argument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new RegularPositionStatement(argument, substatements);
}
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ protected PositionStatement createEmptyDeclared(final Long argument) {
+ return new EmptyPositionStatement(argument);
+ }
+
+ @Override
+ protected PositionEffectiveStatement createEmptyEffective(final PositionStatement declared) {
+ return new EmptyPositionEffectiveStatement(declared);
+ }
+
+ @Override
+ protected PositionEffectiveStatement createEffective(
+ final StmtContext<Long, PositionStatement, PositionEffectiveStatement> ctx,
+ final PositionStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new RegularPositionEffectiveStatement(declared, substatements);
}
}
\ No newline at end of file
--- /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.rfc7950.stmt.position;
+
+import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
+
+final class RegularPositionEffectiveStatement extends AbstractPositionEffectiveStatement {
+ private final @NonNull Object substatements;
+
+ RegularPositionEffectiveStatement(final PositionStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared);
+ this.substatements = maskList(substatements);
+ }
+
+ @Override
+ public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return unmaskList(substatements);
+ }
+}
--- /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.rfc7950.stmt.position;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+
+final class RegularPositionStatement extends AbstractPositionStatement {
+ private final @NonNull Object substatements;
+
+ RegularPositionStatement(final Long argument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(argument);
+ this.substatements = maskList(substatements);
+ }
+
+ @Override
+ public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
+ return unmaskList(substatements);
+ }
+}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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,
import org.opendaylight.yangtools.yang.model.api.stmt.ValueEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement;
-final class ValueEffectiveStatementImpl extends DeclaredEffectiveStatementBase<Integer, ValueStatement>
+abstract class AbstractValueEffectiveStatement
+ extends AbstractDeclaredEffectiveStatement.DefaultArgument<Integer, ValueStatement>
implements ValueEffectiveStatement {
- ValueEffectiveStatementImpl(final StmtContext<Integer, ValueStatement, ?> ctx) {
- super(ctx);
+ AbstractValueEffectiveStatement(final ValueStatement declared) {
+ super(declared);
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.rfc7950.stmt.value;
+
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.ArgumentToString;
+
+abstract class AbstractValueStatement extends ArgumentToString<Integer> implements ValueStatement {
+ AbstractValueStatement(final Integer argument) {
+ super(argument);
+ }
+
+ @Override
+ public StatementDefinition statementDefinition() {
+ return YangStmtMapping.VALUE;
+ }
+}
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.value;
import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class ValueStatementImpl extends AbstractDeclaredStatement<Integer> implements ValueStatement {
- ValueStatementImpl(final StmtContext<Integer, ValueStatement, ?> context) {
- super(context);
+final class EmptyValueEffectiveStatement extends AbstractValueEffectiveStatement {
+ EmptyValueEffectiveStatement(final ValueStatement declared) {
+ super(declared);
}
}
--- /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.rfc7950.stmt.value;
+
+final class EmptyValueStatement extends AbstractValueStatement {
+ EmptyValueStatement(final Integer argument) {
+ super(argument);
+ }
+}
--- /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.rfc7950.stmt.value;
+
+import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
+
+final class RegularValueEffectiveStatement extends AbstractValueEffectiveStatement {
+ private final @NonNull Object substatements;
+
+ RegularValueEffectiveStatement(final ValueStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ super(declared);
+ this.substatements = maskList(substatements);
+ }
+
+ @Override
+ public ImmutableList<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
+ return unmaskList(substatements);
+ }
+}
--- /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.rfc7950.stmt.value;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+
+final class RegularValueStatement extends AbstractValueStatement {
+ private final @NonNull Object substatements;
+
+ RegularValueStatement(final Integer argument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ super(argument);
+ this.substatements = maskList(substatements);
+ }
+
+ @Override
+ public Collection<? extends DeclaredStatement<?>> declaredSubstatements() {
+ return unmaskList(substatements);
+ }
+}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.value;
+import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+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.stmt.ValueEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ValueStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseInternedStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public final class ValueStatementSupport
- extends AbstractStatementSupport<Integer, ValueStatement, ValueEffectiveStatement> {
+ extends BaseInternedStatementSupport<Integer, ValueStatement, ValueEffectiveStatement> {
private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
YangStmtMapping.VALUE).build();
private static final ValueStatementSupport INSTANCE = new ValueStatementSupport();
}
@Override
- public ValueStatement createDeclared(final StmtContext<Integer, ValueStatement, ?> ctx) {
- return new ValueStatementImpl(ctx);
+ protected SubstatementValidator getSubstatementValidator() {
+ return SUBSTATEMENT_VALIDATOR;
}
@Override
- public ValueEffectiveStatement createEffective(
- final StmtContext<Integer, ValueStatement, ValueEffectiveStatement> ctx) {
- return new ValueEffectiveStatementImpl(ctx);
+ protected ValueStatement createDeclared(final Integer argument,
+ final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+ return new RegularValueStatement(argument, substatements);
}
@Override
- protected SubstatementValidator getSubstatementValidator() {
- return SUBSTATEMENT_VALIDATOR;
+ protected ValueStatement createEmptyDeclared(@NonNull final Integer argument) {
+ return new EmptyValueStatement(argument);
+ }
+
+ @Override
+ protected ValueEffectiveStatement createEmptyEffective(@NonNull final ValueStatement declared) {
+ return new EmptyValueEffectiveStatement(declared);
+ }
+
+ @Override
+ protected ValueEffectiveStatement createEffective(
+ final StmtContext<Integer, ValueStatement, ValueEffectiveStatement> ctx, final ValueStatement declared,
+ final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+ return new RegularValueEffectiveStatement(declared, substatements);
}
-}
\ No newline at end of file
+}