From fc9c81c01de81734a2a96434af938be0df754ba1 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 12 Jun 2017 09:57:55 +0200 Subject: [PATCH] Enable checkstyle in yang-model-util Change-Id: I52d97ddfb88eaedd168a373e55ab06e0f21b8f46 Signed-off-by: Robert Varga --- yang/yang-model-util/pom.xml | 38 ++- .../AbstractSchemaListenerRegistration.java | 3 +- .../repo/util/AbstractSchemaRepository.java | 58 ++-- .../repo/util/AbstractSchemaSourceCache.java | 9 +- .../AbstractSchemaSourceRegistration.java | 6 +- .../util/FilesystemSchemaSourceCache.java | 63 +++-- .../repo/util/InMemorySchemaSourceCache.java | 15 +- .../repo/util/SchemaSourceTransformer.java | 9 +- .../model/util/AbstractSchemaContext.java | 6 + .../yang/model/util/BaseConstraints.java | 35 +-- .../yangtools/yang/model/util/BaseTypes.java | 10 +- .../yang/model/util/DataNodeIterator.java | 6 +- .../util/EffectiveAugmentationSchema.java | 5 +- .../util/FilteringSchemaContextProxy.java | 47 ++-- .../yang/model/util/LengthConstraintImpl.java | 25 +- .../yang/model/util/ModuleIdentifierImpl.java | 20 +- .../model/util/PatternConstraintImpl.java | 7 +- .../yang/model/util/RangeConstraintImpl.java | 2 +- .../yangtools/yang/model/util/RegexUtils.java | 8 +- .../yang/model/util/SchemaContextUtil.java | 92 ++++--- .../yang/model/util/SchemaNodeUtils.java | 22 +- .../yang/model/util/UnresolvedNumber.java | 2 + .../model/util/type/AbstractDerivedType.java | 5 +- .../util/type/AbstractIntegerBaseType.java | 3 +- .../util/type/AbstractRestrictedType.java | 3 +- .../yang/model/util/type/BaseDecimalType.java | 5 +- .../model/util/type/BaseEnumerationType.java | 3 +- .../model/util/type/BaseIdentityrefType.java | 3 +- .../yang/model/util/type/BaseTypes.java | 5 +- .../yang/model/util/type/BaseUnionType.java | 3 +- .../yang/model/util/type/BitsTypeBuilder.java | 4 +- .../yang/model/util/type/CompatUtils.java | 6 +- .../yang/model/util/type/ConcreteTypes.java | 91 ++++--- .../util/type/DerivedIdentityrefType.java | 3 +- .../type/DerivedInstanceIdentifierType.java | 10 +- .../model/util/type/DerivedIntegerType.java | 5 +- .../model/util/type/DerivedStringType.java | 5 +- .../model/util/type/DerivedTypeBuilder.java | 4 +- .../yang/model/util/type/DerivedTypes.java | 92 ++++--- .../util/type/EnumerationTypeBuilder.java | 4 +- .../type/InstanceIdentifierTypeBuilder.java | 9 +- .../type/LengthRestrictedTypeBuilder.java | 53 ++-- .../yang/model/util/type/NumberUtil.java | 25 +- .../util/type/RangeRestrictedTypeBuilder.java | 18 +- .../model/util/type/RestrictedBinaryType.java | 3 +- .../util/type/RestrictedBooleanType.java | 3 +- .../util/type/RestrictedIdentityrefType.java | 3 +- .../util/type/RestrictedIntegerType.java | 7 +- .../util/type/RestrictedLeafrefType.java | 3 +- .../model/util/type/RestrictedStringType.java | 3 +- .../yang/model/util/type/RestrictedTypes.java | 50 ++-- .../yang/model/util/type/TypeDefinitions.java | 217 +++++++-------- .../util/InMemorySchemaSourceCacheTest.java | 49 ++-- .../util/SchemaSourceTransformerTest.java | 12 +- .../yang/model/util/BaseConstraintsTest.java | 23 +- .../yang/model/util/BaseTypesTest.java | 1 + .../yang/model/util/BinaryTypeTest.java | 7 +- .../yang/model/util/BitsTypeTest.java | 11 +- .../yang/model/util/BooleanTypeTest.java | 14 +- .../yang/model/util/Bug4969Test.java | 8 +- .../yang/model/util/DataNodeIteratorTest.java | 26 +- .../yang/model/util/EmptyTypeTest.java | 3 +- .../yangtools/yang/model/util/Int8Test.java | 1 + .../yang/model/util/LeafrefTest.java | 18 +- .../model/util/PatternConstraintImplTest.java | 6 +- .../model/util/SchemaContextProxyTest.java | 248 ++++++++---------- .../model/util/SchemaContextUtilTest.java | 23 +- .../yang/model/util/SchemaNodeUtilsTest.java | 17 +- .../yang/model/util/type/BitImplTest.java | 13 +- .../yang/model/util/type/TypeTest.java | 90 ++++--- 70 files changed, 911 insertions(+), 795 deletions(-) diff --git a/yang/yang-model-util/pom.xml b/yang/yang-model-util/pom.xml index dda3501056..d7cd67e50a 100644 --- a/yang/yang-model-util/pom.xml +++ b/yang/yang-model-util/pom.xml @@ -57,19 +57,31 @@ - - ${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/ + + ${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/ + + + + opendaylight-site + ${nexus.site.url}/${project.artifactId}/ + + diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaListenerRegistration.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaListenerRegistration.java index c8cc2f0799..336f63440c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaListenerRegistration.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaListenerRegistration.java @@ -11,7 +11,8 @@ import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaListenerRegistration; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener; -public abstract class AbstractSchemaListenerRegistration extends AbstractListenerRegistration implements SchemaListenerRegistration { +public abstract class AbstractSchemaListenerRegistration extends AbstractListenerRegistration + implements SchemaListenerRegistration { protected AbstractSchemaListenerRegistration(final SchemaSourceListener listener) { super(listener); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java index e059265d4d..b887c2d95a 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java @@ -51,14 +51,16 @@ import org.slf4j.LoggerFactory; @Beta public abstract class AbstractSchemaRepository implements SchemaRepository, SchemaSourceRegistry { private static final Logger LOG = LoggerFactory.getLogger(AbstractSchemaRepository.class); - private static final ExceptionMapper FETCH_MAPPER = ReflectiveExceptionMapper.create("Schema source fetch", SchemaSourceException.class); + private static final ExceptionMapper FETCH_MAPPER = ReflectiveExceptionMapper.create( + "Schema source fetch", SchemaSourceException.class); /* * Source identifier -> representation -> provider map. We usually are looking for * a specific representation of a source. */ @GuardedBy("this") - private final Map, AbstractSchemaSourceRegistration>> sources = new HashMap<>(); + private final Map, + AbstractSchemaSourceRegistration>> sources = new HashMap<>(); /* * Schema source listeners. @@ -66,34 +68,39 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche @GuardedBy("this") private final Collection listeners = new ArrayList<>(); - private static CheckedFuture fetchSource(final SourceIdentifier id, final Iterator> it) { + private static CheckedFuture fetchSource( + final SourceIdentifier id, final Iterator> it) { final AbstractSchemaSourceRegistration reg = it.next(); @SuppressWarnings("unchecked") - final CheckedFuture f = ((SchemaSourceProvider)reg.getProvider()).getSource(id); + final CheckedFuture f = + ((SchemaSourceProvider)reg.getProvider()).getSource(id); return Futures.makeChecked(Futures.withFallback(f, new FutureFallback() { @Override - public ListenableFuture create(@Nonnull final Throwable t) throws SchemaSourceException { - LOG.debug("Failed to acquire source from {}", reg, t); + public ListenableFuture create(@Nonnull final Throwable cause) throws SchemaSourceException { + LOG.debug("Failed to acquire source from {}", reg, cause); if (it.hasNext()) { return fetchSource(id, it); } - throw new MissingSchemaSourceException("All available providers exhausted", id, t); + throw new MissingSchemaSourceException("All available providers exhausted", id, cause); } }), FETCH_MAPPER); } @Override - public CheckedFuture getSchemaSource(@Nonnull final SourceIdentifier id, @Nonnull final Class representation) { + public CheckedFuture getSchemaSource( + @Nonnull final SourceIdentifier id, @Nonnull final Class representation) { final ArrayList> sortedSchemaSourceRegistrations; synchronized (this) { - final ListMultimap, AbstractSchemaSourceRegistration> srcs = sources.get(id); + final ListMultimap, AbstractSchemaSourceRegistration> srcs = + sources.get(id); if (srcs == null) { - return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id, id)); + return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException( + "No providers registered for source" + id, id)); } sortedSchemaSourceRegistrations = Lists.newArrayList(srcs.get(representation)); @@ -104,8 +111,8 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche final Iterator> regs = sortedSchemaSourceRegistrations.iterator(); if (!regs.hasNext()) { - return Futures.immediateFailedCheckedFuture( - new MissingSchemaSourceException("No providers for source " + id + " representation " + representation + " available", id)); + return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException( + "No providers for source " + id + " representation " + representation + " available", id)); } CheckedFuture fetchSourceFuture = fetchSource(id, regs); @@ -119,6 +126,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche } @Override + @SuppressWarnings("checkstyle:parameterName") public void onFailure(@Nonnull final Throwable t) { LOG.trace("Skipping notification for encountered source {}, fetching source failed", id, t); } @@ -127,14 +135,16 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche return fetchSourceFuture; } - private synchronized void addSource(final PotentialSchemaSource source, final AbstractSchemaSourceRegistration reg) { - ListMultimap, AbstractSchemaSourceRegistration> m = sources.get(source.getSourceIdentifier()); - if (m == null) { - m = ArrayListMultimap.create(); - sources.put(source.getSourceIdentifier(), m); + private synchronized void addSource(final PotentialSchemaSource source, + final AbstractSchemaSourceRegistration reg) { + ListMultimap, AbstractSchemaSourceRegistration> map = + sources.get(source.getSourceIdentifier()); + if (map == null) { + map = ArrayListMultimap.create(); + sources.put(source.getSourceIdentifier(), map); } - m.put(source.getRepresentation(), reg); + map.put(source.getRepresentation(), reg); final Collection> reps = Collections.singleton(source); for (SchemaListenerRegistration l : listeners) { @@ -142,8 +152,10 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche } } - private synchronized void removeSource(final PotentialSchemaSource source, final SchemaSourceRegistration reg) { - final Multimap, AbstractSchemaSourceRegistration> m = sources.get(source.getSourceIdentifier()); + private synchronized void removeSource(final PotentialSchemaSource source, + final SchemaSourceRegistration reg) { + final Multimap, AbstractSchemaSourceRegistration> m = + sources.get(source.getSourceIdentifier()); if (m != null) { m.remove(source.getRepresentation(), reg); @@ -158,7 +170,8 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche } @Override - public SchemaSourceRegistration registerSchemaSource(final SchemaSourceProvider provider, final PotentialSchemaSource source) { + public SchemaSourceRegistration registerSchemaSource( + final SchemaSourceProvider provider, final PotentialSchemaSource source) { final PotentialSchemaSource src = source.cachedReference(); final AbstractSchemaSourceRegistration ret = new AbstractSchemaSourceRegistration(provider, src) { @@ -183,7 +196,8 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche synchronized (this) { final Collection> col = new ArrayList<>(); - for (Multimap, AbstractSchemaSourceRegistration> m : sources.values()) { + for (Multimap, AbstractSchemaSourceRegistration> m + : sources.values()) { for (AbstractSchemaSourceRegistration r : m.values()) { col.add(r.getInstance()); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceCache.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceCache.java index b665f43c58..4816e8f28a 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceCache.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceCache.java @@ -26,12 +26,14 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry; * * @param Cached schema source type. */ -public abstract class AbstractSchemaSourceCache implements SchemaSourceListener, SchemaSourceProvider { +public abstract class AbstractSchemaSourceCache + implements SchemaSourceListener, SchemaSourceProvider { private final SchemaSourceRegistry consumer; private final Class representation; private final Costs cost; - protected AbstractSchemaSourceCache(final SchemaSourceRegistry consumer, final Class representation, final Costs cost) { + protected AbstractSchemaSourceCache(final SchemaSourceRegistry consumer, final Class representation, + final Costs cost) { this.consumer = Preconditions.checkNotNull(consumer); this.representation = Preconditions.checkNotNull(representation); this.cost = Preconditions.checkNotNull(cost); @@ -58,7 +60,8 @@ public abstract class AbstractSchemaSourceCache register(final SourceIdentifier sourceIdentifier) { - final PotentialSchemaSource src = PotentialSchemaSource.create(sourceIdentifier, representation, cost.getValue()); + final PotentialSchemaSource src = PotentialSchemaSource.create(sourceIdentifier, representation, + cost.getValue()); return consumer.registerSchemaSource(this, src); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceRegistration.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceRegistration.java index fd4c1acf79..7c1c4ce658 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceRegistration.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaSourceRegistration.java @@ -15,10 +15,12 @@ import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration; -public abstract class AbstractSchemaSourceRegistration extends AbstractObjectRegistration> implements SchemaSourceRegistration { +public abstract class AbstractSchemaSourceRegistration + extends AbstractObjectRegistration> implements SchemaSourceRegistration { private final SchemaSourceProvider provider; - protected AbstractSchemaSourceRegistration(final SchemaSourceProvider provider, final PotentialSchemaSource source) { + protected AbstractSchemaSourceRegistration(final SchemaSourceProvider provider, + final PotentialSchemaSource source) { super(source); this.provider = Preconditions.checkNotNull(provider); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java index 0eb7fc0013..9f8e798fc4 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java @@ -7,7 +7,7 @@ */ package org.opendaylight.yangtools.yang.model.repo.util; -import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -46,21 +46,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Cache implementation that stores schemas in form of files under provided folder + * Cache implementation that stores schemas in form of files under provided folder. */ -public final class FilesystemSchemaSourceCache extends AbstractSchemaSourceCache { +public final class FilesystemSchemaSourceCache + extends AbstractSchemaSourceCache { private static final Logger LOG = LoggerFactory.getLogger(FilesystemSchemaSourceCache.class); // Init storage adapters - private static final Map, StorageAdapter> STORAGE_ADAPTERS = - Collections.singletonMap( + private static final Map, + StorageAdapter> STORAGE_ADAPTERS = Collections.singletonMap( YangTextSchemaSource.class, new YangTextSchemaStorageAdapter()); private static final Pattern CACHED_FILE_PATTERN = - Pattern.compile( - "(?[^@]+)" + - "(@(?" + SourceIdentifier.REVISION_PATTERN + "))?"); + Pattern.compile("(?[^@]+)" + "(@(?" + SourceIdentifier.REVISION_PATTERN + "))?"); private final Class representation; private final File storageDirectory; @@ -74,7 +73,8 @@ public final class FilesystemSchemaSourceCache getSource(final SourceIdentifier sourceIdentifier) { + public synchronized CheckedFuture getSource( + final SourceIdentifier sourceIdentifier) { final File file = sourceIdToFile(sourceIdentifier, storageDirectory); if (file.exists() && file.canRead()) { LOG.trace("Source {} found in cache as {}", sourceIdentifier, file); - final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, file); + final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, + file); return Futures.immediateCheckedFuture(representation.cast(restored)); } LOG.debug("Source {} not found in cache as {}", sourceIdentifier, file); - return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier)); + return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", + sourceIdentifier)); } @Override @@ -157,11 +161,12 @@ public final class FilesystemSchemaSourceCache map = new TreeMap<>(); for (File sorted : files) { String fileName = sorted.getName(); - Matcher m = SourceIdentifier.REVISION_PATTERN.matcher(fileName); - if (m.find()) { - String revStr = m.group(); + Matcher match = SourceIdentifier.REVISION_PATTERN.matcher(fileName); + if (match.find()) { + String revStr = match.group(); /* * FIXME: Consider using string for comparison. * String is comparable, pattern check tested format @@ -186,8 +191,8 @@ public final class FilesystemSchemaSourceCache { + private abstract static class StorageAdapter { private final Class supportedType; @@ -216,10 +221,10 @@ public final class FilesystemSchemaSourceCache extends AbstractSchemaSourceCache implements AutoCloseable { +public class InMemorySchemaSourceCache extends AbstractSchemaSourceCache + implements AutoCloseable { private final List> regs = Collections.synchronizedList(new ArrayList<>()); private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue(); private final Cache cache; - protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class representation, final CacheBuilder builder) { + protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class representation, + final CacheBuilder builder) { super(consumer, representation, Costs.IMMEDIATE); cache = builder.build(); } - public static InMemorySchemaSourceCache createSoftCache(final SchemaSourceRegistry consumer, final Class representation) { + public static InMemorySchemaSourceCache createSoftCache( + final SchemaSourceRegistry consumer, final Class representation) { return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues()); } public static InMemorySchemaSourceCache createSoftCache( - final SchemaSourceRegistry consumer, final Class representation, final long lifetime, final TimeUnit units) { + final SchemaSourceRegistry consumer, final Class representation, final long lifetime, + final TimeUnit units) { return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues() .expireAfterAccess(lifetime, units)); } @@ -54,7 +58,8 @@ public class InMemorySchemaSourceCache ext return Futures.immediateCheckedFuture(present); } - return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier)); + return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", + sourceIdentifier)); } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java index 24a4826983..ec2df4571b 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java @@ -26,11 +26,14 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry; -public class SchemaSourceTransformer implements SchemaSourceListener, SchemaSourceProvider { - private static final ExceptionMapper MAPPER = ReflectiveExceptionMapper.create("Source transformation", SchemaSourceException.class); +public class SchemaSourceTransformer + implements SchemaSourceListener, SchemaSourceProvider { + private static final ExceptionMapper MAPPER = ReflectiveExceptionMapper.create( + "Source transformation", SchemaSourceException.class); @FunctionalInterface - public interface Transformation extends AsyncFunction { + public interface Transformation + extends AsyncFunction { @Override CheckedFuture apply(@Nonnull final S input) throws Exception; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSchemaContext.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSchemaContext.java index aabe481724..87c112b500 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSchemaContext.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/AbstractSchemaContext.java @@ -53,16 +53,22 @@ public abstract class AbstractSchemaContext implements SchemaContext { protected static final Supplier> MODULE_SET_SUPPLIER = () -> new TreeSet<>(REVISION_COMPARATOR); /** + * Returns the ModuleIdentifier-to-YANG source mapping. + * * @return yang sources where key is ModuleIdentifier */ protected abstract Map getIdentifiersToSources(); /** + * Returns the namespace-to-module mapping. + * * @return Map of modules where key is namespace */ protected abstract SetMultimap getNamespaceToModules(); /** + * Returns the module name-to-module mapping. + * * @return Map of modules where key is name of module */ protected abstract SetMultimap getNameToModules(); diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java index cef542935e..3116132b02 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseConstraints.java @@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; /** * Utility class which provides factory methods to construct Constraints. * + *

* Provides static factory methods which constructs instances of *

    *
  • {@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)} @@ -31,12 +32,13 @@ public final class BaseConstraints { /** * Creates a {@link LengthConstraint}. * + *

    * Creates an instance of Length constraint based on supplied parameters * with additional behaviour: - * *

      *
    • {@link LengthConstraint#getErrorAppTag()} returns length-out-of-specified-bounds - *
    • {@link LengthConstraint#getErrorMessage()} returns The argument is out of bounds <min, max > + *
    • {@link LengthConstraint#getErrorMessage()} returns The argument is out of bounds + * <min, max > *
    * * @see LengthConstraint @@ -47,20 +49,21 @@ public final class BaseConstraints { * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined. * @return Instance of {@link LengthConstraint} */ - public static LengthConstraint newLengthConstraint(final Number min, final Number max, final Optional description, - final Optional reference) { + public static LengthConstraint newLengthConstraint(final Number min, final Number max, + final Optional description, final Optional reference) { return new LengthConstraintImpl(min, max, description, reference); } /** * Creates a {@link LengthConstraint}. * + *

    * Creates an instance of Length constraint based on supplied parameters * with additional behaviour: - * *

      *
    • {@link LengthConstraint#getErrorAppTag()} returns length-out-of-specified-bounds - *
    • {@link LengthConstraint#getErrorMessage()} returns The argument is out of bounds <min, max > + *
    • {@link LengthConstraint#getErrorMessage()} returns The argument is out of bounds + * <min, max > *
    * * @see LengthConstraint @@ -82,15 +85,15 @@ public final class BaseConstraints { /** * Creates a {@link RangeConstraint}. * + *

    * Creates an instance of Range constraint based on supplied parameters * with additional behaviour: - * *

      *
    • {@link RangeConstraint#getErrorAppTag()} returns range-out-of-specified-bounds - *
    • {@link RangeConstraint#getErrorMessage()} returns The argument is out of bounds <min, max > + *
    • {@link RangeConstraint#getErrorMessage()} returns The argument is out of bounds + * <min, max > *
    * - * * @see RangeConstraint * * @param Type of constraint @@ -100,23 +103,23 @@ public final class BaseConstraints { * @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined. * @return Instance of {@link RangeConstraint} */ - public static RangeConstraint newRangeConstraint(final T min, final T max, final Optional description, - final Optional reference) { + public static RangeConstraint newRangeConstraint(final T min, final T max, + final Optional description, final Optional reference) { return new RangeConstraintImpl(min, max, description, reference); } /** * Creates a {@link RangeConstraint}. * + *

    * Creates an instance of Range constraint based on supplied parameters * with additional behaviour: - * *

      *
    • {@link RangeConstraint#getErrorAppTag()} returns range-out-of-specified-bounds - *
    • {@link RangeConstraint#getErrorMessage()} returns The argument is out of bounds <min, max > + *
    • {@link RangeConstraint#getErrorMessage()} returns The argument is out of bounds + * <min, max > *
    * - * * @see RangeConstraint * * @param Type of constraint @@ -137,9 +140,9 @@ public final class BaseConstraints { /** * Creates a {@link PatternConstraint}. * + *

    * Creates an instance of Pattern constraint based on supplied parameters * with additional behaviour: - * *

      *
    • {@link PatternConstraint#getErrorAppTag()} returns * invalid-regular-expression @@ -163,9 +166,9 @@ public final class BaseConstraints { /** * Creates a {@link PatternConstraint}. * + *

      * Creates an instance of Pattern constraint based on supplied parameters * with additional behaviour: - * *

        *
      • {@link PatternConstraint#getErrorAppTag()} returns * invalid-regular-expression diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java index 27ca7a90b3..e3a5284f89 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/BaseTypes.java @@ -15,9 +15,7 @@ import org.opendaylight.yangtools.yang.common.YangConstants; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; /** - * Utility methods and constants to work with built-in YANG types - * - * + * Utility methods and constants to work with built-in YANG types. */ public final class BaseTypes { @@ -82,9 +80,10 @@ public final class BaseTypes { * Returns true if supplied type is representation of built-in YANG type as * per RFC 6020. * + *

        * See package documentation for description of base types. * - * @param type + * @param type A type name * @return true if type is built-in YANG Types. */ public static boolean isYangBuildInType(final String type) { @@ -96,9 +95,10 @@ public final class BaseTypes { * Returns true if supplied type is representation of built-in YANG type as * per RFC 6020. * + *

        * See package documentation for description of base types. * - * @param type + * @param type Type definition * @return true if type is built-in YANG Types. */ public static boolean isYangBuildInType(final TypeDefinition type) { diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java index 02b81df296..1c7543cf32 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java @@ -28,10 +28,8 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition; * DataNodeIterator is iterator, which walks down whole YANG DataNodeContainer * and walks all instances of {@link DataSchemaNode} present in subtree. * - * Iterator instance is eagerly created, walking happens on initialization. - * - * Iteration is not ordered. - * + *

        + * Iterator instance is eagerly created, walking happens on initialization. Iteration is not ordered. */ public class DataNodeIterator implements Iterator { diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java index 7e22270712..fecb622945 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/EffectiveAugmentationSchema.java @@ -35,11 +35,12 @@ public final class EffectiveAugmentationSchema implements AugmentationSchema { private final Set realChildSchemas; private final Map mappedChildSchemas; - public EffectiveAugmentationSchema(final AugmentationSchema augmentSchema, final Set realChildSchemas) { + public EffectiveAugmentationSchema(final AugmentationSchema augmentSchema, + final Set realChildSchemas) { this.delegate = Preconditions.checkNotNull(augmentSchema); this.realChildSchemas = ImmutableSet.copyOf(realChildSchemas); - final Map m = new HashMap<>(realChildSchemas.size());; + final Map m = new HashMap<>(realChildSchemas.size()); for (DataSchemaNode realChildSchema : realChildSchemas) { m.put(realChildSchema.getQName(), realChildSchema); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/FilteringSchemaContextProxy.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/FilteringSchemaContextProxy.java index 95016a1719..7c3c7abc95 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/FilteringSchemaContextProxy.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/FilteringSchemaContextProxy.java @@ -47,20 +47,19 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext { private final SetMultimap nameToModules; /** - * Filters SchemaContext for yang modules + * Filters SchemaContext for yang modules. * * @param delegate original SchemaContext - * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing rootModule and whole chain of their imports) + * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing + * rootModule and whole chain of their imports) * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain of their imports - * */ - public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection rootModules, final Set additionalModuleIds) { - - Preconditions.checkArgument(rootModules!=null,"Base modules cannot be null."); - Preconditions.checkArgument(additionalModuleIds!=null,"Additional modules cannot be null."); + public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection rootModules, + final Set additionalModuleIds) { + Preconditions.checkNotNull(rootModules, "Base modules cannot be null."); + Preconditions.checkNotNull(additionalModuleIds, "Additional modules cannot be null."); final Builder filteredModulesBuilder = new Builder<>(); - final SetMultimap nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); final SetMultimap nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); @@ -79,7 +78,8 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext { processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder); filteredModulesBuilder.addAll(getImportedModules( - Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID::apply), filteredModulesBuilder.build(), nameToModulesAll)); + Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID::apply), + filteredModulesBuilder.build(), nameToModulesAll)); /** * Instead of doing this on each invocation of getModules(), pre-compute @@ -119,25 +119,29 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext { } //dealing with imported module other than root and directly importing root - private static Collection getImportedModules(final Map allModules, final Set baseModules, final TreeMultimap nameToModulesAll) { + private static Collection getImportedModules(final Map allModules, + final Set baseModules, final TreeMultimap nameToModulesAll) { List relatedModules = Lists.newLinkedList(); for (Module module : baseModules) { for (ModuleImport moduleImport : module.getImports()) { - Date revisionDate = moduleImport.getRevision() == null ? - nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision() : moduleImport.getRevision(); + Date revisionDate = moduleImport.getRevision() == null + ? nameToModulesAll.get(moduleImport.getModuleName()).first().getRevision() + : moduleImport.getRevision(); ModuleId key = new ModuleId(moduleImport.getModuleName(),revisionDate); Module importedModule = allModules.get(key); - Preconditions.checkArgument(importedModule != null, "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s", key, module.getQNameModule(), module.getName() ); + Preconditions.checkArgument(importedModule != null, + "Invalid schema, cannot find imported module: %s from module: %s, %s, modules:%s", key, + module.getQNameModule(), module.getName()); relatedModules.add(importedModule); //calling imports recursive - relatedModules.addAll(getImportedModules(allModules, Collections.singleton(importedModule), nameToModulesAll)); - + relatedModules.addAll(getImportedModules(allModules, Collections.singleton(importedModule), + nameToModulesAll)); } } @@ -164,7 +168,7 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext { return nameToModules; } - private static boolean selectAdditionalModules(final Module module, final Set additionalModules){ + private static boolean selectAdditionalModules(final Module module, final Set additionalModules) { return additionalModules.contains(new ModuleId(module.getName(), module.getRevision())); } @@ -209,7 +213,8 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext { private final Date rev; public ModuleId(final String name, final Date rev) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "No module dependency name given. Nothing to do."); + Preconditions.checkArgument(!Strings.isNullOrEmpty(name), + "No module dependency name given. Nothing to do."); this.name = name; this.rev = Preconditions.checkNotNull(rev, "No revision date given. Nothing to do."); } @@ -226,15 +231,15 @@ public final class FilteringSchemaContextProxy extends AbstractSchemaContext { input.getRevision()); @Override - public boolean equals(final Object o) { - if (this == o) { + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModuleId)) { + if (!(obj instanceof ModuleId)) { return false; } - ModuleId moduleId = (ModuleId) o; + ModuleId moduleId = (ModuleId) obj; if (name != null ? !name.equals(moduleId.name) : moduleId.name != null) { return false; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java index 5e8f43fd54..feca985796 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/LengthConstraintImpl.java @@ -15,7 +15,6 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; /** * {@link Immutable} implementation of {@link LengthConstraint}. - * * Length constraint based on supplied parameters with additional behaviour: * *

          @@ -23,7 +22,7 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; * length-out-of-specified-bounds *
        • {@link LengthConstraint#getErrorMessage()} returns The argument is * out of bounds <min, max > - *
        */ final class LengthConstraintImpl implements LengthConstraint, Immutable { @@ -131,18 +130,12 @@ final class LengthConstraintImpl implements LengthConstraint, Immutable { @Override public String toString() { - return "LengthConstraintImpl [min=" + - min + - ", max=" + - max + - ", description=" + - description + - ", errorAppTag=" + - errorAppTag + - ", reference=" + - reference + - ", errorMessage=" + - errorMessage + - "]"; + return "LengthConstraintImpl [min=" + min + + ", max=" + max + + ", description=" + description + + ", errorAppTag=" + errorAppTag + + ", reference=" + reference + + ", errorMessage=" + errorMessage + + "]"; } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java index cb59566eea..af5c18c82c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleIdentifierImpl.java @@ -74,24 +74,24 @@ public final class ModuleIdentifierImpl implements ModuleIdentifier { @Override public String toString() { - return "ModuleIdentifierImpl{" + - "name='" + name + '\'' + - ", namespace=" + getNamespace() + - ", revision=" + qnameModule.getFormattedRevision() + - ", semantic version=" + semVer + - '}'; + return "ModuleIdentifierImpl{" + + "name='" + name + '\'' + + ", namespace=" + getNamespace() + + ", revision=" + qnameModule.getFormattedRevision() + + ", semantic version=" + semVer + + '}'; } @Override - public boolean equals(final Object o) { - if (this == o) { + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModuleIdentifier)) { + if (!(obj instanceof ModuleIdentifier)) { return false; } - ModuleIdentifier other = (ModuleIdentifier) o; + ModuleIdentifier other = (ModuleIdentifier) obj; if (!name.equals(other.getName())) { return false; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java index 3aafa348fa..6dd0414cba 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java @@ -16,16 +16,15 @@ import org.opendaylight.yangtools.yang.model.api.type.ModifierKind; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; /** - * {@link Immutable} implementation of {@link PatternConstraint} + * {@link Immutable} implementation of {@link PatternConstraint}. * + *

        * Creates an instance of Range constraint based on supplied parameters with * additional behaviour: - * *

          *
        • {@link PatternConstraint#getErrorAppTag()} returns * invalid-regular-expression *
        - * */ final class PatternConstraintImpl implements PatternConstraint, Immutable { @@ -102,4 +101,4 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { .add("reference", reference).add("errorAppTag", errorAppTag).add("errorMessage", errorMessage) .add("modifier", modifier).toString(); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java index 2b8d6321d5..f1e76b14e7 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java @@ -16,8 +16,8 @@ import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; /** * {@link Immutable} implementation of {@link RangeConstraint}. * + *

        * Range constraint based on supplied parameters with additional behavior: - * *

          *
        • {@link RangeConstraint#getErrorAppTag()} returns * range-out-of-specified-bounds diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RegexUtils.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RegexUtils.java index 862d7e5459..0991750e6c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RegexUtils.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RegexUtils.java @@ -17,7 +17,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Utilities for converting YANG XSD regexes into Java-compatible regexes + * Utilities for converting YANG XSD regexes into Java-compatible regexes. */ public final class RegexUtils { private static final Logger LOG = LoggerFactory.getLogger(RegexUtils.class); @@ -240,7 +240,7 @@ public final class RegexUtils { } /** - * Converts XSD regex to Java-compatible regex + * Converts XSD regex to Java-compatible regex. * * @param xsdRegex XSD regex pattern as it is defined in a YANG source * @return Java-compatible regex @@ -301,7 +301,7 @@ public final class RegexUtils { try { Pattern.compile(rawPattern); return rawPattern; - } catch(final PatternSyntaxException ex) { + } catch (final PatternSyntaxException ex) { LOG.debug("Invalid regex pattern syntax in: {}", rawPattern, ex); if (ex.getMessage().contains("Unknown character script name")) { rawPattern = fixUnknownScripts(ex.getMessage(), rawPattern); @@ -327,4 +327,4 @@ public final class RegexUtils { } return result.toString(); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java index 21d2d28113..8e390ba7be 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java @@ -66,7 +66,7 @@ public final class SchemaContextUtil { * the end of the SchemaPath. If the DataSchemaNode is not present in the * Schema Context the method will return null.
          * In case that Schema Context or Schema Path are not specified correctly - * (i.e. contains null values) the method will return + * (i.e. contains null values) the method will throw * IllegalArgumentException. * * @param context @@ -75,8 +75,7 @@ public final class SchemaContextUtil { * Schema Path to search for * @return SchemaNode from the end of the Schema Path or null * if the Node is not present. - * - * @throws IllegalArgumentException + * @throws IllegalArgumentException if context or schemaPath is not correct. */ public static SchemaNode findDataSchemaNode(final SchemaContext context, final SchemaPath schemaPath) { Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL"); @@ -119,7 +118,6 @@ public final class SchemaContextUtil { * @return Returns Data Schema Node for specified Schema Context for given * Non-conditional Revision Aware XPath, or null if the * DataSchemaNode is not present in Schema Context. - * @throws IllegalArgumentException */ public static SchemaNode findDataSchemaNode(final SchemaContext context, final Module module, final RevisionAwareXPath nonCondXPath) { @@ -177,8 +175,6 @@ public final class SchemaContextUtil { * @return DataSchemaNode if is present in specified Schema Context for * given relative Revision Aware XPath, otherwise will return * null. - * - * @throws IllegalArgumentException */ public static SchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, final Module module, final SchemaNode actualSchemaNode, final RevisionAwareXPath relativeXPath) { @@ -214,8 +210,6 @@ public final class SchemaContextUtil { * Schema Node * @return Yang Module for specified Schema Context and Schema Node, if Schema Node is NOT present, the method will * return null - * - * @throws IllegalArgumentException */ public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) { Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL!"); @@ -243,20 +237,21 @@ public final class SchemaContextUtil { } /** - * Returns NotificationDefinition from Schema Context + * Returns NotificationDefinition from Schema Context. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema Path of notification * @return Notification schema or null, if notification is not present in schema context. */ @Beta - @Nullable public static NotificationDefinition getNotificationSchema(@Nonnull final SchemaContext schema, + @Nullable + public static NotificationDefinition getNotificationSchema(@Nonnull final SchemaContext schema, @Nonnull final SchemaPath path) { Preconditions.checkNotNull(schema, "Schema context must not be null."); Preconditions.checkNotNull(path, "Schema path must not be null."); for (final NotificationDefinition potential : schema.getNotifications()) { if (path.equals(potential.getPath())) { - return potential; + return potential; } } return null; @@ -270,7 +265,8 @@ public final class SchemaContextUtil { * @return Notification schema or null, if notification is not present in schema context. */ @Beta - @Nullable public static ContainerSchemaNode getRpcDataSchema(@Nonnull final SchemaContext schema, + @Nullable + public static ContainerSchemaNode getRpcDataSchema(@Nonnull final SchemaContext schema, @Nonnull final SchemaPath path) { Preconditions.checkNotNull(schema, "Schema context must not be null."); Preconditions.checkNotNull(path, "Schema path must not be null."); @@ -281,7 +277,7 @@ public final class SchemaContextUtil { final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { - return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); + return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; @@ -476,10 +472,12 @@ public final class SchemaContextUtil { * XPath String * @return return a list of QName * - * @throws IllegalArgumentException + * @throws IllegalArgumentException if any arguments are null + * */ private static List xpathToQNamePath(final SchemaContext context, final Module parentModule, final String xpath) { + // FIXME: 2.0.0: this should throw NPE, not IAE Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL"); Preconditions.checkArgument(parentModule != null, "Parent Module reference cannot be NULL"); Preconditions.checkArgument(xpath != null, "XPath string reference cannot be NULL"); @@ -511,11 +509,11 @@ public final class SchemaContextUtil { * @param prefixedPathPart * Prefixed Path Part string * @return QName from prefixed Path Part String. - * - * @throws IllegalArgumentException + * @throws IllegalArgumentException if any arguments are null */ private static QName stringPathPartToQName(final SchemaContext context, final Module parentModule, final String prefixedPathPart) { + // FIXME: 2.0.0: this should throw NPE, not IAE Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL"); Preconditions.checkArgument(parentModule != null, "Parent Module reference cannot be NULL"); Preconditions.checkArgument(prefixedPathPart != null, "Prefixed Path Part cannot be NULL!"); @@ -556,11 +554,11 @@ public final class SchemaContextUtil { * Module Prefix * @return Module for given prefix in specified Schema Context if is * present, otherwise returns null - * - * @throws IllegalArgumentException + * @throws IllegalArgumentException if any arguments are null */ private static Module resolveModuleForPrefix(final SchemaContext context, final Module module, final String prefix) { + // FIXME: 2.0.0: this should throw NPE, not IAE Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL"); Preconditions.checkArgument(module != null, "Module reference cannot be NULL"); Preconditions.checkArgument(prefix != null, "Prefix string cannot be NULL"); @@ -579,6 +577,8 @@ public final class SchemaContextUtil { } /** + * Resolve a relative XPath into a set of QNames. + * * @param context * Schema Context * @param module @@ -588,11 +588,11 @@ public final class SchemaContextUtil { * @param actualSchemaNode * actual schema node * @return list of QName - * - * @throws IllegalArgumentException + * @throws IllegalArgumentException if any arguments are null */ private static Iterable resolveRelativeXPath(final SchemaContext context, final Module module, final RevisionAwareXPath relativeXPath, final SchemaNode actualSchemaNode) { + // FIXME: 2.0.0: this should throw NPE, not IAE Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL"); Preconditions.checkArgument(module != null, "Module reference cannot be NULL"); Preconditions.checkArgument(relativeXPath != null, "Non Conditional Revision Aware XPath cannot be NULL"); @@ -680,38 +680,16 @@ public final class SchemaContextUtil { return targetTypeDefinition; } - private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext, - final SchemaNode schemaNode) { - Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!"); - Preconditions.checkArgument(schemaNode instanceof TypedSchemaNode, "Unsupported node %s", schemaNode); - - TypeDefinition nodeType = ((TypedSchemaNode) schemaNode).getType(); - if (nodeType.getBaseType() != null) { - while (nodeType.getBaseType() != null) { - nodeType = nodeType.getBaseType(); - } - - final QNameModule typeDefModuleQname = nodeType.getQName().getModule(); - return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(), - typeDefModuleQname.getRevision()); - } - - return SchemaContextUtil.findParentModule(schemaContext, schemaNode); - } - /** - * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qName}. This handle + * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle * the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other * module as typedef which is then imported to referenced module. * + *

          * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful. - * - * @param typeDefinition - * @param schemaContext - * @param qName */ public static TypeDefinition getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition, - final SchemaContext schemaContext, final QName qName) { + final SchemaContext schemaContext, final QName qname) { final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement(); final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl( stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute()); @@ -719,8 +697,8 @@ public final class SchemaContextUtil { return null; } - final Module parentModule = schemaContext.findModuleByNamespaceAndRevision(qName.getNamespace() - ,qName.getRevision()); + final Module parentModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(), + qname.getRevision()); final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule, strippedPathStatement); final TypeDefinition targetTypeDefinition = typeDefinition(dataSchemaNode); @@ -731,6 +709,25 @@ public final class SchemaContextUtil { return targetTypeDefinition; } + private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext, + final SchemaNode schemaNode) { + Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!"); + Preconditions.checkArgument(schemaNode instanceof TypedSchemaNode, "Unsupported node %s", schemaNode); + + TypeDefinition nodeType = ((TypedSchemaNode) schemaNode).getType(); + if (nodeType.getBaseType() != null) { + while (nodeType.getBaseType() != null) { + nodeType = nodeType.getBaseType(); + } + + final QNameModule typeDefModuleQname = nodeType.getQName().getModule(); + return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(), + typeDefModuleQname.getRevision()); + } + + return SchemaContextUtil.findParentModule(schemaContext, schemaNode); + } + private static final Pattern STRIP_PATTERN = Pattern.compile("\\[[^\\[\\]]*\\]"); /** @@ -739,7 +736,6 @@ public final class SchemaContextUtil { * @param pathStatement * xPath to target node * @return string representation of xPath without conditions - * */ @VisibleForTesting static String stripConditionsFromXPathString(final RevisionAwareXPath pathStatement) { diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtils.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtils.java index 5121da0ec7..1ad31d4812 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtils.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtils.java @@ -43,22 +43,24 @@ public class SchemaNodeUtils { } /** - * Returns RPC input or output schema based on supplied QName + * Returns RPC input or output schema based on supplied QName. * * @param rpc RPC Definition * @param qname input or output QName with namespace same as RPC * @return input or output schema. Returns null if RPC does not have input/output specified. */ - @Nullable public static ContainerSchemaNode getRpcDataSchema(@Nonnull final RpcDefinition rpc, @Nonnull final QName qname) { + @Nullable public static ContainerSchemaNode getRpcDataSchema(@Nonnull final RpcDefinition rpc, + @Nonnull final QName qname) { Preconditions.checkNotNull(rpc, "Rpc Schema must not be null"); Preconditions.checkNotNull(qname,"QName must not be null"); switch (qname.getLocalName()) { - case "input": - return rpc.getInput(); - case "output": - return rpc.getOutput(); - default: - throw new IllegalArgumentException("Supplied qname " + qname + " does not represent rpc input or output."); - } - } + case "input": + return rpc.getInput(); + case "output": + return rpc.getOutput(); + default: + throw new IllegalArgumentException("Supplied qname " + qname + + " does not represent rpc input or output."); + } + } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnresolvedNumber.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnresolvedNumber.java index 5cfd9960ed..67b10767bd 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnresolvedNumber.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/UnresolvedNumber.java @@ -39,6 +39,7 @@ public abstract class UnresolvedNumber extends Number implements Immutable { return MAX; } }; + private static final UnresolvedNumber MIN = new UnresolvedNumber() { private static final long serialVersionUID = 1L; @@ -96,6 +97,7 @@ public abstract class UnresolvedNumber extends Number implements Immutable { } public abstract Number resolveLength(List constraints); + public abstract Number resolveRange(List constraints); @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java index f28e62fa7e..c195878b71 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractDerivedType.java @@ -25,7 +25,8 @@ abstract class AbstractDerivedType> extends Abstract private final String units; AbstractDerivedType(final T baseType, final SchemaPath path, final Object defaultValue, final String description, - final String reference, final Status status, final String units, final Collection unknownSchemNodes) { + final String reference, final Status status, final String units, + final Collection unknownSchemNodes) { super(path, unknownSchemNodes); this.baseType = Preconditions.checkNotNull(baseType); this.status = Preconditions.checkNotNull(status); @@ -42,8 +43,6 @@ abstract class AbstractDerivedType> extends Abstract /** * Return the stored base type. Unlike {@link #getBaseType()}, this method returns the underlying restricted type. - * - * @return */ final T baseType() { return baseType; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java index ddcb015c03..4d0db4a29f 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractIntegerBaseType.java @@ -10,7 +10,8 @@ package org.opendaylight.yangtools.yang.model.util.type; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; -abstract class AbstractIntegerBaseType extends AbstractRangedBaseType implements IntegerTypeDefinition { +abstract class AbstractIntegerBaseType extends AbstractRangedBaseType + implements IntegerTypeDefinition { AbstractIntegerBaseType(final QName qname, final Number minValue, final Number maxValue) { super(qname, minValue, maxValue); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java index 8020ef584f..d40fdd6577 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/AbstractRestrictedType.java @@ -18,7 +18,8 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; abstract class AbstractRestrictedType> extends AbstractTypeDefinition { private final T baseType; - AbstractRestrictedType(final T baseType, final SchemaPath path, final Collection unknownSchemaNodes) { + AbstractRestrictedType(final T baseType, final SchemaPath path, + final Collection unknownSchemaNodes) { super(path, unknownSchemaNodes); this.baseType = Preconditions.checkNotNull(baseType); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java index ad0c5b62ee..22d185f30c 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseDecimalType.java @@ -21,6 +21,7 @@ import org.opendaylight.yangtools.yang.model.util.BaseConstraints; final class BaseDecimalType extends AbstractRangedBaseType implements DecimalTypeDefinition { private static final List> IMPLICIT_RANGE_STATEMENTS; + static { final Builder> b = ImmutableList.builder(); b.add(createRangeConstraint("-922337203685477580.8", "922337203685477580.7")); @@ -55,8 +56,8 @@ final class BaseDecimalType extends AbstractRangedBaseType unknownSchemaNodes, final Integer fractionDigits, - final List rangeConstraints) { + BaseDecimalType(final SchemaPath path, final List unknownSchemaNodes, + final Integer fractionDigits, final List rangeConstraints) { super(path, unknownSchemaNodes, rangeConstraints); this.fractionDigits = fractionDigits; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java index b17d2b9f5a..c4e9ade89f 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseEnumerationType.java @@ -18,7 +18,8 @@ import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; final class BaseEnumerationType extends AbstractBaseType implements EnumTypeDefinition { private final List values; - BaseEnumerationType(final SchemaPath path, final List unknownSchemaNodes, final Collection values) { + BaseEnumerationType(final SchemaPath path, final List unknownSchemaNodes, + final Collection values) { super(path, unknownSchemaNodes); this.values = ImmutableList.copyOf(values); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java index b2628f3129..44064abaea 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseIdentityrefType.java @@ -15,7 +15,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; -final class BaseIdentityrefType extends AbstractBaseType implements IdentityrefTypeDefinition { +final class BaseIdentityrefType extends AbstractBaseType + implements IdentityrefTypeDefinition { private final IdentitySchemaNode identity; private final Set identities; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java index a59e637334..a6f64a70cc 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseTypes.java @@ -23,7 +23,9 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * Utility access methods for creating and accessing YANG base type definitions. YANG types come in two basic variants, * depending on whether they fully define their base instance or model input is required to fully-form the type. * - * The following types have their base type fully specified and are exposed as appropriate TypeDefinition sub-interfaces: + *

          + * The following types have their base type fully specified and are exposed as appropriate TypeDefinition + * sub-interfaces: *

            *
          • boolean
          • *
          • empty
          • @@ -33,6 +35,7 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit *
          • uint{8,16,32,64}
          • *
          * + *

          * The following types require additional specification in the model and are exposed by means of a specialized * {@link TypeBuilder}s for each type: *

            diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java index bbbe6ba8a8..0b68bc62e3 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BaseUnionType.java @@ -18,7 +18,8 @@ import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; final class BaseUnionType extends AbstractBaseType implements UnionTypeDefinition { private final List> types; - BaseUnionType(final SchemaPath path, final List unknownSchemaNodes, final Collection> types) { + BaseUnionType(final SchemaPath path, final List unknownSchemaNodes, + final Collection> types) { super(path, unknownSchemaNodes); this.types = ImmutableList.copyOf(types); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java index 362f2b8681..c4ac7be534 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java @@ -43,8 +43,8 @@ public final class BitsTypeBuilder extends AbstractRestrictedTypeBuilder * Here are the possible scenarios: * *
            @@ -80,6 +81,7 @@ public final class CompatUtils {
                  * 
            * The leaf type's schema path will not match the schema path of the leaf. We do NOT want to strip it. * + *

            * The situation is different for types which do not have a default instantiation in YANG: leafref, enumeration, * identityref, decimal64, bits and union. If these types are defined within this leaf's statement, a base type * will be instantiated. If the leaf defines a default statement, this base type will be visible via getBaseType(). @@ -170,8 +172,8 @@ public final class CompatUtils { final List patterns = type.getPatternConstraints(); final List lengths = type.getLengthConstraints(); - if ((patterns.isEmpty() || patterns.equals(base.getPatternConstraints())) && - (lengths.isEmpty() || lengths.equals(base.getLengthConstraints()))) { + if ((patterns.isEmpty() || patterns.equals(base.getPatternConstraints())) + && (lengths.isEmpty() || lengths.equals(base.getLengthConstraints()))) { return base; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/ConcreteTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/ConcreteTypes.java index cacc6cff71..b9ac813d60 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/ConcreteTypes.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/ConcreteTypes.java @@ -67,145 +67,158 @@ public final class ConcreteTypes { } } - private static ConcreteTypeBuilder concreteBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) { + private static ConcreteTypeBuilder concreteBinaryBuilder( + @Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public BinaryTypeDefinition buildType() { - return new DerivedBinaryType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedBinaryType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteBitsBuilder(final BitsTypeDefinition baseType, + final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public BitsTypeDefinition buildType() { - return new DerivedBitsType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedBitsType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) { + private static ConcreteTypeBuilder concreteBooleanBuilder( + @Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public BooleanTypeDefinition buildType() { - return new DerivedBooleanType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedBooleanType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteDecimalBuilder( + final DecimalTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public DecimalTypeDefinition buildType() { - return new DerivedDecimalType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedDecimalType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteEmptyBuilder(final EmptyTypeDefinition baseType, + final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public EmptyTypeDefinition buildType() { - return new DerivedEmptyType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedEmptyType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteEnumerationBuilder( + final EnumTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public EnumTypeDefinition buildType() { - return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteIdentityrefBuilder( + final IdentityrefTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public IdentityrefTypeDefinition buildType() { - return new DerivedIdentityrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedIdentityrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteInstanceIdentifierBuilder( + final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public InstanceIdentifierTypeDefinition buildType() { - return new DerivedInstanceIdentifierType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes(), baseType.requireInstance()); + return new DerivedInstanceIdentifierType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes(), baseType.requireInstance()); } }; } - private static ConcreteTypeBuilder concreteIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteIntegerBuilder( + final IntegerTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public IntegerTypeDefinition buildType() { - return new DerivedIntegerType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedIntegerType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteLeafrefBuilder( + final LeafrefTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public LeafrefTypeDefinition buildType() { - return new DerivedLeafrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedLeafrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteStringBuilder(final StringTypeDefinition baseType, + final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public StringTypeDefinition buildType() { - return new DerivedStringType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedStringType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteUnionBuilder(final UnionTypeDefinition baseType, + final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public DerivedUnionType buildType() { - return new DerivedUnionType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedUnionType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static ConcreteTypeBuilder concreteUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) { + private static ConcreteTypeBuilder concreteUnsignedBuilder( + final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) { return new ConcreteTypeBuilder(baseType, path) { @Nonnull @Override public UnsignedIntegerTypeDefinition buildType() { - return new DerivedUnsignedType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedUnsignedType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java index 7aedf3344e..919c1c3fa6 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIdentityrefType.java @@ -15,7 +15,8 @@ import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; -final class DerivedIdentityrefType extends AbstractDerivedType implements IdentityrefTypeDefinition { +final class DerivedIdentityrefType extends AbstractDerivedType + implements IdentityrefTypeDefinition { DerivedIdentityrefType(final IdentityrefTypeDefinition baseType, final SchemaPath path, final Object defaultValue, final String description, final String reference, final Status status, final String units, final Collection unknownSchemaNodes) { diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java index f63f84fab7..b646c22394 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedInstanceIdentifierType.java @@ -13,12 +13,14 @@ import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; -final class DerivedInstanceIdentifierType extends AbstractDerivedType implements InstanceIdentifierTypeDefinition { +final class DerivedInstanceIdentifierType extends AbstractDerivedType + implements InstanceIdentifierTypeDefinition { private final boolean requireInstance; - DerivedInstanceIdentifierType(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path, final Object defaultValue, - final String description, final String reference, final Status status, final String units, - final Collection unknownSchemaNodes, final boolean requireInstance) { + DerivedInstanceIdentifierType(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path, + final Object defaultValue, final String description, final String reference, final Status status, + final String units, final Collection unknownSchemaNodes, + final boolean requireInstance) { super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes); this.requireInstance = requireInstance; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java index ef4998a81e..ebe9b959a4 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedIntegerType.java @@ -17,8 +17,9 @@ import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; final class DerivedIntegerType extends AbstractDerivedType implements IntegerTypeDefinition { - DerivedIntegerType(final IntegerTypeDefinition baseType, final SchemaPath path, final Object defaultValue, final String description, - final String reference, final Status status, final String units, final Collection unknownSchemaNodes) { + DerivedIntegerType(final IntegerTypeDefinition baseType, final SchemaPath path, final Object defaultValue, + final String description, final String reference, final Status status, final String units, + final Collection unknownSchemaNodes) { super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java index 31802bcf6d..13171011f5 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedStringType.java @@ -17,8 +17,9 @@ import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; final class DerivedStringType extends AbstractDerivedType implements StringTypeDefinition { - DerivedStringType(final StringTypeDefinition baseType, final SchemaPath path, final Object defaultValue, final String description, - final String reference, final Status status, final String units, final Collection unknownSchemaNodes) { + DerivedStringType(final StringTypeDefinition baseType, final SchemaPath path, final Object defaultValue, + final String description, final String reference, final Status status, final String units, + final Collection unknownSchemaNodes) { super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java index a843a93eaa..e946992c84 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypeBuilder.java @@ -31,8 +31,8 @@ public abstract class DerivedTypeBuilder> extends Ty DerivedTypeBuilder(final T baseType, final SchemaPath path) { super(Preconditions.checkNotNull(baseType), path); - Preconditions.checkArgument(baseType instanceof AbstractBaseType || - baseType instanceof AbstractDerivedType || baseType instanceof AbstractRestrictedType, + Preconditions.checkArgument(baseType instanceof AbstractBaseType + || baseType instanceof AbstractDerivedType || baseType instanceof AbstractRestrictedType, "Derived type can be built only from a base, derived, or restricted type, not %s", baseType); // http://tools.ietf.org/html/rfc6020#section-7.3.4 diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java index 31d80d8323..2c762c113a 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/DerivedTypes.java @@ -29,6 +29,7 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * YANG defines 'derived type' as a type created through a 'typedef' statement. These types are exposed in the * hierarchical namespace and can be looked up. * + *

            * A derived type can redefine the default value, description, status and reference of a particular type definition. * It can only refine the units attribute, as that attribute is tied to the semantics of the value. The default value, * and units attributes are inherited from the super (base or restricted) type, others are left undefined if not @@ -169,132 +170,145 @@ public final class DerivedTypes { return BaseTypes.isUint64(BaseTypes.baseTypeOf(type)); } - private static DerivedTypeBuilder derivedBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) { + private static DerivedTypeBuilder derivedBinaryBuilder( + @Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public BinaryTypeDefinition build() { - return new DerivedBinaryType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedBinaryType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedBitsBuilder(final BitsTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public BitsTypeDefinition build() { - return new DerivedBitsType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedBitsType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) { + private static DerivedTypeBuilder derivedBooleanBuilder( + @Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public BooleanTypeDefinition build() { - return new DerivedBooleanType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedBooleanType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedDecimalBuilder(final DecimalTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public DecimalTypeDefinition build() { - return new DerivedDecimalType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedDecimalType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedEmptyBuilder(final EmptyTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public EmptyTypeDefinition build() { - return new DerivedEmptyType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedEmptyType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedEnumerationBuilder(final EnumTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public EnumTypeDefinition build() { - return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedEnumerationType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedIdentityrefBuilder( + final IdentityrefTypeDefinition baseType, final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public IdentityrefTypeDefinition build() { - return new DerivedIdentityrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedIdentityrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedInstanceIdentifierBuilder( + final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public InstanceIdentifierTypeDefinition build() { - return new DerivedInstanceIdentifierType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes(), baseType.requireInstance()); + return new DerivedInstanceIdentifierType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes(), baseType.requireInstance()); } }; } - private static DerivedTypeBuilder derivedIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedIntegerBuilder(final IntegerTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public IntegerTypeDefinition build() { - return new DerivedIntegerType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedIntegerType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedLeafrefBuilder(final LeafrefTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public LeafrefTypeDefinition build() { - return new DerivedLeafrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedLeafrefType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedStringBuilder(final StringTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public StringTypeDefinition build() { - return new DerivedStringType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedStringType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedUnionBuilder(final UnionTypeDefinition baseType, + final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public DerivedUnionType build() { - return new DerivedUnionType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedUnionType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } - private static DerivedTypeBuilder derivedUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) { + private static DerivedTypeBuilder derivedUnsignedBuilder( + final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) { return new DerivedTypeBuilder(baseType, path) { @Override public UnsignedIntegerTypeDefinition build() { - return new DerivedUnsignedType(getBaseType(), getPath(), getDefaultValue(), getDescription(), getReference(), - getStatus(), getUnits(), getUnknownSchemaNodes()); + return new DerivedUnsignedType(getBaseType(), getPath(), getDefaultValue(), getDescription(), + getReference(), getStatus(), getUnits(), getUnknownSchemaNodes()); } }; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java index c0d368ed23..03d077c5ce 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java @@ -43,8 +43,8 @@ public final class EnumerationTypeBuilder extends AbstractRestrictedTypeBuilder< for (EnumPair baseTypeEnumPair : getBaseType().getValues()) { if (item.getName().equals(baseTypeEnumPair.getName())) { if (item.getValue() != baseTypeEnumPair.getValue()) { - throw new InvalidEnumDefinitionException(item, "Value of enum '%s' must be the same as the value" + - " of corresponding enum in the base enumeration type %s.", item.getName(), + throw new InvalidEnumDefinitionException(item, "Value of enum '%s' must be the same as the value" + + " of corresponding enum in the base enumeration type %s.", item.getName(), getBaseType().getQName()); } isASubsetOfBaseEnums = true; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java index 8143a24448..e6b2e81041 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/InstanceIdentifierTypeBuilder.java @@ -11,9 +11,11 @@ import com.google.common.base.Preconditions; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; -public final class InstanceIdentifierTypeBuilder extends RequireInstanceRestrictedTypeBuilder { +public final class InstanceIdentifierTypeBuilder + extends RequireInstanceRestrictedTypeBuilder { - InstanceIdentifierTypeBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { + InstanceIdentifierTypeBuilder(final InstanceIdentifierTypeDefinition baseType, + final SchemaPath path) { super(Preconditions.checkNotNull(baseType), path); } @@ -23,6 +25,7 @@ public final class InstanceIdentifierTypeBuilder extends RequireInstanceRestrict return getBaseType(); } - return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(), getRequireInstance()); + return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(), + getRequireInstance()); } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java index 0d803ce34b..35d1336a44 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/LengthRestrictedTypeBuilder.java @@ -21,7 +21,8 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; import org.opendaylight.yangtools.yang.model.util.BaseConstraints; import org.opendaylight.yangtools.yang.model.util.UnresolvedNumber; -public abstract class LengthRestrictedTypeBuilder> extends AbstractRestrictedTypeBuilder { +public abstract class LengthRestrictedTypeBuilder> + extends AbstractRestrictedTypeBuilder { private List lengthAlternatives; LengthRestrictedTypeBuilder(final T baseType, final SchemaPath path) { @@ -57,10 +58,10 @@ public abstract class LengthRestrictedTypeBuilder> e final Number min = c.getMin(); if (max instanceof UnresolvedNumber || min instanceof UnresolvedNumber) { - final Number rMax = max instanceof UnresolvedNumber ? - ((UnresolvedNumber)max).resolveLength(baseLengthConstraints) : max; - final Number rMin = min instanceof UnresolvedNumber ? - ((UnresolvedNumber)min).resolveLength(baseLengthConstraints) : min; + final Number rMax = max instanceof UnresolvedNumber + ? ((UnresolvedNumber)max).resolveLength(baseLengthConstraints) : max; + final Number rMin = min instanceof UnresolvedNumber + ? ((UnresolvedNumber)min).resolveLength(baseLengthConstraints) : min; builder.add(BaseConstraints.newLengthConstraint(rMin, rMax, Optional.fromNullable(c.getDescription()), Optional.fromNullable(c.getReference()), c.getErrorAppTag(), c.getErrorMessage())); @@ -83,7 +84,8 @@ public abstract class LengthRestrictedTypeBuilder> e return lengths; } - private static List typedLengths(final List lengths, final Class clazz) { + private static List typedLengths(final List lengths, + final Class clazz) { final Function function = NumberUtil.converterTo(clazz); Preconditions.checkArgument(function != null, "Unsupported range class %s", clazz); @@ -91,7 +93,8 @@ public abstract class LengthRestrictedTypeBuilder> e for (LengthConstraint c : lengths) { if (!clazz.isInstance(c.getMin()) || !clazz.isInstance(c.getMax())) { - final Number min, max; + final Number min; + final Number max; try { min = function.apply(c.getMin()); @@ -121,21 +124,6 @@ public abstract class LengthRestrictedTypeBuilder> e return false; } - abstract T buildType(List lengthConstraints); - abstract List getLengthConstraints(T type); - abstract List typeLengthConstraints(); - - private List findLenghts() { - List ret = ImmutableList.of(); - T wlk = getBaseType(); - while (wlk != null && ret.isEmpty()) { - ret = getLengthConstraints(wlk); - wlk = wlk.getBaseType(); - } - - return ret.isEmpty() ? typeLengthConstraints() : ret; - } - @Override final T buildType() { final List baseLengths = findLenghts(); @@ -154,11 +142,28 @@ public abstract class LengthRestrictedTypeBuilder> e // Now verify if new ranges are strict subset of base ranges for (LengthConstraint c : typedLengths) { if (!lengthCovered(baseLengths, c)) { - throw new InvalidLengthConstraintException(c, "Length constraint %s is not a subset of parent constraints %s", - c, baseLengths); + throw new InvalidLengthConstraintException(c, + "Length constraint %s is not a subset of parent constraints %s", c, baseLengths); } } return buildType(typedLengths); } + + abstract T buildType(List lengthConstraints); + + abstract List getLengthConstraints(T type); + + abstract List typeLengthConstraints(); + + private List findLenghts() { + List ret = ImmutableList.of(); + T wlk = getBaseType(); + while (wlk != null && ret.isEmpty()) { + ret = getLengthConstraints(wlk); + wlk = wlk.getBaseType(); + } + + return ret.isEmpty() ? typeLengthConstraints() : ret; + } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/NumberUtil.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/NumberUtil.java index 424d416a95..0899ed9aba 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/NumberUtil.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/NumberUtil.java @@ -38,6 +38,7 @@ final class NumberUtil { }; private static final Map, Function> CONVERTERS; + static { final ImmutableMap.Builder, Function> b = ImmutableMap.builder(); b.put(Byte.class, input -> { @@ -48,14 +49,14 @@ final class NumberUtil { return Byte.valueOf(input.toString()); }); b.put(Short.class, input -> { - if (input instanceof Short) { - return input; - } - if (input instanceof Byte) { - return input.shortValue(); - } + if (input instanceof Short) { + return input; + } + if (input instanceof Byte) { + return input.shortValue(); + } - return Short.valueOf(input.toString()); + return Short.valueOf(input.toString()); }); b.put(Integer.class, input -> { if (input instanceof Integer) { @@ -81,8 +82,7 @@ final class NumberUtil { if (input instanceof BigDecimal) { return input; } - if (input instanceof Byte || input instanceof Short || - input instanceof Integer || input instanceof Long) { + if (input instanceof Byte || input instanceof Short || input instanceof Integer || input instanceof Long) { return BigDecimal.valueOf(input.longValue()); } @@ -92,8 +92,7 @@ final class NumberUtil { if (input instanceof BigInteger) { return input; } - if (input instanceof Byte || input instanceof Short || - input instanceof Integer || input instanceof Long) { + if (input instanceof Byte || input instanceof Short || input instanceof Integer || input instanceof Long) { return BigInteger.valueOf(input.longValue()); } @@ -111,7 +110,7 @@ final class NumberUtil { } static boolean isRangeCovered(final Number min, final Number max, final Number superMin, final Number superMax) { - return NumberUtil.NUMBER_COMPARATOR.compare(min, superMin) >= 0 && - NumberUtil.NUMBER_COMPARATOR.compare(max, superMax) <= 0; + return NumberUtil.NUMBER_COMPARATOR.compare(min, superMin) >= 0 + && NumberUtil.NUMBER_COMPARATOR.compare(max, superMax) <= 0; } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java index 434b4adbac..92c2117ffc 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RangeRestrictedTypeBuilder.java @@ -58,10 +58,10 @@ public abstract class RangeRestrictedTypeBuilder> ex final Number min = c.getMin(); if (max instanceof UnresolvedNumber || min instanceof UnresolvedNumber) { - final Number rMax = max instanceof UnresolvedNumber ? - ((UnresolvedNumber)max).resolveRange(baseRangeConstraints) : max; - final Number rMin = min instanceof UnresolvedNumber ? - ((UnresolvedNumber)min).resolveRange(baseRangeConstraints) : min; + final Number rMax = max instanceof UnresolvedNumber + ? ((UnresolvedNumber)max).resolveRange(baseRangeConstraints) : max; + final Number rMin = min instanceof UnresolvedNumber + ? ((UnresolvedNumber)min).resolveRange(baseRangeConstraints) : min; builder.add(BaseConstraints.newRangeConstraint(rMin, rMax, Optional.fromNullable(c.getDescription()), Optional.fromNullable(c.getReference()), c.getErrorAppTag(), c.getErrorMessage())); @@ -85,7 +85,8 @@ public abstract class RangeRestrictedTypeBuilder> ex return ranges; } - private static List typedRanges(final List ranges, final Class clazz) { + private static List typedRanges(final List ranges, + final Class clazz) { final Function function = NumberUtil.converterTo(clazz); Preconditions.checkArgument(function != null, "Unsupported range class %s", clazz); @@ -93,7 +94,8 @@ public abstract class RangeRestrictedTypeBuilder> ex for (RangeConstraint c : ranges) { if (!clazz.isInstance(c.getMin()) || !clazz.isInstance(c.getMax())) { - final Number min, max; + final Number min; + final Number max; try { min = function.apply(c.getMin()); @@ -139,8 +141,8 @@ public abstract class RangeRestrictedTypeBuilder> ex // Now verify if new ranges are strict subset of base ranges for (RangeConstraint c : typedRanges) { if (!rangeCovered(baseRangeConstraints, c)) { - throw new InvalidRangeConstraintException(c, "Range constraint %s is not a subset of parent constraints %s", - c, baseRangeConstraints); + throw new InvalidRangeConstraintException(c, + "Range constraint %s is not a subset of parent constraints %s", c, baseRangeConstraints); } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java index 930f5654a7..2e24640fc2 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBinaryType.java @@ -13,7 +13,8 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; -final class RestrictedBinaryType extends AbstractLengthRestrictedType implements BinaryTypeDefinition { +final class RestrictedBinaryType extends AbstractLengthRestrictedType + implements BinaryTypeDefinition { RestrictedBinaryType(final BinaryTypeDefinition baseType, final SchemaPath path, final Collection unknownSchemaNodes, final Collection lengthConstraints) { diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java index 41bdc1c7ba..b71652f9bf 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedBooleanType.java @@ -12,7 +12,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; -final class RestrictedBooleanType extends AbstractRestrictedType implements BooleanTypeDefinition { +final class RestrictedBooleanType extends AbstractRestrictedType + implements BooleanTypeDefinition { RestrictedBooleanType(final BooleanTypeDefinition baseType, final SchemaPath path, final Collection unknownSchemaNodes) { super(baseType, path, unknownSchemaNodes); diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java index 13751e4b6d..701403a98e 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIdentityrefType.java @@ -14,7 +14,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; -final class RestrictedIdentityrefType extends AbstractRestrictedType implements IdentityrefTypeDefinition { +final class RestrictedIdentityrefType extends AbstractRestrictedType + implements IdentityrefTypeDefinition { RestrictedIdentityrefType(final IdentityrefTypeDefinition baseType, final SchemaPath path, final Collection unknownSchemaNodes) { super(baseType, path, unknownSchemaNodes); diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java index 9935f24bb2..5e92d0ad67 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedIntegerType.java @@ -13,19 +13,20 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; -final class RestrictedIntegerType extends AbstractRangeRestrictedType implements IntegerTypeDefinition { +final class RestrictedIntegerType extends AbstractRangeRestrictedType + implements IntegerTypeDefinition { RestrictedIntegerType(final IntegerTypeDefinition baseType, final SchemaPath path, final Collection unknownSchemaNodes, final Collection rangeConstraints) { super(baseType, path, unknownSchemaNodes, rangeConstraints); } @Override - public final int hashCode() { + public int hashCode() { return TypeDefinitions.hashCode(this); } @Override - public final boolean equals(final Object obj) { + public boolean equals(final Object obj) { return TypeDefinitions.equals(this, obj); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java index b589b20297..691aa7e9a5 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedLeafrefType.java @@ -13,7 +13,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; -final class RestrictedLeafrefType extends AbstractRestrictedType implements LeafrefTypeDefinition { +final class RestrictedLeafrefType extends AbstractRestrictedType + implements LeafrefTypeDefinition { private final boolean requireInstance; diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java index 04dd026703..0c1aa6aca5 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedStringType.java @@ -16,7 +16,8 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; -final class RestrictedStringType extends AbstractLengthRestrictedType implements StringTypeDefinition { +final class RestrictedStringType extends AbstractLengthRestrictedType + implements StringTypeDefinition { private final List patternConstraints; RestrictedStringType(final StringTypeDefinition baseType, final SchemaPath path, diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java index 3e3200e465..521036e612 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/RestrictedTypes.java @@ -7,8 +7,9 @@ */ package org.opendaylight.yangtools.yang.model.util.type; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; import java.util.List; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -31,6 +32,7 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * Restricted types are a refinement of the restrictions applied to a particular type. YANG defines restrictions only * on a subset of the base types, but conceptually any such definition can hold unknown nodes. * + *

            * 1) Restrictable * binary (length) * int{8,16,32,64} (range) @@ -39,6 +41,7 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * decimal64 (range) * instance-identifier (require-instance) * + *

            * 2) Non-restrictable * boolean * bits @@ -48,11 +51,13 @@ import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinit * leafref * union * + *

            * This class holds methods which allow creation of restricted types using {@link TypeBuilder} and its subclasses. Each * restricted type is logically anchored at a {@link SchemaPath}, but can be substituted by its base type if it does * not contribute any additional restrictions. TypeBuilder instances take this into account, and result in the base type * being returned from the builder when the base type and restricted type are semantically equal. * + *

            * Restricted types inherit the default value, description, reference, status and units from the base type, if that type * defines them. */ @@ -62,7 +67,8 @@ public final class RestrictedTypes { throw new UnsupportedOperationException(); } - public static LengthRestrictedTypeBuilder newBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) { + public static LengthRestrictedTypeBuilder newBinaryBuilder( + @Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) { return new LengthRestrictedTypeBuilder(baseType, path) { @Override BinaryTypeDefinition buildType(final List lengthConstraints) { @@ -72,8 +78,8 @@ public final class RestrictedTypes { @Override List typeLengthConstraints() { /** - * Length constraint imposed on YANG binary type by our implementation. byte[].length is an integer, capping our - * ability to support arbitrary binary data. + * Length constraint imposed on YANG binary type by our implementation. byte[].length is an integer, + * capping our ability to support arbitrary binary data. */ return JavaLengthConstraints.INTEGER_SIZE_CONSTRAINTS; } @@ -89,7 +95,8 @@ public final class RestrictedTypes { return new BitsTypeBuilder(baseType, path); } - public static TypeBuilder newBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) { + public static TypeBuilder newBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, + @Nonnull final SchemaPath path) { return new AbstractRestrictedTypeBuilder(baseType, path) { @Override BooleanTypeDefinition buildType() { @@ -98,8 +105,9 @@ public final class RestrictedTypes { }; } - public static RangeRestrictedTypeBuilder newDecima64Builder(final DecimalTypeDefinition baseType, final SchemaPath path) { - return new RangeRestrictedTypeBuilder(Preconditions.checkNotNull(baseType), path) { + public static RangeRestrictedTypeBuilder newDecima64Builder( + final DecimalTypeDefinition baseType, final SchemaPath path) { + return new RangeRestrictedTypeBuilder(checkNotNull(baseType), path) { @Override DecimalTypeDefinition buildType() { return new RestrictedDecimalType(getBaseType(), getPath(), getUnknownSchemaNodes(), @@ -108,7 +116,8 @@ public final class RestrictedTypes { }; } - public static TypeBuilder newEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) { + public static TypeBuilder newEmptyBuilder(final EmptyTypeDefinition baseType, + final SchemaPath path) { return new AbstractRestrictedTypeBuilder(baseType, path) { @Override EmptyTypeDefinition buildType() { @@ -117,11 +126,13 @@ public final class RestrictedTypes { }; } - public static EnumerationTypeBuilder newEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) { + public static EnumerationTypeBuilder newEnumerationBuilder(final EnumTypeDefinition baseType, + final SchemaPath path) { return new EnumerationTypeBuilder(baseType, path); } - public static TypeBuilder newIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) { + public static TypeBuilder newIdentityrefBuilder(final IdentityrefTypeDefinition baseType, + final SchemaPath path) { return new AbstractRestrictedTypeBuilder(baseType, path) { @Override IdentityrefTypeDefinition buildType() { @@ -130,7 +141,8 @@ public final class RestrictedTypes { }; } - public static InstanceIdentifierTypeBuilder newInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { + public static InstanceIdentifierTypeBuilder newInstanceIdentifierBuilder( + final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) { return new InstanceIdentifierTypeBuilder(baseType, path); } @@ -142,13 +154,15 @@ public final class RestrictedTypes { if (getRequireInstance() == getBaseType().requireInstance()) { return getBaseType(); } - return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes(), getRequireInstance()); + return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes(), + getRequireInstance()); } }; } - public static RangeRestrictedTypeBuilder newIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) { - return new RangeRestrictedTypeBuilder(Preconditions.checkNotNull(baseType), path) { + public static RangeRestrictedTypeBuilder newIntegerBuilder( + final IntegerTypeDefinition baseType, final SchemaPath path) { + return new RangeRestrictedTypeBuilder(checkNotNull(baseType), path) { @Override IntegerTypeDefinition buildType() { return new RestrictedIntegerType(getBaseType(), getPath(), getUnknownSchemaNodes(), @@ -161,7 +175,8 @@ public final class RestrictedTypes { return new StringTypeBuilder(baseType, path); } - public static TypeBuilder newUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) { + public static TypeBuilder newUnionBuilder(final UnionTypeDefinition baseType, + final SchemaPath path) { return new AbstractRestrictedTypeBuilder(baseType, path) { @Override UnionTypeDefinition buildType() { @@ -170,8 +185,9 @@ public final class RestrictedTypes { }; } - public static RangeRestrictedTypeBuilder newUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) { - return new RangeRestrictedTypeBuilder(Preconditions.checkNotNull(baseType), path) { + public static RangeRestrictedTypeBuilder newUnsignedBuilder( + final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) { + return new RangeRestrictedTypeBuilder(checkNotNull(baseType), path) { @Override UnsignedIntegerTypeDefinition buildType() { return new RestrictedUnsignedType(getBaseType(), getPath(), getUnknownSchemaNodes(), diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeDefinitions.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeDefinitions.java index 117375d21d..8b8ba8d35b 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeDefinitions.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/TypeDefinitions.java @@ -65,84 +65,99 @@ final class TypeDefinitions { type.getDefaultValue(), type.getLengthConstraints()); } - static boolean equals(final BinaryTypeDefinition type, final Object obj) { - if (type == obj) { - return true; - } + static int hashCode(final BitsTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getBits()); + } - final BinaryTypeDefinition other = castIfEquals(BinaryTypeDefinition.class, type, obj); - return other != null && type.getLengthConstraints().equals(other.getLengthConstraints()); + + static int hashCode(final BooleanTypeDefinition type) { + return basicHashCode(type); } - static String toString(final BinaryTypeDefinition type) { - return toStringHelper(type).add("length", type.getLengthConstraints()).toString(); + static int hashCode(final DecimalTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getFractionDigits(), type.getRangeConstraints()); } - static int hashCode(final BitsTypeDefinition type) { + static int hashCode(final EmptyTypeDefinition type) { + return basicHashCode(type); + } + + static int hashCode(final EnumTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getBits()); + type.getDefaultValue(), type.getValues()); } - static boolean equals(final BitsTypeDefinition type, final Object obj) { - if (type == obj) { - return true; - } + static int hashCode(final IdentityrefTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getIdentity()); + } - final BitsTypeDefinition other = castIfEquals(BitsTypeDefinition.class, type, obj); - return other != null && type.getBits().equals(other.getBits()); + static int hashCode(final InstanceIdentifierTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.requireInstance()); } - static String toString(final BitsTypeDefinition type) { - return toStringHelper(type).add("bits", type.getBits()).toString(); + static int hashCode(final IntegerTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getRangeConstraints()); } - static int hashCode(final BooleanTypeDefinition type) { - return basicHashCode(type); + static int hashCode(final LeafrefTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getPathStatement()); } - static boolean equals(final BooleanTypeDefinition type, final Object obj) { - return type == obj || castIfEquals(BooleanTypeDefinition.class, type, obj) != null; + static int hashCode(final StringTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getLengthConstraints(), type.getPatternConstraints()); } - static String toString(final BooleanTypeDefinition type) { - return toStringHelper(type).toString(); + static int hashCode(final UnionTypeDefinition type) { + return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), + type.getDefaultValue(), type.getTypes()); } - static int hashCode(final DecimalTypeDefinition type) { + static int hashCode(final UnsignedIntegerTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getFractionDigits(), type.getRangeConstraints()); + type.getDefaultValue(), type.getRangeConstraints()); } - static boolean equals(final DecimalTypeDefinition type, final Object obj) { + static boolean equals(final BinaryTypeDefinition type, final Object obj) { if (type == obj) { return true; } - final DecimalTypeDefinition other = castIfEquals(DecimalTypeDefinition.class, type, obj); - return other != null && type.getFractionDigits().equals(other.getFractionDigits()) - && type.getRangeConstraints().equals(other.getRangeConstraints()); + final BinaryTypeDefinition other = castIfEquals(BinaryTypeDefinition.class, type, obj); + return other != null && type.getLengthConstraints().equals(other.getLengthConstraints()); } - static String toString(final DecimalTypeDefinition type) { - return toStringHelper(type).add("fractionDigits", type.getFractionDigits()) - .add("range", type.getRangeConstraints()).toString(); - } + static boolean equals(final BitsTypeDefinition type, final Object obj) { + if (type == obj) { + return true; + } - static int hashCode(final EmptyTypeDefinition type) { - return basicHashCode(type); + final BitsTypeDefinition other = castIfEquals(BitsTypeDefinition.class, type, obj); + return other != null && type.getBits().equals(other.getBits()); } - static boolean equals(final EmptyTypeDefinition type, final Object obj) { - return type == obj || castIfEquals(EmptyTypeDefinition.class, type, obj) != null; + static boolean equals(final BooleanTypeDefinition type, final Object obj) { + return type == obj || castIfEquals(BooleanTypeDefinition.class, type, obj) != null; } - static String toString(final EmptyTypeDefinition type) { - return toStringHelper(type).toString(); + static boolean equals(final DecimalTypeDefinition type, final Object obj) { + if (type == obj) { + return true; + } + + final DecimalTypeDefinition other = castIfEquals(DecimalTypeDefinition.class, type, obj); + return other != null && type.getFractionDigits().equals(other.getFractionDigits()) + && type.getRangeConstraints().equals(other.getRangeConstraints()); } - static int hashCode(final EnumTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getValues()); + static boolean equals(final EmptyTypeDefinition type, final Object obj) { + return type == obj || castIfEquals(EmptyTypeDefinition.class, type, obj) != null; } static boolean equals(final EnumTypeDefinition type, final Object obj) { @@ -154,15 +169,6 @@ final class TypeDefinitions { return other != null && type.getValues().equals(other.getValues()); } - static String toString(final EnumTypeDefinition type) { - return toStringHelper(type).add("values", type.getValues()).toString(); - } - - static int hashCode(final IdentityrefTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getIdentity()); - } - static boolean equals(final IdentityrefTypeDefinition type, final Object obj) { if (type == obj) { return true; @@ -172,15 +178,6 @@ final class TypeDefinitions { return other != null && type.getIdentity().equals(other.getIdentity()); } - static String toString(final IdentityrefTypeDefinition type) { - return toStringHelper(type).add("identity", type.getIdentity()).toString(); - } - - static int hashCode(final InstanceIdentifierTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.requireInstance()); - } - static boolean equals(final InstanceIdentifierTypeDefinition type, final Object obj) { if (type == obj) { return true; @@ -190,15 +187,6 @@ final class TypeDefinitions { return other != null && type.requireInstance() == other.requireInstance(); } - static String toString(final InstanceIdentifierTypeDefinition type) { - return toStringHelper(type).add("requireInstance", type.requireInstance()).toString(); - } - - static int hashCode(final IntegerTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getRangeConstraints()); - } - static boolean equals(final IntegerTypeDefinition type, final Object obj) { if (type == obj) { return true; @@ -208,33 +196,15 @@ final class TypeDefinitions { return other != null && type.getRangeConstraints().equals(other.getRangeConstraints()); } - static String toString(final IntegerTypeDefinition type) { - return toStringHelper(type).add("range", type.getRangeConstraints()).toString(); - } - - static int hashCode(final LeafrefTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getPathStatement()); - } - static boolean equals(final LeafrefTypeDefinition type, final Object obj) { if (type == obj) { return true; } - final LeafrefTypeDefinition other =castIfEquals(LeafrefTypeDefinition.class, type, obj); + final LeafrefTypeDefinition other = castIfEquals(LeafrefTypeDefinition.class, type, obj); return other != null && type.getPathStatement().equals(other.getPathStatement()); } - static String toString(final LeafrefTypeDefinition type) { - return toStringHelper(type).add("pathStatement", type.getPathStatement()).toString(); - } - - static int hashCode(final StringTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getLengthConstraints(), type.getPatternConstraints()); - } - static boolean equals(final StringTypeDefinition type, final Object obj) { if (type == obj) { return true; @@ -245,16 +215,6 @@ final class TypeDefinitions { && type.getPatternConstraints().equals(other.getPatternConstraints()); } - static String toString(final StringTypeDefinition type) { - return toStringHelper(type).add("length", type.getLengthConstraints()) - .add("patterns", type.getPatternConstraints()).toString(); - } - - static int hashCode(final UnionTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getTypes()); - } - static boolean equals(final UnionTypeDefinition type, final Object obj) { if (type == obj) { return true; @@ -264,15 +224,6 @@ final class TypeDefinitions { return other != null && type.getTypes().equals(other.getTypes()); } - static String toString(final UnionTypeDefinition type) { - return toStringHelper(type).add("types", type.getTypes()).toString(); - } - - static int hashCode(final UnsignedIntegerTypeDefinition type) { - return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits(), - type.getDefaultValue(), type.getRangeConstraints()); - } - static boolean equals(final UnsignedIntegerTypeDefinition type, final Object obj) { if (type == obj) { return true; @@ -282,6 +233,56 @@ final class TypeDefinitions { return other != null && type.getRangeConstraints().equals(other.getRangeConstraints()); } + static String toString(final BinaryTypeDefinition type) { + return toStringHelper(type).add("length", type.getLengthConstraints()).toString(); + } + + static String toString(final BitsTypeDefinition type) { + return toStringHelper(type).add("bits", type.getBits()).toString(); + } + + static String toString(final BooleanTypeDefinition type) { + return toStringHelper(type).toString(); + } + + static String toString(final DecimalTypeDefinition type) { + return toStringHelper(type).add("fractionDigits", type.getFractionDigits()) + .add("range", type.getRangeConstraints()).toString(); + } + + static String toString(final EmptyTypeDefinition type) { + return toStringHelper(type).toString(); + } + + static String toString(final EnumTypeDefinition type) { + return toStringHelper(type).add("values", type.getValues()).toString(); + } + + static String toString(final IdentityrefTypeDefinition type) { + return toStringHelper(type).add("identity", type.getIdentity()).toString(); + } + + static String toString(final InstanceIdentifierTypeDefinition type) { + return toStringHelper(type).add("requireInstance", type.requireInstance()).toString(); + } + + static String toString(final IntegerTypeDefinition type) { + return toStringHelper(type).add("range", type.getRangeConstraints()).toString(); + } + + static String toString(final LeafrefTypeDefinition type) { + return toStringHelper(type).add("pathStatement", type.getPathStatement()).toString(); + } + + static String toString(final StringTypeDefinition type) { + return toStringHelper(type).add("length", type.getLengthConstraints()) + .add("patterns", type.getPatternConstraints()).toString(); + } + + static String toString(final UnionTypeDefinition type) { + return toStringHelper(type).add("types", type.getTypes()).toString(); + } + static String toString(final UnsignedIntegerTypeDefinition type) { return toStringHelper(type).add("range", type.getRangeConstraints()).toString(); } diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCacheTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCacheTest.java index 597d16017c..17cd535e27 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCacheTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCacheTest.java @@ -39,9 +39,9 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry; @RunWith(MockitoJUnitRunner.class) public class InMemorySchemaSourceCacheTest { - private static final Class representation = YangSchemaSourceRepresentation.class; - private static final long lifetime = 1000l; - private static final TimeUnit units = TimeUnit.MILLISECONDS; + private static final Class REPRESENTATION = YangSchemaSourceRepresentation.class; + private static final long LIFETIME = 1000L; + private static final TimeUnit UNITS = TimeUnit.MILLISECONDS; @Mock private SchemaSourceRegistry registry; @@ -56,31 +56,30 @@ public class InMemorySchemaSourceCacheTest { @Test public void inMemorySchemaSourceCacheTest1() { - final InMemorySchemaSourceCache inMemorySchemaSourceCache = InMemorySchemaSourceCache - .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation); + final InMemorySchemaSourceCache inMemorySchemaSourceCache = + InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION); Assert.assertNotNull(inMemorySchemaSourceCache); inMemorySchemaSourceCache.close(); } @Test public void inMemorySchemaSourceCacheTest2() { - final InMemorySchemaSourceCache inMemorySchemaSourceCache = InMemorySchemaSourceCache - .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation, - InMemorySchemaSourceCacheTest.lifetime, InMemorySchemaSourceCacheTest.units); + final InMemorySchemaSourceCache inMemorySchemaSourceCache = + InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION, LIFETIME, UNITS); Assert.assertNotNull(inMemorySchemaSourceCache); inMemorySchemaSourceCache.close(); } @Test public void inMemorySchemaSourceCacheOfferAndGetSourcestest() throws Exception { - final InMemorySchemaSourceCache inMemorySchemaSourceCache = InMemorySchemaSourceCache - .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation); + final InMemorySchemaSourceCache inMemorySchemaSourceCache = + InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION); final String content = "content"; final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content); inMemorySchemaSourceCache.offer(source); final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("test", "2012-12-12"); - final CheckedFuture checkedSource = inMemorySchemaSourceCache - .getSource(sourceIdentifier); + final CheckedFuture checkedSource = + inMemorySchemaSourceCache.getSource(sourceIdentifier); Assert.assertNotNull(checkedSource); final YangSchemaSourceRepresentation yangSchemaSourceRepresentation = checkedSource.get(); Assert.assertNotNull(yangSchemaSourceRepresentation); @@ -90,11 +89,11 @@ public class InMemorySchemaSourceCacheTest { @Test(expected = ExecutionException.class) public void inMemorySchemaSourceCacheNullGetSourcestest() throws Exception { - final InMemorySchemaSourceCache inMemorySchemaSourceCache = InMemorySchemaSourceCache - .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation); + final InMemorySchemaSourceCache inMemorySchemaSourceCache = + InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION); final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("test", "2012-12-12"); - final CheckedFuture checkedSource = inMemorySchemaSourceCache - .getSource(sourceIdentifier); + final CheckedFuture checkedSource = + inMemorySchemaSourceCache.getSource(sourceIdentifier); Assert.assertNotNull(checkedSource); checkedSource.get(); inMemorySchemaSourceCache.close(); @@ -102,12 +101,10 @@ public class InMemorySchemaSourceCacheTest { @Test public void inMemorySchemaSourceCache3test() throws Exception { - final InMemorySchemaSourceCache inMemorySchemaSourceCache = InMemorySchemaSourceCache - .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation); - - final InMemorySchemaSourceCache inMemorySchemaSourceCache2 = InMemorySchemaSourceCache - .createSoftCache(this.registry, representation, InMemorySchemaSourceCacheTest.lifetime, - InMemorySchemaSourceCacheTest.units); + final InMemorySchemaSourceCache inMemorySchemaSourceCache = + InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION); + final InMemorySchemaSourceCache inMemorySchemaSourceCache2 = + InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION, LIFETIME, UNITS); final String content = "content"; final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content); @@ -115,10 +112,10 @@ public class InMemorySchemaSourceCacheTest { inMemorySchemaSourceCache2.offer(source); final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("test", "2012-12-12"); - final CheckedFuture checkedSource = inMemorySchemaSourceCache - .getSource(sourceIdentifier); - final CheckedFuture checkedSource2 = inMemorySchemaSourceCache2 - .getSource(sourceIdentifier); + final CheckedFuture checkedSource = + inMemorySchemaSourceCache.getSource(sourceIdentifier); + final CheckedFuture checkedSource2 = + inMemorySchemaSourceCache2.getSource(sourceIdentifier); Assert.assertNotNull(checkedSource); Assert.assertNotNull(checkedSource2); diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformerTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformerTest.java index 9bc44aa84f..a9d6bc9053 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformerTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformerTest.java @@ -7,19 +7,18 @@ */ package org.opendaylight.yangtools.yang.model.repo.util; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; - import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.CheckedFuture; import java.util.Arrays; import java.util.concurrent.Future; +import javax.annotation.Nonnull; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory; import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; @@ -61,7 +60,8 @@ public class SchemaSourceTransformerTest { @Test public void schemaSourceTransformerGetSourceTest() throws Exception { final Provider p = new Provider(); - final Registrator reg = new Registrator(p, SchemaSourceTransformerTest.SRC_CLASS, PotentialSchemaSource.Costs.IMMEDIATE); + final Registrator reg = new Registrator(p, SchemaSourceTransformerTest.SRC_CLASS, + PotentialSchemaSource.Costs.IMMEDIATE); final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("source"); reg.register(sourceIdentifier); this.schema = new SchemaSourceTransformer<>(p, @@ -109,7 +109,7 @@ public class SchemaSourceTransformerTest { final PotentialSchemaSource src; - public Foo(final SourceIdentifier sourceIdentifier, final Class representation, final Costs cost) { + Foo(final SourceIdentifier sourceIdentifier, final Class representation, final Costs cost) { this.src = PotentialSchemaSource.create(sourceIdentifier, representation, cost.getValue()); } @@ -122,7 +122,7 @@ public class SchemaSourceTransformerTest { private class Registrator extends AbstractSchemaSourceCache { - protected Registrator(final SchemaSourceRegistry consumer, final Class srcClass, + Registrator(final SchemaSourceRegistry consumer, final Class srcClass, final Costs cost) { super(consumer, srcClass, cost); } diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java index 5948d000fe..32ae99eb25 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseConstraintsTest.java @@ -7,36 +7,37 @@ */ package org.opendaylight.yangtools.yang.model.util; +import static org.junit.Assert.assertEquals; + import com.google.common.base.Optional; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; -import static org.junit.Assert.assertEquals; - public class BaseConstraintsTest { @Test public void canCreateConstraints() { - Number min = 5; - Number max = 99; - String description = "Any description"; - String reference = "any_ref"; - String reg_exp = "x|z"; - Optional desc = Optional.of(description); - Optional ref = Optional.of(reference); + final Number min = 5; + final Number max = 99; + final String description = "Any description"; + final String reference = "any_ref"; - LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, desc, ref); + LengthConstraint lengthCons = BaseConstraints.newLengthConstraint(min, max, Optional.of(description), + Optional.of(reference)); assertEquals("LengthConstraints Get min", min, lengthCons.getMin()); assertEquals("LengthConstraints Get max", max, lengthCons.getMax()); assertEquals("LengthConstraints Get description", description, lengthCons.getDescription()); assertEquals("LengthConstraints Get reference", reference, lengthCons.getReference()); + final String reg_exp = "x|z"; + final Optional desc = Optional.of(description); + final Optional ref = Optional.of(reference); PatternConstraint patternCons = BaseConstraints.newPatternConstraint(reg_exp, desc, ref); assertEquals("PatternConstraints Get regex", reg_exp, patternCons.getRegularExpression()); assertEquals("PatternConstraints Get description", description, patternCons.getDescription()); assertEquals("PatternConstraints Get reference", reference, patternCons.getReference()); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java index aefdf8a394..2ed2274cce 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BaseTypesTest.java @@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.model.util; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import org.junit.Test; public class BaseTypesTest { diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java index 146cb48191..52063b4b88 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BinaryTypeTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.binaryType; + import java.util.Collections; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Status; @@ -21,8 +22,8 @@ public class BinaryTypeTest { @Test public void canCreateBinaryType() { - BinaryTypeDefinition binType = binaryType(); - BinaryTypeDefinition binType1 = binaryType(); + final BinaryTypeDefinition binType = binaryType(); + final BinaryTypeDefinition binType1 = binaryType(); assertEquals(0, binType.getLengthConstraints().size()); assertNull(binType.getDefaultValue()); @@ -42,4 +43,4 @@ public class BinaryTypeTest { assertFalse("binType shouldn't equal to object of other type", binType.equals("str")); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java index 5507357018..b4054de4cc 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.doReturn; + import java.util.Collections; import org.junit.Test; import org.mockito.Mock; @@ -27,17 +28,17 @@ public class BitsTypeTest { private BitsTypeDefinition.Bit bit; @Test - public void canCreateBitsType(){ + public void canCreateBitsType() { MockitoAnnotations.initMocks(this); doReturn("test").when(bit).getName(); - QName qName = QName.create("TestQName"); - SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true); + QName qname = QName.create("TestQName"); + SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true); BitsTypeDefinition bitsType = BaseTypes.bitsTypeBuilder(schemaPath).addBit(bit).build(); assertNull("Description is not null", bitsType.getDescription()); - assertEquals("QName", qName, bitsType.getQName()); + assertEquals("QName", qname, bitsType.getQName()); assertNull("Should be null", bitsType.getUnits()); assertNotEquals("Description should not be null", null, bitsType.toString()); assertNull("Reference is not null", bitsType.getReference()); @@ -56,4 +57,4 @@ public class BitsTypeTest { } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java index 56253d9d29..7c57e81947 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BooleanTypeTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.booleanType; + import java.util.Collections; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Status; @@ -20,27 +21,20 @@ public class BooleanTypeTest { @Test public void canCreateBooleanType() { - BooleanTypeDefinition boolType = booleanType(); - String stringBoolType = boolType.toString(); + final BooleanTypeDefinition boolType = booleanType(); + final String stringBoolType = boolType.toString(); assertEquals("getPath gives List of BOOLEAN_QNAME", Collections.singletonList(BaseTypes.BOOLEAN_QNAME), boolType.getPath().getPathFromRoot()); - assertEquals("getQName gives BOOLEAN_QNAME", BaseTypes.BOOLEAN_QNAME, boolType.getQName()); - assertNull(boolType.getDescription()); - String strPath = boolType.getPath().toString(); + final String strPath = boolType.getPath().toString(); assertTrue("Should contain string of getPath", stringBoolType.contains(strPath)); - assertNull("Should be null", boolType.getUnits()); - assertEquals("Base type is null", null, boolType.getBaseType()); - assertNull("Default value is null", boolType.getDefaultValue()); - assertEquals("Status CURRENT", Status.CURRENT, boolType.getStatus()); - assertEquals("Should contain empty list", Collections.EMPTY_LIST, boolType.getUnknownSchemaNodes()); } } diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Bug4969Test.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Bug4969Test.java index 271dd708f0..96de5bab22 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Bug4969Test.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Bug4969Test.java @@ -15,10 +15,10 @@ import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; public class Bug4969Test { @Test public void testRegex() { - RevisionAwareXPath xPath = new RevisionAwareXPathImpl( - "nd:network[nd:network-id=current()/../network-ref]/nd:node[nd:node-id=current()/../node-ref]/termination-point/tp-id", - true); + RevisionAwareXPath xpath = new RevisionAwareXPathImpl( + "nd:network[nd:network-id=current()/../network-ref]/nd:node[nd:node-id=current()/../node-ref]" + + "/termination-point/tp-id", true); assertEquals("nd:network/nd:node/termination-point/tp-id", - SchemaContextUtil.stripConditionsFromXPathString(xPath)); + SchemaContextUtil.stripConditionsFromXPathString(xpath)); } } diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java index d5a7243f44..aae6a5ef3b 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java @@ -7,7 +7,15 @@ */ package org.opendaylight.yangtools.yang.model.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.NoSuchElementException; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -15,9 +23,6 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; - -import java.util.Collections; -import java.util.NoSuchElementException; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; @@ -25,12 +30,6 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - public class DataNodeIteratorTest { private DataNodeIterator dataNodeIterator; @@ -41,12 +40,12 @@ public class DataNodeIteratorTest { this.dataNodeIterator = new DataNodeIterator(dataNodeContainer); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void createDataNodeIteratorWithNullArgument() { new DataNodeIterator(null); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void removeFromEmptyDataNodeContainer() { dataNodeIterator.remove(); } @@ -83,7 +82,8 @@ public class DataNodeIteratorTest { final Set cases = Sets.newHashSet(mockedCase1, mockedCase2); doReturn(cases).when(mockedChoice).getCases(); - final Set childNodes = Sets.newHashSet(mockedAugmentingContainer, mockedContainer, mockedList, mockedChoice); + final Set childNodes = Sets.newHashSet(mockedAugmentingContainer, mockedContainer, mockedList, + mockedChoice); doReturn(childNodes).when(mockedModule).getChildNodes(); final NotificationDefinition mockedNotification = mock(NotificationDefinition.class); @@ -120,4 +120,4 @@ public class DataNodeIteratorTest { assertTrue(dataNodeIterator.allLists().contains(mockedListInRpcInputContainer)); assertTrue(dataNodeIterator.allGroupings().contains(mockedGrouping)); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java index 9c021d91c1..366e81b912 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EmptyTypeTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.opendaylight.yangtools.yang.model.util.type.BaseTypes.emptyType; + import java.util.Collections; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Status; @@ -34,4 +35,4 @@ public class EmptyTypeTest { assertEquals("UnknownSchemaNodes", Collections.EMPTY_LIST, emptyType.getUnknownSchemaNodes()); assertTrue("toString", emptyType.toString().contains("empty")); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java index 46db0ed9c0..5bf00d6018 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/Int8Test.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.yang.model.util; import static org.junit.Assert.assertTrue; + import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/LeafrefTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/LeafrefTest.java index 2cd6969852..2e4be322a1 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/LeafrefTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/LeafrefTest.java @@ -31,9 +31,12 @@ public class LeafrefTest { final RevisionAwareXPathImpl revision = new RevisionAwareXPathImpl("/test:Cont1/test:List1", false); final RevisionAwareXPathImpl revision2 = new RevisionAwareXPathImpl("/test:Cont1/test:List2", false); - final LeafrefTypeDefinition leafref = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision).build(); - final LeafrefTypeDefinition leafref2 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision2).build(); - final LeafrefTypeDefinition leafref3 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision).build(); + final LeafrefTypeDefinition leafref = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision) + .build(); + final LeafrefTypeDefinition leafref2 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision2) + .build(); + final LeafrefTypeDefinition leafref3 = BaseTypes.leafrefTypeBuilder(schemaPath).setPathStatement(revision) + .build(); final LeafrefTypeDefinition leafref4 = leafref; assertNotNull("Object 'leafref' shouldn't be null.", leafref); @@ -45,10 +48,13 @@ public class LeafrefTest { assertNull(leafref.getDescription()); assertNull(leafref.getReference()); assertEquals("Status of 'leafref' is current.", Status.CURRENT, leafref.getStatus()); - assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.", leafref.getUnknownSchemaNodes().isEmpty()); - assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision, leafref.getPathStatement()); + assertTrue("Object 'leafref' shouldn't have any unknown schema nodes.", + leafref.getUnknownSchemaNodes().isEmpty()); + assertEquals("Revision aware XPath of 'leafref' should be '/test:Cont1/test:List1'.", revision, + leafref.getPathStatement()); assertNotNull("String representation of 'leafref' shouldn't be null.", leafref.toString()); - assertNotEquals("Hash codes of two different object of type Leafref shouldn't be equal.", leafref.hashCode(), leafref2.hashCode()); + assertNotEquals("Hash codes of two different object of type Leafref shouldn't be equal.", leafref.hashCode(), + leafref2.hashCode()); assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref3)); assertTrue("Objects of type Leafref should be equal.", leafref.equals(leafref4)); assertFalse("Objects of type Leafref shouldn't be equal.", leafref.equals(leafref2)); diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImplTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImplTest.java index 305fea505c..2465bdc4af 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImplTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImplTest.java @@ -33,8 +33,10 @@ public class PatternConstraintImplTest { final PatternConstraintImpl patternConstraint5 = new PatternConstraintImpl(regexExp2, description2, reference2); assertNotNull("Object of PatternConstraintImpl shouldn't be null.", patternConstraint); - assertEquals("Description should be 'test description'.", "test description", patternConstraint.getDescription()); - assertEquals("Error app tag shouldn't be null.", "invalid-regular-expression", patternConstraint.getErrorAppTag()); + assertEquals("Description should be 'test description'.", "test description", + patternConstraint.getDescription()); + assertEquals("Error app tag shouldn't be null.", "invalid-regular-expression", + patternConstraint.getErrorAppTag()); assertNotNull(patternConstraint.getErrorMessage()); assertEquals("Reference should be equals 'RFC 6020'.", "RFC 6020", patternConstraint.getReference()); assertEquals("Regular expression should be equls '\\D'.", "\\D", patternConstraint.getRegularExpression()); diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java index 52398a7142..acb5eaf75d 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java @@ -13,12 +13,13 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -68,17 +69,15 @@ public class SchemaContextProxyTest { private static SchemaContext mockSchema(final Module... module) { SchemaContext mock = mock(SchemaContext.class); - doReturn(Sets.newHashSet(module)).when(mock).getModules(); + doReturn(ImmutableSet.copyOf(module)).when(mock).getModules(); return mock; } - /** - *

            +    /*
                  * CFG(R)
                  *  | \
                  *  |  \
            -     * M2 <- M3
            -     * 
            + * M2 <- M3 */ @Test public void testBasic() { @@ -91,17 +90,16 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3); } - /** - *
            +    /*
                  * No root or additional modules
                  *  | \
                  *  |  \
            -     * M2 <- M3
            -     * 
            + * M2 <- M3 */ @Test public void testNull() { @@ -118,13 +116,11 @@ public class SchemaContextProxyTest { assertProxyContext(filteringSchemaContextProxy, null); } - /** - *
            +    /*
                  *  Config
                  *  | \ (NR)
                  *  |  \
            -     * M2 <- M3
            -     * 
            + * M2 <- M3 */ @Test public void testConfigDifferentRevisions() { @@ -139,25 +135,25 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, moduleConfig2, module2, module3); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, moduleConfig2, module2, module3); } - /** - *
            +    /*
                  *     CFG(R)
                  *    |      \
                  *   |         \
            -     * M2<-(NullRev)M3
            -     * 
            + * M2<-(NullRev)M3 */ @Test public void testBasicNullRevision() throws Exception { - Module moduleConfig = mockModule(CONFIG_NAME,SimpleDateFormatUtil.getRevisionFormat().parse("2013-04-05")); - Module module2 = mockModule(MODULE2_NAME, SimpleDateFormatUtil.getRevisionFormat().parse("2014-06-17")); - Module module20 = mockModule(MODULE2_NAME, null); - Module module3 = mockModule(MODULE3_NAME, SimpleDateFormatUtil.getRevisionFormat().parse("2014-06-12")); - Module module30 = mockModule(MODULE3_NAME, null); + final Module moduleConfig = mockModule(CONFIG_NAME,SimpleDateFormatUtil.getRevisionFormat() + .parse("2013-04-05")); + final Module module2 = mockModule(MODULE2_NAME, SimpleDateFormatUtil.getRevisionFormat().parse("2014-06-17")); + final Module module20 = mockModule(MODULE2_NAME, null); + final Module module3 = mockModule(MODULE3_NAME, SimpleDateFormatUtil.getRevisionFormat().parse("2014-06-12")); + final Module module30 = mockModule(MODULE3_NAME, null); mockModuleImport(module20, moduleConfig); mockModuleImport(module2, moduleConfig); @@ -166,42 +162,40 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3); } - /** - *
            +    /*
                  * CFG(R)   ROOT(R)
                  *  |         \
                  *  |          \
                  * M2          M3
            -     * 
            */ @Test public void testBasicMoreRootModules() { - Module moduleConfig = mockModule(CONFIG_NAME); - Module moduleRoot = mockModule(ROOT_NAME); - Module module2 = mockModule(MODULE2_NAME); - Module module3 = mockModule(MODULE3_NAME); + final Module moduleConfig = mockModule(CONFIG_NAME); + final Module moduleRoot = mockModule(ROOT_NAME); + final Module module2 = mockModule(MODULE2_NAME); + final Module module3 = mockModule(MODULE3_NAME); mockModuleImport(module2, moduleConfig); mockModuleImport(module3, moduleRoot); SchemaContext schemaContext = mockSchema(moduleConfig, moduleRoot, module2, module3); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleRoot, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleRoot, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleRoot, module3, moduleConfig, module2); } - /** - *
            +    /*
                  * CFG(R)
                  *  |
                  *  |
            -     * M2 <- M3
            -     * 
            + * M2 <- M3 */ @Test public void testChainNotDepend() { @@ -214,17 +208,16 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2); } - /** - *
            +    /*
                  * CFG(R)
                  *  |
                  *  |
            -     * M2 -> M3 -> M4 -> M5
            -     * 
            + * M2 -> M3 -> M4 -> M5 */ @Test public void testChainDependMulti() { @@ -240,17 +233,16 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4, module5); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4, module5); } - /** - *
            +    /*
                  * CFG(R)
                  *  |
                  *  |
            -     * M2 -> M3 <- M4
            -     * 
            + * M2 -> M3 <- M4 */ @Test public void testChainNotDependMulti() { @@ -264,25 +256,24 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3); } - /** - *
            +    /*
                  *  CFG(R)
                  *  | \ \ \
                  *  |  \ \ \
                  * M2 M3 M4 M5
            -     * 
            */ @Test public void testChainNotMulti() { - Module moduleConfig = mockModule(CONFIG_NAME); - Module module2 = mockModule(MODULE2_NAME); - Module module3 = mockModule(MODULE3_NAME); - Module module4 = mockModule(MODULE4_NAME); - Module module5 = mockModule(MODULE5_NAME); + final Module moduleConfig = mockModule(CONFIG_NAME); + final Module module2 = mockModule(MODULE2_NAME); + final Module module3 = mockModule(MODULE3_NAME); + final Module module4 = mockModule(MODULE4_NAME); + final Module module5 = mockModule(MODULE5_NAME); mockModuleImport(module2, moduleConfig); mockModuleImport(module3, moduleConfig); @@ -291,17 +282,16 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4, module5); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4, module5); } - /** - *
            +    /*
                  * CFG(R)
                  *  | \
                  *  |  \
            -     * M2 <- M3 M4=M3(Different revision)
            -     * 
            + * M2 <- M3 M4=M3(Different revision) */ @Test public void testBasicRevisionChange() throws Exception { @@ -317,16 +307,15 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3); } - /** - *
            +    /*
                  * CFG(R)
                  * |
            -     * M2 -(no revision)-> M3(R2) ... M3(R1)
            -     * 
            + * M2 -(no revision)-> M3(R2) ... M3(R1) */ @Test public void testImportNoRevision() { @@ -340,20 +329,19 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module30, module31); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module31); } - /** - *
            +    /*
                  * CFG(R)
                  * |   \
                  * |    \
            -     * |    M2 -> M3
            +     * |    M2 -> M3
                  * |
            -     * M41(S) => M4
            -     * 
            + * M41(S) => M4 */ @Test public void testBasicSubmodule() { @@ -369,16 +357,13 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, + moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4); } - /** - *
            -     *
            -     * M2 -> M3 -> M4 -> M5
            -     *
            -     * 
            + /* + * M2 -> M3 -> M4 -> M5 */ @Test public void testChainAdditionalModules() { @@ -393,21 +378,19 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(module2, module3, module4, module5); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Sets.newHashSet(module2), null); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, + Collections.singleton(module2), null); assertProxyContext(filteringSchemaContextProxy, module2, module3, module4, module5); } - /** - *
            +    /*
                  *
                  * CFG(R)
                  *  |
                  *  |       M5
                  * M2
                  *
            -     * M3 -> M4
            -     *
            -     * 
            + * M3 -> M4 */ @Test public void testChainAdditionalModulesConfig() { @@ -423,7 +406,8 @@ public class SchemaContextProxyTest { SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4, module5); - FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, Sets.newHashSet(module3), moduleConfig); + FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, + Collections.singleton(module3), moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4); } @@ -432,10 +416,10 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class); - final Set childNodes = Sets.newHashSet(mockedContainer); + final Set childNodes = Collections.singleton(mockedContainer); doReturn(childNodes).when(moduleConfig).getChildNodes(); final Set dataDefinitions = filteringSchemaContextProxy.getDataDefinitions(); @@ -447,13 +431,14 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final NotificationDefinition mockedNotification = mock(NotificationDefinition.class); - final Set notifications = Sets.newHashSet(mockedNotification); + final Set notifications = Collections.singleton(mockedNotification); doReturn(notifications).when(moduleConfig).getNotifications(); - final Set schemaContextProxyNotifications = filteringSchemaContextProxy.getNotifications(); + final Set schemaContextProxyNotifications = + filteringSchemaContextProxy.getNotifications(); assertTrue(schemaContextProxyNotifications.contains(mockedNotification)); } @@ -462,10 +447,10 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final RpcDefinition mockedRpc = mock(RpcDefinition.class); - final Set rpcs = Sets.newHashSet(mockedRpc); + final Set rpcs = Collections.singleton(mockedRpc); doReturn(rpcs).when(moduleConfig).getRpcs(); final Set operations = filteringSchemaContextProxy.getOperations(); @@ -477,7 +462,7 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final ExtensionDefinition mockedExtension = mock(ExtensionDefinition.class); final List extensions = Lists.newArrayList(mockedExtension); @@ -492,7 +477,7 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final UnknownSchemaNode mockedUnknownSchemaNode = mock(UnknownSchemaNode.class); final List unknownSchemaNodes = Lists.newArrayList(mockedUnknownSchemaNode); @@ -508,13 +493,14 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final TypeDefinition mockedTypeDefinition = mock(TypeDefinition.class); - final Set> typeDefinitions = Sets.newHashSet(mockedTypeDefinition); + final Set> typeDefinitions = Collections.singleton(mockedTypeDefinition); doReturn(typeDefinitions).when(moduleConfig).getTypeDefinitions(); - final Set> schemaContextProxyTypeDefinitions = filteringSchemaContextProxy.getTypeDefinitions(); + final Set> schemaContextProxyTypeDefinitions = filteringSchemaContextProxy + .getTypeDefinitions(); assertTrue(schemaContextProxyTypeDefinitions.contains(mockedTypeDefinition)); } @@ -523,10 +509,10 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class); - final Set childNodes = Sets.newHashSet(mockedContainer); + final Set childNodes = Collections.singleton(mockedContainer); doReturn(childNodes).when(moduleConfig).getChildNodes(); final Set schemaContextProxyChildNodes = filteringSchemaContextProxy.getChildNodes(); @@ -538,10 +524,10 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); final GroupingDefinition mockedGrouping = mock(GroupingDefinition.class); - final Set groupings = Sets.newHashSet(mockedGrouping); + final Set groupings = Collections.singleton(mockedGrouping); doReturn(groupings).when(moduleConfig).getGroupings(); final Set schemaContextProxyGroupings = filteringSchemaContextProxy.getGroupings(); @@ -553,38 +539,35 @@ public class SchemaContextProxyTest { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, - Sets.newHashSet(), moduleConfig); + new HashSet<>(), moduleConfig); - final QName qName = QName.create("config-namespace", "2016-08-11", "cont"); + final QName qname = QName.create("config-namespace", "2016-08-11", "cont"); final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class); doReturn(mockedContainer).when(moduleConfig).getDataChildByName(any(QName.class)); - final DataSchemaNode dataSchemaNode = filteringSchemaContextProxy.getDataChildByName(qName); + final DataSchemaNode dataSchemaNode = filteringSchemaContextProxy.getDataChildByName(qname); assertTrue(dataSchemaNode instanceof ContainerSchemaNode); } - private static void assertProxyContext(final FilteringSchemaContextProxy filteringSchemaContextProxy, final Module... expected) { - - Set modSet = Sets.newHashSet(); - - if (expected!=null) { - - modSet = Sets.newHashSet(expected); - } + private static void assertProxyContext(final FilteringSchemaContextProxy filteringSchemaContextProxy, + final Module... expected) { + final Set modSet = expected != null ? ImmutableSet.copyOf(expected) : new HashSet<>(); Set modSetFiltering = filteringSchemaContextProxy.getModules(); assertEquals(modSet, modSetFiltering); //asserting collections - if (expected!=null) { + if (expected != null) { for (final Module module : expected) { - assertEquals(module, filteringSchemaContextProxy.findModuleByName(module.getName(), module.getRevision())); + assertEquals(module, filteringSchemaContextProxy.findModuleByName(module.getName(), + module.getRevision())); Set mod = filteringSchemaContextProxy.findModuleByNamespace(module.getNamespace()); assertTrue(mod.contains(module)); - assertEquals(module, filteringSchemaContextProxy.findModuleByNamespaceAndRevision(module.getNamespace(), module.getRevision())); + assertEquals(module, filteringSchemaContextProxy.findModuleByNamespaceAndRevision(module.getNamespace(), + module.getRevision())); assertEquals(module.getSource(), filteringSchemaContextProxy.getModuleSource(module).get()); } @@ -593,26 +576,19 @@ public class SchemaContextProxyTest { private static FilteringSchemaContextProxy createProxySchemaCtx(final SchemaContext schemaContext, final Set additionalModules, final Module... modules) { - Set modulesSet = new HashSet<>(); - - if (modules!=null) { - - modulesSet = Sets.newHashSet(modules); - + if (modules != null) { + modulesSet = ImmutableSet.copyOf(modules); } - return new FilteringSchemaContextProxy(schemaContext, createModuleIds(modulesSet) , createModuleIds(additionalModules)); + return new FilteringSchemaContextProxy(schemaContext, createModuleIds(modulesSet), + createModuleIds(additionalModules)); } private static Set createModuleIds(final Set modules) { - - Set moduleIds = Sets.newHashSet(); - - if (modules!=null && modules.size()>0) { - + Set moduleIds = new HashSet<>(); + if (modules != null) { for (Module module : modules) { - moduleIds.add(new ModuleId(module.getName(), module.getRevision())); } } @@ -621,7 +597,6 @@ public class SchemaContextProxyTest { } private static void mockSubmodules(final Module mainModule, final Module... submodules) { - Set submodulesSet = new HashSet<>(); submodulesSet.addAll(Arrays.asList(submodules)); @@ -629,7 +604,7 @@ public class SchemaContextProxyTest { } private static void mockModuleImport(final Module importer, final Module... imports) { - Set mockedImports = Sets.newHashSet(); + Set mockedImports = new HashSet<>(); for (final Module module : imports) { mockedImports.add(new ModuleImport() { @Override @@ -654,7 +629,6 @@ public class SchemaContextProxyTest { @Override public String toString() { - return String.format("Module: %s, revision:%s", module.getName(), module.getRevision()); } }); @@ -675,16 +649,16 @@ public class SchemaContextProxyTest { } //mock module with default revision - private static Module mockModule(final String mName) { + private static Module mockModule(final String name) { Module mockedModule = mock(Module.class); - doReturn(mName).when(mockedModule).getName(); + doReturn(name).when(mockedModule).getName(); doReturn(revision).when(mockedModule).getRevision(); - final URI newNamespace = URI.create(namespace.toString() + ":" + mName); + final URI newNamespace = URI.create(namespace.toString() + ":" + name); doReturn(newNamespace).when(mockedModule).getNamespace(); doReturn(QNameModule.create(newNamespace, revision)).when(mockedModule).getQNameModule(); doReturn(TEST_SOURCE).when(mockedModule).getSource(); - doReturn(Sets.newHashSet()).when(mockedModule).getSubmodules(); + doReturn(new HashSet<>()).when(mockedModule).getSubmodules(); doReturn(mockedModule.getQNameModule().toString()).when(mockedModule).toString(); mockModuleImport(mockedModule); diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java index d69af03bb3..d7b751322b 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.yang.model.util; import static org.junit.Assert.assertEquals; + import java.util.Collections; import org.junit.Test; import org.mockito.Mock; @@ -21,31 +22,33 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; public class SchemaContextUtilTest { - @Mock private SchemaContext mockSchemaContext; - @Mock private Module mockModule; + @Mock + private SchemaContext mockSchemaContext; + @Mock + private Module mockModule; @Test public void testFindDummyData() { MockitoAnnotations.initMocks(this); - QName qName = QName.create("TestQName"); - SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true); + QName qname = QName.create("TestQName"); + SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qname), true); assertEquals("Should be null. Module TestQName not found", null, SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath)); - RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true); + RevisionAwareXPath xpath = new RevisionAwareXPathImpl("/bookstore/book/title", true); assertEquals("Should be null. Module bookstore not found", null, - SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath)); + SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xpath)); SchemaNode schemaNode = BaseTypes.int32Type(); - RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false); + RevisionAwareXPath xpathRelative = new RevisionAwareXPathImpl("../prefix", false); assertEquals("Should be null, Module prefix not found", null, SchemaContextUtil.findDataSchemaNodeForRelativeXPath( - mockSchemaContext, mockModule, schemaNode, xPathRelative)); + mockSchemaContext, mockModule, schemaNode, xpathRelative)); assertEquals("Should be null. Module TestQName not found", null, - SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName))); + SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qname))); assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode)); } -} \ No newline at end of file +} diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java index cdae5415c0..6ec194712e 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaNodeUtilsTest.java @@ -7,18 +7,19 @@ */ package org.opendaylight.yangtools.yang.model.util; -import com.google.common.base.Optional; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.mockito.MockitoAnnotations; -import org.mockito.Mock; -import org.junit.Before; -import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; -import org.junit.Test; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; -import static org.hamcrest.CoreMatchers.instanceOf; + +import com.google.common.base.Optional; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; public class SchemaNodeUtilsTest { diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/BitImplTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/BitImplTest.java index 5e640ae744..0310c2bce6 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/BitImplTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/BitImplTest.java @@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.model.util.type; import static java.util.Collections.emptyList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; + import java.net.URI; import java.net.URISyntaxException; import java.util.Date; @@ -35,11 +36,10 @@ public class BitImplTest { QName qnameA2 = QName.create(uriA2, new Date(7000000), "some nameA2"); SchemaPath schemaPathA = SchemaPath.create(true, qnameA1, qnameA2); - QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1"); - QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2"); - SchemaPath schemaPathB = SchemaPath.create(true, qnameB1, qnameB2); + final QName qnameB1 = QName.create(uriB1, new Date(6000000), "some nameB1"); + final QName qnameB2 = QName.create(uriB2, new Date(7000000), "some nameB2"); + final SchemaPath schemaPathB = SchemaPath.create(true, qnameB1, qnameB2); - BitImpl biB; BitImpl biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList()); assertEquals("biA should equals to itsefl", biA, biA); @@ -48,7 +48,7 @@ public class BitImplTest { // // test schemaPath biA = new BitImpl(schemaPathA, 55L, "description", "reference", Status.CURRENT, emptyList()); - biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList()); + BitImpl biB = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList()); assertFalse("biA shouldn't equal to biB", biA.equals(biB)); biA = new BitImpl(schemaPathB, 55L, "description", "reference", Status.CURRENT, emptyList()); @@ -74,6 +74,7 @@ public class BitImplTest { assertEquals("Incorrect value for unknown nodes.", emptyList(), biA.getUnknownSchemaNodes()); // test of toString method - assertEquals("toString method doesn't return correct value", "Bit[name=some nameA2, position=55]", biA.toString()); + assertEquals("toString method doesn't return correct value", "Bit[name=some nameA2, position=55]", + biA.toString()); } } diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/TypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/TypeTest.java index de7272c443..bc742e5f50 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/TypeTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/type/TypeTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; + import com.google.common.base.Optional; import java.util.ArrayList; import org.junit.Test; @@ -61,10 +62,10 @@ public class TypeTest { SCHEMA_PATH).build(); hashCodeEqualsToStringTest(derivedBinaryType1, derivedBinaryType2); - final RestrictedBinaryType restrictedBinaryType1 = (RestrictedBinaryType)RestrictedTypes.newBinaryBuilder - (baseBinaryType1, SCHEMA_PATH).buildType(); - final RestrictedBinaryType restrictedBinaryType2 = (RestrictedBinaryType)RestrictedTypes.newBinaryBuilder - (baseBinaryType2, SCHEMA_PATH).buildType(); + final RestrictedBinaryType restrictedBinaryType1 = (RestrictedBinaryType)RestrictedTypes.newBinaryBuilder( + baseBinaryType1, SCHEMA_PATH).buildType(); + final RestrictedBinaryType restrictedBinaryType2 = (RestrictedBinaryType)RestrictedTypes.newBinaryBuilder( + baseBinaryType2, SCHEMA_PATH).buildType(); hashCodeEqualsToStringTest(restrictedBinaryType1, restrictedBinaryType2); final LengthRestrictedTypeBuilder lengthRestrictedTypeBuilder = RestrictedTypes @@ -82,10 +83,10 @@ public class TypeTest { final BaseBooleanType baseBooleanType2 = (BaseBooleanType)BaseTypes.booleanType(); hashCodeEqualsToStringTest(baseBooleanType1, baseBooleanType2); - final DerivedBooleanType derivedBooleanType1 = (DerivedBooleanType)DerivedTypes.derivedTypeBuilder - (baseBooleanType1, SCHEMA_PATH).build(); - final DerivedBooleanType derivedBooleanType2 = (DerivedBooleanType)DerivedTypes.derivedTypeBuilder - (baseBooleanType1, SCHEMA_PATH).build(); + final DerivedBooleanType derivedBooleanType1 = (DerivedBooleanType)DerivedTypes.derivedTypeBuilder( + baseBooleanType1, SCHEMA_PATH).build(); + final DerivedBooleanType derivedBooleanType2 = (DerivedBooleanType)DerivedTypes.derivedTypeBuilder( + baseBooleanType1, SCHEMA_PATH).build(); hashCodeEqualsToStringTest(derivedBooleanType1, derivedBooleanType2); restrictedBuilderTest(RestrictedTypes.newBooleanBuilder(baseBooleanType1, SCHEMA_PATH), RestrictedTypes @@ -104,15 +105,15 @@ public class TypeTest { final IdentityrefTypeDefinition identityrefTypeDefinition2 = identityrefTypeBuilder2.build(); hashCodeEqualsToStringTest(identityrefTypeDefinition1, identityrefTypeDefinition2); - final DerivedIdentityrefType derivedIdentityrefType1 = (DerivedIdentityrefType)DerivedTypes.derivedTypeBuilder - (identityrefTypeDefinition1, SCHEMA_PATH).build(); - final DerivedIdentityrefType derivedIdentityrefType2 = (DerivedIdentityrefType)DerivedTypes.derivedTypeBuilder - (identityrefTypeDefinition2, SCHEMA_PATH).build(); + final DerivedIdentityrefType derivedIdentityrefType1 = (DerivedIdentityrefType)DerivedTypes.derivedTypeBuilder( + identityrefTypeDefinition1, SCHEMA_PATH).build(); + final DerivedIdentityrefType derivedIdentityrefType2 = (DerivedIdentityrefType)DerivedTypes.derivedTypeBuilder( + identityrefTypeDefinition2, SCHEMA_PATH).build(); hashCodeEqualsToStringTest(derivedIdentityrefType1, derivedIdentityrefType2); concreteBuilderTest(identityrefTypeDefinition1, derivedIdentityrefType1); - restrictedBuilderTest(RestrictedTypes.newIdentityrefBuilder(derivedIdentityrefType1, SCHEMA_PATH), RestrictedTypes - .newIdentityrefBuilder(derivedIdentityrefType2, SCHEMA_PATH)); + restrictedBuilderTest(RestrictedTypes.newIdentityrefBuilder(derivedIdentityrefType1, SCHEMA_PATH), + RestrictedTypes.newIdentityrefBuilder(derivedIdentityrefType2, SCHEMA_PATH)); } @Test @@ -146,10 +147,10 @@ public class TypeTest { final BaseEmptyType baseEmptyType2 = (BaseEmptyType)BaseTypes.emptyType(); hashCodeEqualsToStringTest(baseEmptyType1, baseEmptyType2); - final DerivedEmptyType derivedEmptyType1 = (DerivedEmptyType)DerivedTypes.derivedTypeBuilder - (baseEmptyType1, SCHEMA_PATH).build(); - final DerivedEmptyType derivedEmptyType2 = (DerivedEmptyType)DerivedTypes.derivedTypeBuilder - (baseEmptyType2, SCHEMA_PATH).build(); + final DerivedEmptyType derivedEmptyType1 = (DerivedEmptyType)DerivedTypes.derivedTypeBuilder( + baseEmptyType1, SCHEMA_PATH).build(); + final DerivedEmptyType derivedEmptyType2 = (DerivedEmptyType)DerivedTypes.derivedTypeBuilder( + baseEmptyType2, SCHEMA_PATH).build(); hashCodeEqualsToStringTest(derivedEmptyType1, derivedEmptyType2); restrictedBuilderTest(RestrictedTypes.newEmptyBuilder(baseEmptyType1, SCHEMA_PATH), @@ -174,11 +175,13 @@ public class TypeTest { final InstanceIdentifierTypeBuilder instanceIdentifierBuilder1 = RestrictedTypes .newInstanceIdentifierBuilder(baseInstanceIdentifierType1, SCHEMA_PATH); instanceIdentifierBuilder1.setRequireInstance(true); - final InstanceIdentifierTypeDefinition instanceIdentifierTypeDefinition1 = instanceIdentifierBuilder1.buildType(); + final InstanceIdentifierTypeDefinition instanceIdentifierTypeDefinition1 = instanceIdentifierBuilder1 + .buildType(); final InstanceIdentifierTypeBuilder instanceIdentifierBuilder2 = RestrictedTypes .newInstanceIdentifierBuilder(baseInstanceIdentifierType1, SCHEMA_PATH); instanceIdentifierBuilder2.setRequireInstance(true); - final InstanceIdentifierTypeDefinition instanceIdentifierTypeDefinition2 = instanceIdentifierBuilder2.buildType(); + final InstanceIdentifierTypeDefinition instanceIdentifierTypeDefinition2 = instanceIdentifierBuilder2 + .buildType(); hashCodeEqualsToStringTest(instanceIdentifierTypeDefinition2, instanceIdentifierTypeDefinition1); concreteBuilderTest(baseInstanceIdentifierType1, derivedInstanceIdentifierType1); } @@ -198,10 +201,10 @@ public class TypeTest { testInstance(BaseInt32Type.INSTANCE, integerTypeDefinition32); testInstance(BaseInt64Type.INSTANCE, integerTypeDefinition64); - final RestrictedIntegerType restrictedIntegerType1 = (RestrictedIntegerType)RestrictedTypes.newIntegerBuilder - (integerTypeDefinition8, SCHEMA_PATH).buildType(); - final RestrictedIntegerType restrictedIntegerType2 = (RestrictedIntegerType)RestrictedTypes.newIntegerBuilder - (BaseInt8Type.INSTANCE, SCHEMA_PATH).buildType(); + final RestrictedIntegerType restrictedIntegerType1 = (RestrictedIntegerType)RestrictedTypes.newIntegerBuilder( + integerTypeDefinition8, SCHEMA_PATH).buildType(); + final RestrictedIntegerType restrictedIntegerType2 = (RestrictedIntegerType)RestrictedTypes.newIntegerBuilder( + BaseInt8Type.INSTANCE, SCHEMA_PATH).buildType(); hashCodeEqualsToStringTest(restrictedIntegerType1, restrictedIntegerType2); final UnsignedIntegerTypeDefinition integerTypeDefinitionu8 = BaseTypes.uint8Type(); @@ -237,7 +240,8 @@ public class TypeTest { concreteBuilderTest(integerTypeDefinition8, derivedIntegerType1); concreteBuilderTest(integerTypeDefinitionu8, derivedUnsignedType2); - final DerivedTypeBuilder derivedTypeBuilder = DerivedTypes.derivedTypeBuilder(integerTypeDefinition8, SCHEMA_PATH); + final DerivedTypeBuilder derivedTypeBuilder = DerivedTypes.derivedTypeBuilder(integerTypeDefinition8, + SCHEMA_PATH); derivedTypeBuilder.setDefaultValue(1); derivedTypeBuilder.setDescription("test-description"); derivedTypeBuilder.setReference("test-reference"); @@ -299,10 +303,10 @@ public class TypeTest { @Test public void enumerationTypeTest() { - final BaseEnumerationType baseEnumerationType1 = (BaseEnumerationType)BaseTypes.enumerationTypeBuilder - (SCHEMA_PATH).build(); - final BaseEnumerationType baseEnumerationType2 = (BaseEnumerationType)BaseTypes.enumerationTypeBuilder - (SCHEMA_PATH).build(); + final BaseEnumerationType baseEnumerationType1 = (BaseEnumerationType)BaseTypes.enumerationTypeBuilder( + SCHEMA_PATH).build(); + final BaseEnumerationType baseEnumerationType2 = (BaseEnumerationType)BaseTypes.enumerationTypeBuilder( + SCHEMA_PATH).build(); hashCodeEqualsToStringTest(baseEnumerationType1, baseEnumerationType2); assertEquals(baseEnumerationType1.getValues(), baseEnumerationType2.getValues()); @@ -369,16 +373,16 @@ public class TypeTest { @Test public void abstractTypeDefinitionQnameTest() { - final AbstractTypeDefinition abstractTypeDefinition = (AbstractTypeDefinition)BaseTypes.decimalTypeBuilder - (SCHEMA_PATH).setFractionDigits(1).buildType(); + final AbstractTypeDefinition abstractTypeDefinition = (AbstractTypeDefinition) + BaseTypes.decimalTypeBuilder(SCHEMA_PATH).setFractionDigits(1).buildType(); assertEquals(abstractTypeDefinition.getQName(), Q_NAME); } @Test public void abstractDerivedTypeTest() { final BaseBinaryType baseBinaryType1 = BaseBinaryType.INSTANCE; - final AbstractDerivedType abstractDerivedType = (AbstractDerivedType) DerivedTypes.derivedTypeBuilder(baseBinaryType1, - SCHEMA_PATH).build(); + final AbstractDerivedType abstractDerivedType = (AbstractDerivedType) + DerivedTypes.derivedTypeBuilder(baseBinaryType1, SCHEMA_PATH).build(); assertEquals(abstractDerivedType.getDescription(), null); assertEquals(abstractDerivedType.getReference(), null); assertEquals(abstractDerivedType.getStatus().toString(), "CURRENT"); @@ -394,9 +398,10 @@ public class TypeTest { @Test public void concreteTypeBuilderBuildTest() { - final BaseEnumerationType baseEnumerationType1 = (BaseEnumerationType)BaseTypes.enumerationTypeBuilder - (SCHEMA_PATH).build(); - final ConcreteTypeBuilder concreteTypeBuilder = ConcreteTypes.concreteTypeBuilder(baseEnumerationType1, SCHEMA_PATH); + final BaseEnumerationType baseEnumerationType1 = (BaseEnumerationType) + BaseTypes.enumerationTypeBuilder(SCHEMA_PATH).build(); + final ConcreteTypeBuilder concreteTypeBuilder = ConcreteTypes.concreteTypeBuilder( + baseEnumerationType1, SCHEMA_PATH); final TypeDefinition typeDefinition = concreteTypeBuilder.build(); assertNotNull(typeDefinition); } @@ -434,7 +439,7 @@ public class TypeTest { final UnresolvedNumber min = UnresolvedNumber.min(); final UnresolvedNumber max = UnresolvedNumber.max(); final LengthConstraint lengthConstraint = BaseConstraints.newLengthConstraint(min, max, absent, absent); - final RangeConstraint rangeConstraint= BaseConstraints.newRangeConstraint(min, max, absent, absent); + final RangeConstraint rangeConstraint = BaseConstraints.newRangeConstraint(min, max, absent, absent); final EnumPair enumPair = EnumPairBuilder.create("enum1", 1).setDescription("description") .setReference("reference").setUnknownSchemaNodes(mock(UnknownSchemaNode.class)).build(); @@ -451,7 +456,7 @@ public class TypeTest { BIT_A, "error msg", "other important messages"); assertEquals(invalidBitDefinitionException.getOffendingBit(), BIT_A); - final InvalidEnumDefinitionException invalidEnumDefinitionException= new InvalidEnumDefinitionException( + final InvalidEnumDefinitionException invalidEnumDefinitionException = new InvalidEnumDefinitionException( enumPair, "error msg", "other important messages"); assertEquals(invalidEnumDefinitionException.getOffendingEnum(), enumPair); } @@ -473,11 +478,11 @@ public class TypeTest { @Test(expected = InvalidEnumDefinitionException.class) public void invalidEnumDefinitionExceptionTest() { - final UnknownSchemaNode UNKNOWN_SCHEMA_NODE= mock(UnknownSchemaNode.class); + final UnknownSchemaNode unknown = mock(UnknownSchemaNode.class); final EnumPair enumPair1 = EnumPairBuilder.create("enum1", 1).setDescription("description") - .setReference("reference").setUnknownSchemaNodes(UNKNOWN_SCHEMA_NODE).build(); + .setReference("reference").setUnknownSchemaNodes(unknown).build(); final EnumPair enumPair2 = EnumPairBuilder.create("enum", 1).setDescription("description") - .setReference("reference").setUnknownSchemaNodes(UNKNOWN_SCHEMA_NODE).build(); + .setReference("reference").setUnknownSchemaNodes(unknown).build(); final EnumerationTypeBuilder enumerationTypeBuilder = BaseTypes.enumerationTypeBuilder(SCHEMA_PATH); enumerationTypeBuilder.addEnum(enumPair1); enumerationTypeBuilder.addEnum(enumPair2); @@ -500,7 +505,8 @@ public class TypeTest { hashCodeEqualsToStringTest(typeDefinition1, typeDefinition2); } - private static void concreteBuilderTest(final TypeDefinition baseTypeDef, final TypeDefinition derivedTypeDef) { + private static void concreteBuilderTest(final TypeDefinition baseTypeDef, + final TypeDefinition derivedTypeDef) { final ConcreteTypeBuilder concreteTypeBuilder = ConcreteTypes.concreteTypeBuilder(baseTypeDef, SCHEMA_PATH); final TypeDefinition typeDefinition = concreteTypeBuilder.buildType(); assertEquals(typeDefinition.getBaseType(), derivedTypeDef.getBaseType()); -- 2.36.6