</dependency>
</dependencies>
- <!--
- Maven Site Configuration
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
- The following configuration is necessary for maven-site-plugin to
- correctly identify the correct deployment path for OpenDaylight Maven
- sites.
- -->
- <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+ <!--
+ Maven Site Configuration
- <distributionManagement>
- <site>
- <id>opendaylight-site</id>
- <url>${nexus.site.url}/${project.artifactId}/</url>
- </site>
- </distributionManagement>
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+ <distributionManagement>
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
</project>
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaListenerRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
-public abstract class AbstractSchemaListenerRegistration extends AbstractListenerRegistration<SchemaSourceListener> implements SchemaListenerRegistration {
+public abstract class AbstractSchemaListenerRegistration extends AbstractListenerRegistration<SchemaSourceListener>
+ implements SchemaListenerRegistration {
protected AbstractSchemaListenerRegistration(final SchemaSourceListener listener) {
super(listener);
}
@Beta
public abstract class AbstractSchemaRepository implements SchemaRepository, SchemaSourceRegistry {
private static final Logger LOG = LoggerFactory.getLogger(AbstractSchemaRepository.class);
- private static final ExceptionMapper<SchemaSourceException> FETCH_MAPPER = ReflectiveExceptionMapper.create("Schema source fetch", SchemaSourceException.class);
+ private static final ExceptionMapper<SchemaSourceException> 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<SourceIdentifier, ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>>> sources = new HashMap<>();
+ private final Map<SourceIdentifier, ListMultimap<Class<? extends SchemaSourceRepresentation>,
+ AbstractSchemaSourceRegistration<?>>> sources = new HashMap<>();
/*
* Schema source listeners.
@GuardedBy("this")
private final Collection<SchemaListenerRegistration> listeners = new ArrayList<>();
- private static <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> fetchSource(final SourceIdentifier id, final Iterator<AbstractSchemaSourceRegistration<?>> it) {
+ private static <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> fetchSource(
+ final SourceIdentifier id, final Iterator<AbstractSchemaSourceRegistration<?>> it) {
final AbstractSchemaSourceRegistration<?> reg = it.next();
@SuppressWarnings("unchecked")
- final CheckedFuture<? extends T, SchemaSourceException> f = ((SchemaSourceProvider<T>)reg.getProvider()).getSource(id);
+ final CheckedFuture<? extends T, SchemaSourceException> f =
+ ((SchemaSourceProvider<T>)reg.getProvider()).getSource(id);
return Futures.makeChecked(Futures.withFallback(f, new FutureFallback<T>() {
@Override
- public ListenableFuture<T> create(@Nonnull final Throwable t) throws SchemaSourceException {
- LOG.debug("Failed to acquire source from {}", reg, t);
+ public ListenableFuture<T> 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 <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(@Nonnull final SourceIdentifier id, @Nonnull final Class<T> representation) {
+ public <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(
+ @Nonnull final SourceIdentifier id, @Nonnull final Class<T> representation) {
final ArrayList<AbstractSchemaSourceRegistration<?>> sortedSchemaSourceRegistrations;
synchronized (this) {
- final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs = sources.get(id);
+ final ListMultimap<Class<? extends SchemaSourceRepresentation>, 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));
final Iterator<AbstractSchemaSourceRegistration<?>> 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<T, SchemaSourceException> fetchSourceFuture = fetchSource(id, regs);
}
@Override
+ @SuppressWarnings("checkstyle:parameterName")
public void onFailure(@Nonnull final Throwable t) {
LOG.trace("Skipping notification for encountered source {}, fetching source failed", id, t);
}
return fetchSourceFuture;
}
- private synchronized <T extends SchemaSourceRepresentation> void addSource(final PotentialSchemaSource<T> source, final AbstractSchemaSourceRegistration<T> reg) {
- ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m = sources.get(source.getSourceIdentifier());
- if (m == null) {
- m = ArrayListMultimap.create();
- sources.put(source.getSourceIdentifier(), m);
+ private synchronized <T extends SchemaSourceRepresentation> void addSource(final PotentialSchemaSource<T> source,
+ final AbstractSchemaSourceRegistration<T> reg) {
+ ListMultimap<Class<? extends SchemaSourceRepresentation>, 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<PotentialSchemaSource<?>> reps = Collections.singleton(source);
for (SchemaListenerRegistration l : listeners) {
}
}
- private synchronized <T extends SchemaSourceRepresentation> void removeSource(final PotentialSchemaSource<?> source, final SchemaSourceRegistration<?> reg) {
- final Multimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m = sources.get(source.getSourceIdentifier());
+ private synchronized <T extends SchemaSourceRepresentation> void removeSource(final PotentialSchemaSource<?> source,
+ final SchemaSourceRegistration<?> reg) {
+ final Multimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m =
+ sources.get(source.getSourceIdentifier());
if (m != null) {
m.remove(source.getRepresentation(), reg);
}
@Override
- public <T extends SchemaSourceRepresentation> SchemaSourceRegistration<T> registerSchemaSource(final SchemaSourceProvider<? super T> provider, final PotentialSchemaSource<T> source) {
+ public <T extends SchemaSourceRepresentation> SchemaSourceRegistration<T> registerSchemaSource(
+ final SchemaSourceProvider<? super T> provider, final PotentialSchemaSource<T> source) {
final PotentialSchemaSource<T> src = source.cachedReference();
final AbstractSchemaSourceRegistration<T> ret = new AbstractSchemaSourceRegistration<T>(provider, src) {
synchronized (this) {
final Collection<PotentialSchemaSource<?>> col = new ArrayList<>();
- for (Multimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m : sources.values()) {
+ for (Multimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> m
+ : sources.values()) {
for (AbstractSchemaSourceRegistration<?> r : m.values()) {
col.add(r.getInstance());
}
*
* @param <T> Cached schema source type.
*/
-public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresentation> implements SchemaSourceListener, SchemaSourceProvider<T> {
+public abstract class AbstractSchemaSourceCache<T extends SchemaSourceRepresentation>
+ implements SchemaSourceListener, SchemaSourceProvider<T> {
private final SchemaSourceRegistry consumer;
private final Class<T> representation;
private final Costs cost;
- protected AbstractSchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation, final Costs cost) {
+ protected AbstractSchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation,
+ final Costs cost) {
this.consumer = Preconditions.checkNotNull(consumer);
this.representation = Preconditions.checkNotNull(representation);
this.cost = Preconditions.checkNotNull(cost);
* from the cache.
*/
protected final SchemaSourceRegistration<T> register(final SourceIdentifier sourceIdentifier) {
- final PotentialSchemaSource<T> src = PotentialSchemaSource.create(sourceIdentifier, representation, cost.getValue());
+ final PotentialSchemaSource<T> src = PotentialSchemaSource.create(sourceIdentifier, representation,
+ cost.getValue());
return consumer.registerSchemaSource(this, src);
}
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
-public abstract class AbstractSchemaSourceRegistration<T extends SchemaSourceRepresentation> extends AbstractObjectRegistration<PotentialSchemaSource<T>> implements SchemaSourceRegistration<T> {
+public abstract class AbstractSchemaSourceRegistration<T extends SchemaSourceRepresentation>
+ extends AbstractObjectRegistration<PotentialSchemaSource<T>> implements SchemaSourceRegistration<T> {
private final SchemaSourceProvider<?> provider;
- protected AbstractSchemaSourceRegistration(final SchemaSourceProvider<?> provider, final PotentialSchemaSource<T> source) {
+ protected AbstractSchemaSourceRegistration(final SchemaSourceProvider<?> provider,
+ final PotentialSchemaSource<T> source) {
super(source);
this.provider = Preconditions.checkNotNull(provider);
}
*/
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;
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<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T> {
+public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentation>
+ extends AbstractSchemaSourceCache<T> {
private static final Logger LOG = LoggerFactory.getLogger(FilesystemSchemaSourceCache.class);
// Init storage adapters
- private static final Map<Class<? extends SchemaSourceRepresentation>, StorageAdapter<? extends SchemaSourceRepresentation>> STORAGE_ADAPTERS =
- Collections.singletonMap(
+ private static final Map<Class<? extends SchemaSourceRepresentation>,
+ StorageAdapter<? extends SchemaSourceRepresentation>> STORAGE_ADAPTERS = Collections.singletonMap(
YangTextSchemaSource.class, new YangTextSchemaStorageAdapter());
private static final Pattern CACHED_FILE_PATTERN =
- Pattern.compile(
- "(?<moduleName>[^@]+)" +
- "(@(?<revision>" + SourceIdentifier.REVISION_PATTERN + "))?");
+ Pattern.compile("(?<moduleName>[^@]+)" + "(@(?<revision>" + SourceIdentifier.REVISION_PATTERN + "))?");
private final Class<T> representation;
private final File storageDirectory;
checkSupportedRepresentation(representation);
if (!storageDirectory.exists()) {
- Preconditions.checkArgument(storageDirectory.mkdirs(), "Unable to create cache directory at %s", storageDirectory);
+ Preconditions.checkArgument(storageDirectory.mkdirs(), "Unable to create cache directory at %s",
+ storageDirectory);
}
Preconditions.checkArgument(storageDirectory.exists());
Preconditions.checkArgument(storageDirectory.isDirectory());
}
}
- throw new IllegalArgumentException(String.format(
- "This cache does not support representation: %s, supported representations are: %s", representation, STORAGE_ADAPTERS.keySet()));
+ throw new IllegalArgumentException(String.format(
+ "This cache does not support representation: %s, supported representations are: %s",
+ representation, STORAGE_ADAPTERS.keySet()));
}
/**
- * Restore cache state
+ * Restore cache state.
*/
private void init() {
}
@Override
- public synchronized CheckedFuture<? extends T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
+ public synchronized CheckedFuture<? extends T, SchemaSourceException> 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
private static File findFileWithNewestRev(final SourceIdentifier identifier, final File storageDirectory) {
File[] files = storageDirectory.listFiles(new FilenameFilter() {
- final Pattern p = Pattern.compile(Pattern.quote(identifier.getName()) + "(\\.yang|@\\d\\d\\d\\d-\\d\\d-\\d\\d.yang)");
+ final Pattern pat = Pattern.compile(Pattern.quote(identifier.getName())
+ + "(\\.yang|@\\d\\d\\d\\d-\\d\\d-\\d\\d.yang)");
@Override
public boolean accept(final File dir, final String name) {
- return p.matcher(name).matches();
+ return pat.matcher(name).matches();
}
});
TreeMap<Date, File> 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
*/
DateFormat df = SimpleDateFormatUtil.getRevisionFormat();
try {
- Date d = df.parse(revStr);
- map.put(d, sorted);
+ Date date = df.parse(revStr);
+ map.put(date, sorted);
} catch (final ParseException e) {
LOG.info("Unable to parse date from yang file name {}", fileName);
map.put(new Date(0L), sorted);
STORAGE_ADAPTERS.get(representation).store(file, schemaRepresentation);
}
- private static abstract class StorageAdapter<T extends SchemaSourceRepresentation> {
+ private abstract static class StorageAdapter<T extends SchemaSourceRepresentation> {
private final Class<T> supportedType;
void store(final File file, final SchemaSourceRepresentation schemaSourceRepresentation) {
Preconditions.checkArgument(supportedType.isAssignableFrom(schemaSourceRepresentation.getClass()),
- "Cannot store schema source %s, this adapter only supports %s", schemaSourceRepresentation, supportedType);
+ "Cannot store schema source %s, this adapter only supports %s", schemaSourceRepresentation,
+ supportedType);
storeAsType(file, supportedType.cast(schemaSourceRepresentation));
-
}
protected abstract void storeAsType(final File file, final T cast);
try (final InputStream castStream = cast.openStream()) {
Files.copy(castStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (final IOException e) {
- throw new IllegalStateException("Cannot store schema source " + cast.getIdentifier() + " to " + file, e);
+ throw new IllegalStateException("Cannot store schema source " + cast.getIdentifier() + " to " + file,
+ e);
}
}
return new YangTextSchemaSource(sourceIdentifier) {
@Override
- protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
return toStringHelper;
}
LOG.trace("Restoring cached file {} as {}", file, si.get());
cachedSchemas.add(si.get());
} else {
- LOG.debug("Skipping cached file {}, cannot restore source identifier from filename: {}, does not match {}", file, fileName, CACHED_FILE_PATTERN);
+ LOG.debug("Skipping cached file {}, cannot restore source identifier from filename: {},"
+ + " does not match {}", file, fileName, CACHED_FILE_PATTERN);
}
return fileVisitResult;
}
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
@Beta
-public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T> implements AutoCloseable {
+public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T>
+ implements AutoCloseable {
private final List<FinalizablePhantomReference<T>> regs = Collections.synchronizedList(new ArrayList<>());
private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue();
private final Cache<SourceIdentifier, T> cache;
- protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation, final CacheBuilder<Object, Object> builder) {
+ protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation,
+ final CacheBuilder<Object, Object> builder) {
super(consumer, representation, Costs.IMMEDIATE);
cache = builder.build();
}
- public static <R extends SchemaSourceRepresentation> InMemorySchemaSourceCache<R> createSoftCache(final SchemaSourceRegistry consumer, final Class<R> representation) {
+ public static <R extends SchemaSourceRepresentation> InMemorySchemaSourceCache<R> createSoftCache(
+ final SchemaSourceRegistry consumer, final Class<R> representation) {
return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues());
}
public static <R extends SchemaSourceRepresentation> InMemorySchemaSourceCache<R> createSoftCache(
- final SchemaSourceRegistry consumer, final Class<R> representation, final long lifetime, final TimeUnit units) {
+ final SchemaSourceRegistry consumer, final Class<R> representation, final long lifetime,
+ final TimeUnit units) {
return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues()
.expireAfterAccess(lifetime, units));
}
return Futures.immediateCheckedFuture(present);
}
- return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
+ return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found",
+ sourceIdentifier));
}
@Override
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
-public class SchemaSourceTransformer<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation> implements SchemaSourceListener, SchemaSourceProvider<D> {
- private static final ExceptionMapper<SchemaSourceException> MAPPER = ReflectiveExceptionMapper.create("Source transformation", SchemaSourceException.class);
+public class SchemaSourceTransformer<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation>
+ implements SchemaSourceListener, SchemaSourceProvider<D> {
+ private static final ExceptionMapper<SchemaSourceException> MAPPER = ReflectiveExceptionMapper.create(
+ "Source transformation", SchemaSourceException.class);
@FunctionalInterface
- public interface Transformation<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation> extends AsyncFunction<S, D> {
+ public interface Transformation<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation>
+ extends AsyncFunction<S, D> {
@Override
CheckedFuture<D, SchemaSourceException> apply(@Nonnull final S input) throws Exception;
}
protected static final Supplier<TreeSet<Module>> MODULE_SET_SUPPLIER = () -> new TreeSet<>(REVISION_COMPARATOR);
/**
+ * Returns the ModuleIdentifier-to-YANG source mapping.
+ *
* @return yang sources where key is ModuleIdentifier
*/
protected abstract Map<ModuleIdentifier, String> getIdentifiersToSources();
/**
+ * Returns the namespace-to-module mapping.
+ *
* @return Map of modules where key is namespace
*/
protected abstract SetMultimap<URI, Module> getNamespaceToModules();
/**
+ * Returns the module name-to-module mapping.
+ *
* @return Map of modules where key is name of module
*/
protected abstract SetMultimap<String, Module> getNameToModules();
/**
* Utility class which provides factory methods to construct Constraints.
*
+ * <p>
* Provides static factory methods which constructs instances of
* <ul>
* <li>{@link LengthConstraint} - {@link #newLengthConstraint(Number, Number, Optional, Optional)}
/**
* Creates a {@link LengthConstraint}.
*
+ * <p>
* Creates an instance of Length constraint based on supplied parameters
* with additional behaviour:
- *
* <ul>
* <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
- * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
+ * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds
+ * <<i>min</i>, <i>max</i> ></code>
* </ul>
*
* @see LengthConstraint
* @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<String> description,
- final Optional<String> reference) {
+ public static LengthConstraint newLengthConstraint(final Number min, final Number max,
+ final Optional<String> description, final Optional<String> reference) {
return new LengthConstraintImpl(min, max, description, reference);
}
/**
* Creates a {@link LengthConstraint}.
*
+ * <p>
* Creates an instance of Length constraint based on supplied parameters
* with additional behaviour:
- *
* <ul>
* <li>{@link LengthConstraint#getErrorAppTag()} returns <code>length-out-of-specified-bounds</code>
- * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
+ * <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is out of bounds
+ * <<i>min</i>, <i>max</i> ></code>
* </ul>
*
* @see LengthConstraint
/**
* Creates a {@link RangeConstraint}.
*
+ * <p>
* Creates an instance of Range constraint based on supplied parameters
* with additional behaviour:
- *
* <ul>
* <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
- * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
+ * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
+ * <<i>min</i>, <i>max</i> ></code>
* </ul>
*
- *
* @see RangeConstraint
*
* @param <T> Type of constraint
* @param reference Reference associated with constraint. {@link Optional#absent()} if reference is undefined.
* @return Instance of {@link RangeConstraint}
*/
- public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max, final Optional<String> description,
- final Optional<String> reference) {
+ public static <T extends Number> RangeConstraint newRangeConstraint(final T min, final T max,
+ final Optional<String> description, final Optional<String> reference) {
return new RangeConstraintImpl(min, max, description, reference);
}
/**
* Creates a {@link RangeConstraint}.
*
+ * <p>
* Creates an instance of Range constraint based on supplied parameters
* with additional behaviour:
- *
* <ul>
* <li>{@link RangeConstraint#getErrorAppTag()} returns <code>range-out-of-specified-bounds</code>
- * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds <<i>min</i>, <i>max</i> ></code>
+ * <li>{@link RangeConstraint#getErrorMessage()} returns <code>The argument is out of bounds
+ * <<i>min</i>, <i>max</i> ></code>
* </ul>
*
- *
* @see RangeConstraint
*
* @param <T> Type of constraint
/**
* Creates a {@link PatternConstraint}.
*
+ * <p>
* Creates an instance of Pattern constraint based on supplied parameters
* with additional behaviour:
- *
* <ul>
* <li>{@link PatternConstraint#getErrorAppTag()} returns
* <code>invalid-regular-expression</code>
/**
* Creates a {@link PatternConstraint}.
*
+ * <p>
* Creates an instance of Pattern constraint based on supplied parameters
* with additional behaviour:
- *
* <ul>
* <li>{@link PatternConstraint#getErrorAppTag()} returns
* <code>invalid-regular-expression</code>
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 {
* Returns true if supplied type is representation of built-in YANG type as
* per RFC 6020.
*
+ * <p>
* 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) {
* Returns true if supplied type is representation of built-in YANG type as
* per RFC 6020.
*
+ * <p>
* 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) {
* 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.
- *
+ * <p>
+ * Iterator instance is eagerly created, walking happens on initialization. Iteration is not ordered.
*/
public class DataNodeIterator implements Iterator<DataSchemaNode> {
private final Set<DataSchemaNode> realChildSchemas;
private final Map<QName, DataSchemaNode> mappedChildSchemas;
- public EffectiveAugmentationSchema(final AugmentationSchema augmentSchema, final Set<DataSchemaNode> realChildSchemas) {
+ public EffectiveAugmentationSchema(final AugmentationSchema augmentSchema,
+ final Set<DataSchemaNode> realChildSchemas) {
this.delegate = Preconditions.checkNotNull(augmentSchema);
this.realChildSchemas = ImmutableSet.copyOf(realChildSchemas);
- final Map<QName, DataSchemaNode> m = new HashMap<>(realChildSchemas.size());;
+ final Map<QName, DataSchemaNode> m = new HashMap<>(realChildSchemas.size());
for (DataSchemaNode realChildSchema : realChildSchemas) {
m.put(realChildSchema.getQName(), realChildSchema);
}
private final SetMultimap<String, Module> 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<ModuleId> rootModules, final Set<ModuleId> 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<ModuleId> rootModules,
+ final Set<ModuleId> additionalModuleIds) {
+ Preconditions.checkNotNull(rootModules, "Base modules cannot be null.");
+ Preconditions.checkNotNull(additionalModuleIds, "Additional modules cannot be null.");
final Builder<Module> filteredModulesBuilder = new Builder<>();
-
final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER);
final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER);
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
}
//dealing with imported module other than root and directly importing root
- private static Collection<Module> getImportedModules(final Map<ModuleId, Module> allModules, final Set<Module> baseModules, final TreeMultimap<String, Module> nameToModulesAll) {
+ private static Collection<Module> getImportedModules(final Map<ModuleId, Module> allModules,
+ final Set<Module> baseModules, final TreeMultimap<String, Module> nameToModulesAll) {
List<Module> 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));
}
}
return nameToModules;
}
- private static boolean selectAdditionalModules(final Module module, final Set<ModuleId> additionalModules){
+ private static boolean selectAdditionalModules(final Module module, final Set<ModuleId> additionalModules) {
return additionalModules.contains(new ModuleId(module.getName(), module.getRevision()));
}
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.");
}
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;
}
/**
* {@link Immutable} implementation of {@link LengthConstraint}.
- *
* Length constraint based on supplied parameters with additional behaviour:
*
* <ul>
* <code>length-out-of-specified-bounds</code>
* <li>{@link LengthConstraint#getErrorMessage()} returns <code>The argument is
* out of bounds <<i>min</i>, <i>max</i> ></code>
- * </ul
+ * </ul>
*/
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
+}
@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;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
/**
- * {@link Immutable} implementation of {@link PatternConstraint}
+ * {@link Immutable} implementation of {@link PatternConstraint}.
*
+ * <p>
* Creates an instance of Range constraint based on supplied parameters with
* additional behaviour:
- *
* <ul>
* <li>{@link PatternConstraint#getErrorAppTag()} returns
* <code>invalid-regular-expression</code>
* </ul>
- *
*/
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
+}
/**
* {@link Immutable} implementation of {@link RangeConstraint}.
*
+ * <p>
* Range constraint based on supplied parameters with additional behavior:
- *
* <ul>
* <li>{@link RangeConstraint#getErrorAppTag()} returns
* <code>range-out-of-specified-bounds</code>
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);
}
/**
- * 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
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);
}
return result.toString();
}
-}
\ No newline at end of file
+}
* the end of the SchemaPath. If the DataSchemaNode is not present in the
* Schema Context the method will return <code>null</code>. <br>
* In case that Schema Context or Schema Path are not specified correctly
- * (i.e. contains <code>null</code> values) the method will return
+ * (i.e. contains <code>null</code> values) the method will throw
* IllegalArgumentException.
*
* @param context
* Schema Path to search for
* @return SchemaNode from the end of the Schema Path or <code>null</code>
* 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");
* @return Returns Data Schema Node for specified Schema Context for given
* Non-conditional Revision Aware XPath, or <code>null</code> if the
* DataSchemaNode is not present in Schema Context.
- * @throws IllegalArgumentException
*/
public static SchemaNode findDataSchemaNode(final SchemaContext context, final Module module,
final RevisionAwareXPath nonCondXPath) {
* @return DataSchemaNode if is present in specified Schema Context for
* given relative Revision Aware XPath, otherwise will return
* <code>null</code>.
- *
- * @throws IllegalArgumentException
*/
public static SchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, final Module module,
final SchemaNode actualSchemaNode, final RevisionAwareXPath relativeXPath) {
* Schema Node
* @return Yang Module for specified Schema Context and Schema Node, if Schema Node is NOT present, the method will
* return <code>null</code>
- *
- * @throws IllegalArgumentException
*/
public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) {
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL!");
}
/**
- * 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;
* @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.");
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;
* XPath String
* @return return a list of QName
*
- * @throws IllegalArgumentException
+ * @throws IllegalArgumentException if any arguments are null
+ *
*/
private static List<QName> 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");
* @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!");
* Module Prefix
* @return Module for given prefix in specified Schema Context if is
* present, otherwise returns <code>null</code>
- *
- * @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");
}
/**
+ * Resolve a relative XPath into a set of QNames.
+ *
* @param context
* Schema Context
* @param module
* @param actualSchemaNode
* actual schema node
* @return list of QName
- *
- * @throws IllegalArgumentException
+ * @throws IllegalArgumentException if any arguments are null
*/
private static Iterable<QName> 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");
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.
*
+ * <p>
* 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());
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);
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("\\[[^\\[\\]]*\\]");
/**
* @param pathStatement
* xPath to target node
* @return string representation of xPath without conditions
- *
*/
@VisibleForTesting
static String stripConditionsFromXPathString(final RevisionAwareXPath pathStatement) {
}
/**
- * 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.");
+ }
+ }
}
return MAX;
}
};
+
private static final UnresolvedNumber MIN = new UnresolvedNumber() {
private static final long serialVersionUID = 1L;
}
public abstract Number resolveLength(List<LengthConstraint> constraints);
+
public abstract Number resolveRange(List<RangeConstraint> constraints);
@Override
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<UnknownSchemaNode> unknownSchemNodes) {
+ final String reference, final Status status, final String units,
+ final Collection<UnknownSchemaNode> unknownSchemNodes) {
super(path, unknownSchemNodes);
this.baseType = Preconditions.checkNotNull(baseType);
this.status = Preconditions.checkNotNull(status);
/**
* Return the stored base type. Unlike {@link #getBaseType()}, this method returns the underlying restricted type.
- *
- * @return
*/
final T baseType() {
return baseType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-abstract class AbstractIntegerBaseType extends AbstractRangedBaseType<IntegerTypeDefinition> implements IntegerTypeDefinition {
+abstract class AbstractIntegerBaseType extends AbstractRangedBaseType<IntegerTypeDefinition>
+ implements IntegerTypeDefinition {
AbstractIntegerBaseType(final QName qname, final Number minValue, final Number maxValue) {
super(qname, minValue, maxValue);
}
abstract class AbstractRestrictedType<T extends TypeDefinition<T>> extends AbstractTypeDefinition<T> {
private final T baseType;
- AbstractRestrictedType(final T baseType, final SchemaPath path, final Collection<UnknownSchemaNode> unknownSchemaNodes) {
+ AbstractRestrictedType(final T baseType, final SchemaPath path,
+ final Collection<UnknownSchemaNode> unknownSchemaNodes) {
super(path, unknownSchemaNodes);
this.baseType = Preconditions.checkNotNull(baseType);
}
final class BaseDecimalType extends AbstractRangedBaseType<DecimalTypeDefinition> implements DecimalTypeDefinition {
private static final List<List<RangeConstraint>> IMPLICIT_RANGE_STATEMENTS;
+
static {
final Builder<List<RangeConstraint>> b = ImmutableList.builder();
b.add(createRangeConstraint("-922337203685477580.8", "922337203685477580.7"));
private final Integer fractionDigits;
- BaseDecimalType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Integer fractionDigits,
- final List<RangeConstraint> rangeConstraints) {
+ BaseDecimalType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes,
+ final Integer fractionDigits, final List<RangeConstraint> rangeConstraints) {
super(path, unknownSchemaNodes, rangeConstraints);
this.fractionDigits = fractionDigits;
}
final class BaseEnumerationType extends AbstractBaseType<EnumTypeDefinition> implements EnumTypeDefinition {
private final List<EnumPair> values;
- BaseEnumerationType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Collection<EnumPair> values) {
+ BaseEnumerationType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes,
+ final Collection<EnumPair> values) {
super(path, unknownSchemaNodes);
this.values = ImmutableList.copyOf(values);
}
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-final class BaseIdentityrefType extends AbstractBaseType<IdentityrefTypeDefinition> implements IdentityrefTypeDefinition {
+final class BaseIdentityrefType extends AbstractBaseType<IdentityrefTypeDefinition>
+ implements IdentityrefTypeDefinition {
private final IdentitySchemaNode identity;
private final Set<IdentitySchemaNode> identities;
* 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:
+ * <p>
+ * The following types have their base type fully specified and are exposed as appropriate TypeDefinition
+ * sub-interfaces:
* <ul>
* <li>boolean</li>
* <li>empty</li>
* <li>uint{8,16,32,64}</li>
* </ul>
*
+ * <p>
* The following types require additional specification in the model and are exposed by means of a specialized
* {@link TypeBuilder}s for each type:
* <ul>
final class BaseUnionType extends AbstractBaseType<UnionTypeDefinition> implements UnionTypeDefinition {
private final List<TypeDefinition<?>> types;
- BaseUnionType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes, final Collection<TypeDefinition<?>> types) {
+ BaseUnionType(final SchemaPath path, final List<UnknownSchemaNode> unknownSchemaNodes,
+ final Collection<TypeDefinition<?>> types) {
super(path, unknownSchemaNodes);
this.types = ImmutableList.copyOf(types);
}
for (Bit baseTypeBit : getBaseType().getBits()) {
if (item.getName().equals(baseTypeBit.getName())) {
if (item.getPosition() != baseTypeBit.getPosition()) {
- throw new InvalidBitDefinitionException(item, "Position of bit '%s' must be the same as the " +
- "position of corresponding bit in the base bits type %s.", item.getName(),
+ throw new InvalidBitDefinitionException(item, "Position of bit '%s' must be the same as the "
+ + "position of corresponding bit in the base bits type %s.", item.getName(),
getBaseType().getQName());
}
isASubsetOfBaseBits = true;
* declaration has not restricted the type further -- which is not something available via
* {@link TypeDefinition#getBaseType()}.
*
+ * <p>
* Here are the possible scenarios:
*
* <pre>
* </pre>
* The leaf type's schema path will not match the schema path of the leaf. We do NOT want to strip it.
*
+ * <p>
* 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().
final List<PatternConstraint> patterns = type.getPatternConstraints();
final List<LengthConstraint> 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;
}
}
}
- private static ConcreteTypeBuilder<BinaryTypeDefinition> concreteBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ private static ConcreteTypeBuilder<BinaryTypeDefinition> concreteBinaryBuilder(
+ @Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new ConcreteTypeBuilder<BinaryTypeDefinition>(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<BitsTypeDefinition> concreteBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<BitsTypeDefinition> concreteBitsBuilder(final BitsTypeDefinition baseType,
+ final SchemaPath path) {
return new ConcreteTypeBuilder<BitsTypeDefinition>(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<BooleanTypeDefinition> concreteBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ private static ConcreteTypeBuilder<BooleanTypeDefinition> concreteBooleanBuilder(
+ @Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new ConcreteTypeBuilder<BooleanTypeDefinition>(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<DecimalTypeDefinition> concreteDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<DecimalTypeDefinition> concreteDecimalBuilder(
+ final DecimalTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<DecimalTypeDefinition>(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<EmptyTypeDefinition> concreteEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<EmptyTypeDefinition> concreteEmptyBuilder(final EmptyTypeDefinition baseType,
+ final SchemaPath path) {
return new ConcreteTypeBuilder<EmptyTypeDefinition>(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<EnumTypeDefinition> concreteEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<EnumTypeDefinition> concreteEnumerationBuilder(
+ final EnumTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<EnumTypeDefinition>(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<IdentityrefTypeDefinition> concreteIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<IdentityrefTypeDefinition> concreteIdentityrefBuilder(
+ final IdentityrefTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<IdentityrefTypeDefinition>(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<InstanceIdentifierTypeDefinition> concreteInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<InstanceIdentifierTypeDefinition> concreteInstanceIdentifierBuilder(
+ final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<InstanceIdentifierTypeDefinition>(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<IntegerTypeDefinition> concreteIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<IntegerTypeDefinition> concreteIntegerBuilder(
+ final IntegerTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<IntegerTypeDefinition>(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<LeafrefTypeDefinition> concreteLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<LeafrefTypeDefinition> concreteLeafrefBuilder(
+ final LeafrefTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<LeafrefTypeDefinition>(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<StringTypeDefinition> concreteStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<StringTypeDefinition> concreteStringBuilder(final StringTypeDefinition baseType,
+ final SchemaPath path) {
return new ConcreteTypeBuilder<StringTypeDefinition>(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<UnionTypeDefinition> concreteUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<UnionTypeDefinition> concreteUnionBuilder(final UnionTypeDefinition baseType,
+ final SchemaPath path) {
return new ConcreteTypeBuilder<UnionTypeDefinition>(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<UnsignedIntegerTypeDefinition> concreteUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
+ private static ConcreteTypeBuilder<UnsignedIntegerTypeDefinition> concreteUnsignedBuilder(
+ final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
return new ConcreteTypeBuilder<UnsignedIntegerTypeDefinition>(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());
}
};
}
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-final class DerivedIdentityrefType extends AbstractDerivedType<IdentityrefTypeDefinition> implements IdentityrefTypeDefinition {
+final class DerivedIdentityrefType extends AbstractDerivedType<IdentityrefTypeDefinition>
+ 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<UnknownSchemaNode> unknownSchemaNodes) {
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-final class DerivedInstanceIdentifierType extends AbstractDerivedType<InstanceIdentifierTypeDefinition> implements InstanceIdentifierTypeDefinition {
+final class DerivedInstanceIdentifierType extends AbstractDerivedType<InstanceIdentifierTypeDefinition>
+ 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<UnknownSchemaNode> 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<UnknownSchemaNode> unknownSchemaNodes,
+ final boolean requireInstance) {
super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
this.requireInstance = requireInstance;
}
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
final class DerivedIntegerType extends AbstractDerivedType<IntegerTypeDefinition> 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<UnknownSchemaNode> 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<UnknownSchemaNode> unknownSchemaNodes) {
super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
}
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
final class DerivedStringType extends AbstractDerivedType<StringTypeDefinition> 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<UnknownSchemaNode> 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<UnknownSchemaNode> unknownSchemaNodes) {
super(baseType, path, defaultValue, description, reference, status, units, unknownSchemaNodes);
}
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
* 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.
*
+ * <p>
* 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
return BaseTypes.isUint64(BaseTypes.baseTypeOf(type));
}
- private static DerivedTypeBuilder<BinaryTypeDefinition> derivedBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ private static DerivedTypeBuilder<BinaryTypeDefinition> derivedBinaryBuilder(
+ @Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new DerivedTypeBuilder<BinaryTypeDefinition>(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<BitsTypeDefinition> derivedBitsBuilder(final BitsTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<BitsTypeDefinition> derivedBitsBuilder(final BitsTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<BitsTypeDefinition>(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<BooleanTypeDefinition> derivedBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ private static DerivedTypeBuilder<BooleanTypeDefinition> derivedBooleanBuilder(
+ @Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new DerivedTypeBuilder<BooleanTypeDefinition>(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<DecimalTypeDefinition> derivedDecimalBuilder(final DecimalTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<DecimalTypeDefinition> derivedDecimalBuilder(final DecimalTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<DecimalTypeDefinition>(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<EmptyTypeDefinition> derivedEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<EmptyTypeDefinition> derivedEmptyBuilder(final EmptyTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<EmptyTypeDefinition>(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<EnumTypeDefinition> derivedEnumerationBuilder(final EnumTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<EnumTypeDefinition> derivedEnumerationBuilder(final EnumTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<EnumTypeDefinition>(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<IdentityrefTypeDefinition> derivedIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<IdentityrefTypeDefinition> derivedIdentityrefBuilder(
+ final IdentityrefTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<IdentityrefTypeDefinition>(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<InstanceIdentifierTypeDefinition> derivedInstanceIdentifierBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<InstanceIdentifierTypeDefinition> derivedInstanceIdentifierBuilder(
+ final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<InstanceIdentifierTypeDefinition>(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<IntegerTypeDefinition> derivedIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<IntegerTypeDefinition> derivedIntegerBuilder(final IntegerTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<IntegerTypeDefinition>(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<LeafrefTypeDefinition> derivedLeafrefBuilder(final LeafrefTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<LeafrefTypeDefinition> derivedLeafrefBuilder(final LeafrefTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<LeafrefTypeDefinition>(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<StringTypeDefinition> derivedStringBuilder(final StringTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<StringTypeDefinition> derivedStringBuilder(final StringTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<StringTypeDefinition>(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<UnionTypeDefinition> derivedUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<UnionTypeDefinition> derivedUnionBuilder(final UnionTypeDefinition baseType,
+ final SchemaPath path) {
return new DerivedTypeBuilder<UnionTypeDefinition>(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<UnsignedIntegerTypeDefinition> derivedUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
+ private static DerivedTypeBuilder<UnsignedIntegerTypeDefinition> derivedUnsignedBuilder(
+ final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
return new DerivedTypeBuilder<UnsignedIntegerTypeDefinition>(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());
}
};
}
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;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-public final class InstanceIdentifierTypeBuilder extends RequireInstanceRestrictedTypeBuilder<InstanceIdentifierTypeDefinition> {
+public final class InstanceIdentifierTypeBuilder
+ extends RequireInstanceRestrictedTypeBuilder<InstanceIdentifierTypeDefinition> {
- InstanceIdentifierTypeBuilder(final InstanceIdentifierTypeDefinition baseType, final SchemaPath path) {
+ InstanceIdentifierTypeBuilder(final InstanceIdentifierTypeDefinition baseType,
+ final SchemaPath path) {
super(Preconditions.checkNotNull(baseType), path);
}
return getBaseType();
}
- return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(), getRequireInstance());
+ return new RestrictedInstanceIdentifierType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+ getRequireInstance());
}
}
import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
import org.opendaylight.yangtools.yang.model.util.UnresolvedNumber;
-public abstract class LengthRestrictedTypeBuilder<T extends TypeDefinition<T>> extends AbstractRestrictedTypeBuilder<T> {
+public abstract class LengthRestrictedTypeBuilder<T extends TypeDefinition<T>>
+ extends AbstractRestrictedTypeBuilder<T> {
private List<LengthConstraint> lengthAlternatives;
LengthRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
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()));
return lengths;
}
- private static List<LengthConstraint> typedLengths(final List<LengthConstraint> lengths, final Class<? extends Number> clazz) {
+ private static List<LengthConstraint> typedLengths(final List<LengthConstraint> lengths,
+ final Class<? extends Number> clazz) {
final Function<Number, Number> function = NumberUtil.converterTo(clazz);
Preconditions.checkArgument(function != null, "Unsupported range class %s", clazz);
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());
return false;
}
- abstract T buildType(List<LengthConstraint> lengthConstraints);
- abstract List<LengthConstraint> getLengthConstraints(T type);
- abstract List<LengthConstraint> typeLengthConstraints();
-
- private List<LengthConstraint> findLenghts() {
- List<LengthConstraint> 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<LengthConstraint> baseLengths = findLenghts();
// 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<LengthConstraint> lengthConstraints);
+
+ abstract List<LengthConstraint> getLengthConstraints(T type);
+
+ abstract List<LengthConstraint> typeLengthConstraints();
+
+ private List<LengthConstraint> findLenghts() {
+ List<LengthConstraint> ret = ImmutableList.of();
+ T wlk = getBaseType();
+ while (wlk != null && ret.isEmpty()) {
+ ret = getLengthConstraints(wlk);
+ wlk = wlk.getBaseType();
+ }
+
+ return ret.isEmpty() ? typeLengthConstraints() : ret;
+ }
}
};
private static final Map<Class<? extends Number>, Function<Number, Number>> CONVERTERS;
+
static {
final ImmutableMap.Builder<Class<? extends Number>, Function<Number, Number>> b = ImmutableMap.builder();
b.put(Byte.class, input -> {
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) {
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());
}
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());
}
}
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;
}
}
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()));
return ranges;
}
- private static List<RangeConstraint> typedRanges(final List<RangeConstraint> ranges, final Class<? extends Number> clazz) {
+ private static List<RangeConstraint> typedRanges(final List<RangeConstraint> ranges,
+ final Class<? extends Number> clazz) {
final Function<Number, Number> function = NumberUtil.converterTo(clazz);
Preconditions.checkArgument(function != null, "Unsupported range class %s", clazz);
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());
// 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);
}
}
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-final class RestrictedBinaryType extends AbstractLengthRestrictedType<BinaryTypeDefinition> implements BinaryTypeDefinition {
+final class RestrictedBinaryType extends AbstractLengthRestrictedType<BinaryTypeDefinition>
+ implements BinaryTypeDefinition {
RestrictedBinaryType(final BinaryTypeDefinition baseType, final SchemaPath path,
final Collection<UnknownSchemaNode> unknownSchemaNodes,
final Collection<LengthConstraint> lengthConstraints) {
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
-final class RestrictedBooleanType extends AbstractRestrictedType<BooleanTypeDefinition> implements BooleanTypeDefinition {
+final class RestrictedBooleanType extends AbstractRestrictedType<BooleanTypeDefinition>
+ implements BooleanTypeDefinition {
RestrictedBooleanType(final BooleanTypeDefinition baseType, final SchemaPath path,
final Collection<UnknownSchemaNode> unknownSchemaNodes) {
super(baseType, path, unknownSchemaNodes);
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-final class RestrictedIdentityrefType extends AbstractRestrictedType<IdentityrefTypeDefinition> implements IdentityrefTypeDefinition {
+final class RestrictedIdentityrefType extends AbstractRestrictedType<IdentityrefTypeDefinition>
+ implements IdentityrefTypeDefinition {
RestrictedIdentityrefType(final IdentityrefTypeDefinition baseType, final SchemaPath path,
final Collection<UnknownSchemaNode> unknownSchemaNodes) {
super(baseType, path, unknownSchemaNodes);
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
-final class RestrictedIntegerType extends AbstractRangeRestrictedType<IntegerTypeDefinition> implements IntegerTypeDefinition {
+final class RestrictedIntegerType extends AbstractRangeRestrictedType<IntegerTypeDefinition>
+ implements IntegerTypeDefinition {
RestrictedIntegerType(final IntegerTypeDefinition baseType, final SchemaPath path,
final Collection<UnknownSchemaNode> unknownSchemaNodes, final Collection<RangeConstraint> 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);
}
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-final class RestrictedLeafrefType extends AbstractRestrictedType<LeafrefTypeDefinition> implements LeafrefTypeDefinition {
+final class RestrictedLeafrefType extends AbstractRestrictedType<LeafrefTypeDefinition>
+ implements LeafrefTypeDefinition {
private final boolean requireInstance;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-final class RestrictedStringType extends AbstractLengthRestrictedType<StringTypeDefinition> implements StringTypeDefinition {
+final class RestrictedStringType extends AbstractLengthRestrictedType<StringTypeDefinition>
+ implements StringTypeDefinition {
private final List<PatternConstraint> patternConstraints;
RestrictedStringType(final StringTypeDefinition baseType, final SchemaPath path,
*/
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;
* 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.
*
+ * <p>
* 1) Restrictable
* binary (length)
* int{8,16,32,64} (range)
* decimal64 (range)
* instance-identifier (require-instance)
*
+ * <p>
* 2) Non-restrictable
* boolean
* bits
* leafref
* union
*
+ * <p>
* 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.
*
+ * <p>
* Restricted types inherit the default value, description, reference, status and units from the base type, if that type
* defines them.
*/
throw new UnsupportedOperationException();
}
- public static LengthRestrictedTypeBuilder<BinaryTypeDefinition> newBinaryBuilder(@Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ public static LengthRestrictedTypeBuilder<BinaryTypeDefinition> newBinaryBuilder(
+ @Nonnull final BinaryTypeDefinition baseType, @Nonnull final SchemaPath path) {
return new LengthRestrictedTypeBuilder<BinaryTypeDefinition>(baseType, path) {
@Override
BinaryTypeDefinition buildType(final List<LengthConstraint> lengthConstraints) {
@Override
List<LengthConstraint> 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;
}
return new BitsTypeBuilder(baseType, path);
}
- public static TypeBuilder<BooleanTypeDefinition> newBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType, @Nonnull final SchemaPath path) {
+ public static TypeBuilder<BooleanTypeDefinition> newBooleanBuilder(@Nonnull final BooleanTypeDefinition baseType,
+ @Nonnull final SchemaPath path) {
return new AbstractRestrictedTypeBuilder<BooleanTypeDefinition>(baseType, path) {
@Override
BooleanTypeDefinition buildType() {
};
}
- public static RangeRestrictedTypeBuilder<DecimalTypeDefinition> newDecima64Builder(final DecimalTypeDefinition baseType, final SchemaPath path) {
- return new RangeRestrictedTypeBuilder<DecimalTypeDefinition>(Preconditions.checkNotNull(baseType), path) {
+ public static RangeRestrictedTypeBuilder<DecimalTypeDefinition> newDecima64Builder(
+ final DecimalTypeDefinition baseType, final SchemaPath path) {
+ return new RangeRestrictedTypeBuilder<DecimalTypeDefinition>(checkNotNull(baseType), path) {
@Override
DecimalTypeDefinition buildType() {
return new RestrictedDecimalType(getBaseType(), getPath(), getUnknownSchemaNodes(),
};
}
- public static TypeBuilder<EmptyTypeDefinition> newEmptyBuilder(final EmptyTypeDefinition baseType, final SchemaPath path) {
+ public static TypeBuilder<EmptyTypeDefinition> newEmptyBuilder(final EmptyTypeDefinition baseType,
+ final SchemaPath path) {
return new AbstractRestrictedTypeBuilder<EmptyTypeDefinition>(baseType, path) {
@Override
EmptyTypeDefinition buildType() {
};
}
- 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<IdentityrefTypeDefinition> newIdentityrefBuilder(final IdentityrefTypeDefinition baseType, final SchemaPath path) {
+ public static TypeBuilder<IdentityrefTypeDefinition> newIdentityrefBuilder(final IdentityrefTypeDefinition baseType,
+ final SchemaPath path) {
return new AbstractRestrictedTypeBuilder<IdentityrefTypeDefinition>(baseType, path) {
@Override
IdentityrefTypeDefinition buildType() {
};
}
- 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);
}
if (getRequireInstance() == getBaseType().requireInstance()) {
return getBaseType();
}
- return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes(), getRequireInstance());
+ return new RestrictedLeafrefType(getBaseType(), getPath(), getUnknownSchemaNodes(),
+ getRequireInstance());
}
};
}
- public static RangeRestrictedTypeBuilder<IntegerTypeDefinition> newIntegerBuilder(final IntegerTypeDefinition baseType, final SchemaPath path) {
- return new RangeRestrictedTypeBuilder<IntegerTypeDefinition>(Preconditions.checkNotNull(baseType), path) {
+ public static RangeRestrictedTypeBuilder<IntegerTypeDefinition> newIntegerBuilder(
+ final IntegerTypeDefinition baseType, final SchemaPath path) {
+ return new RangeRestrictedTypeBuilder<IntegerTypeDefinition>(checkNotNull(baseType), path) {
@Override
IntegerTypeDefinition buildType() {
return new RestrictedIntegerType(getBaseType(), getPath(), getUnknownSchemaNodes(),
return new StringTypeBuilder(baseType, path);
}
- public static TypeBuilder<UnionTypeDefinition> newUnionBuilder(final UnionTypeDefinition baseType, final SchemaPath path) {
+ public static TypeBuilder<UnionTypeDefinition> newUnionBuilder(final UnionTypeDefinition baseType,
+ final SchemaPath path) {
return new AbstractRestrictedTypeBuilder<UnionTypeDefinition>(baseType, path) {
@Override
UnionTypeDefinition buildType() {
};
}
- public static RangeRestrictedTypeBuilder<UnsignedIntegerTypeDefinition> newUnsignedBuilder(final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
- return new RangeRestrictedTypeBuilder<UnsignedIntegerTypeDefinition>(Preconditions.checkNotNull(baseType), path) {
+ public static RangeRestrictedTypeBuilder<UnsignedIntegerTypeDefinition> newUnsignedBuilder(
+ final UnsignedIntegerTypeDefinition baseType, final SchemaPath path) {
+ return new RangeRestrictedTypeBuilder<UnsignedIntegerTypeDefinition>(checkNotNull(baseType), path) {
@Override
UnsignedIntegerTypeDefinition buildType() {
return new RestrictedUnsignedType(getBaseType(), getPath(), getUnknownSchemaNodes(),
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) {
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;
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;
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;
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;
&& 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;
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;
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();
}
@RunWith(MockitoJUnitRunner.class)
public class InMemorySchemaSourceCacheTest {
- private static final Class<YangSchemaSourceRepresentation> representation = YangSchemaSourceRepresentation.class;
- private static final long lifetime = 1000l;
- private static final TimeUnit units = TimeUnit.MILLISECONDS;
+ private static final Class<YangSchemaSourceRepresentation> REPRESENTATION = YangSchemaSourceRepresentation.class;
+ private static final long LIFETIME = 1000L;
+ private static final TimeUnit UNITS = TimeUnit.MILLISECONDS;
@Mock
private SchemaSourceRegistry registry;
@Test
public void inMemorySchemaSourceCacheTest1() {
- final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache = InMemorySchemaSourceCache
- .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation);
+ final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache =
+ InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION);
Assert.assertNotNull(inMemorySchemaSourceCache);
inMemorySchemaSourceCache.close();
}
@Test
public void inMemorySchemaSourceCacheTest2() {
- final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache = InMemorySchemaSourceCache
- .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation,
- InMemorySchemaSourceCacheTest.lifetime, InMemorySchemaSourceCacheTest.units);
+ final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache =
+ InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION, LIFETIME, UNITS);
Assert.assertNotNull(inMemorySchemaSourceCache);
inMemorySchemaSourceCache.close();
}
@Test
public void inMemorySchemaSourceCacheOfferAndGetSourcestest() throws Exception {
- final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache = InMemorySchemaSourceCache
- .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation);
+ final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> 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<? extends YangSchemaSourceRepresentation, SchemaSourceException> checkedSource = inMemorySchemaSourceCache
- .getSource(sourceIdentifier);
+ final CheckedFuture<? extends YangSchemaSourceRepresentation, SchemaSourceException> checkedSource =
+ inMemorySchemaSourceCache.getSource(sourceIdentifier);
Assert.assertNotNull(checkedSource);
final YangSchemaSourceRepresentation yangSchemaSourceRepresentation = checkedSource.get();
Assert.assertNotNull(yangSchemaSourceRepresentation);
@Test(expected = ExecutionException.class)
public void inMemorySchemaSourceCacheNullGetSourcestest() throws Exception {
- final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache = InMemorySchemaSourceCache
- .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation);
+ final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache =
+ InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION);
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("test", "2012-12-12");
- final CheckedFuture<? extends YangSchemaSourceRepresentation, SchemaSourceException> checkedSource = inMemorySchemaSourceCache
- .getSource(sourceIdentifier);
+ final CheckedFuture<? extends YangSchemaSourceRepresentation, SchemaSourceException> checkedSource =
+ inMemorySchemaSourceCache.getSource(sourceIdentifier);
Assert.assertNotNull(checkedSource);
checkedSource.get();
inMemorySchemaSourceCache.close();
@Test
public void inMemorySchemaSourceCache3test() throws Exception {
- final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache = InMemorySchemaSourceCache
- .createSoftCache(this.registry, InMemorySchemaSourceCacheTest.representation);
-
- final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache2 = InMemorySchemaSourceCache
- .createSoftCache(this.registry, representation, InMemorySchemaSourceCacheTest.lifetime,
- InMemorySchemaSourceCacheTest.units);
+ final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache =
+ InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION);
+ final InMemorySchemaSourceCache<YangSchemaSourceRepresentation> inMemorySchemaSourceCache2 =
+ InMemorySchemaSourceCache.createSoftCache(this.registry, REPRESENTATION, LIFETIME, UNITS);
final String content = "content";
final YangTextSchemaSource source = new TestingYangSource("test", "2012-12-12", content);
inMemorySchemaSourceCache2.offer(source);
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("test", "2012-12-12");
- final CheckedFuture<? extends YangSchemaSourceRepresentation, SchemaSourceException> checkedSource = inMemorySchemaSourceCache
- .getSource(sourceIdentifier);
- final CheckedFuture<? extends SchemaSourceRepresentation, SchemaSourceException> checkedSource2 = inMemorySchemaSourceCache2
- .getSource(sourceIdentifier);
+ final CheckedFuture<? extends YangSchemaSourceRepresentation, SchemaSourceException> checkedSource =
+ inMemorySchemaSourceCache.getSource(sourceIdentifier);
+ final CheckedFuture<? extends SchemaSourceRepresentation, SchemaSourceException> checkedSource2 =
+ inMemorySchemaSourceCache2.getSource(sourceIdentifier);
Assert.assertNotNull(checkedSource);
Assert.assertNotNull(checkedSource2);
*/
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;
@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,
final PotentialSchemaSource<T> src;
- public Foo(final SourceIdentifier sourceIdentifier, final Class<T> representation, final Costs cost) {
+ Foo(final SourceIdentifier sourceIdentifier, final Class<T> representation, final Costs cost) {
this.src = PotentialSchemaSource.create(sourceIdentifier, representation,
cost.getValue());
}
private class Registrator extends AbstractSchemaSourceCache<YangSchemaSourceRepresentation> {
- protected Registrator(final SchemaSourceRegistry consumer, final Class<YangSchemaSourceRepresentation> srcClass,
+ Registrator(final SchemaSourceRegistry consumer, final Class<YangSchemaSourceRepresentation> srcClass,
final Costs cost) {
super(consumer, srcClass, cost);
}
*/
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<String> desc = Optional.of(description);
- Optional<String> 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<String> desc = Optional.of(description);
+ final Optional<String> 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
+}
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
public class BaseTypesTest {
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;
@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());
assertFalse("binType shouldn't equal to object of other type", binType.equals("str"));
}
-}
\ No newline at end of file
+}
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;
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());
}
-}
\ No newline at end of file
+}
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;
@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());
}
}
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));
}
}
*/
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;
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;
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;
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();
}
final Set<ChoiceCaseNode> cases = Sets.newHashSet(mockedCase1, mockedCase2);
doReturn(cases).when(mockedChoice).getCases();
- final Set<DataSchemaNode> childNodes = Sets.newHashSet(mockedAugmentingContainer, mockedContainer, mockedList, mockedChoice);
+ final Set<DataSchemaNode> childNodes = Sets.newHashSet(mockedAugmentingContainer, mockedContainer, mockedList,
+ mockedChoice);
doReturn(childNodes).when(mockedModule).getChildNodes();
final NotificationDefinition mockedNotification = mock(NotificationDefinition.class);
assertTrue(dataNodeIterator.allLists().contains(mockedListInRpcInputContainer));
assertTrue(dataNodeIterator.allGroupings().contains(mockedGrouping));
}
-}
\ No newline at end of file
+}
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;
assertEquals("UnknownSchemaNodes", Collections.EMPTY_LIST, emptyType.getUnknownSchemaNodes());
assertTrue("toString", emptyType.toString().contains("empty"));
}
-}
\ No newline at end of file
+}
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;
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);
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));
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());
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;
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;
}
- /**
- * <pre>
+ /*
* CFG(R)
* | \
* | \
- * M2 <- M3
- * </pre>
+ * M2 <- M3
*/
@Test
public void testBasic() {
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3);
- FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig);
+ FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null,
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3);
}
- /**
- * <pre>
+ /*
* No root or additional modules
* | \
* | \
- * M2 <- M3
- * </pre>
+ * M2 <- M3
*/
@Test
public void testNull() {
assertProxyContext(filteringSchemaContextProxy, null);
}
- /**
- * <pre>
+ /*
* Config
* | \ (NR)
* | \
- * M2 <- M3
- * </pre>
+ * M2 <- M3
*/
@Test
public void testConfigDifferentRevisions() {
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);
}
- /**
- * <pre>
+ /*
* CFG(R)
* | \
* | \
- * M2<-(NullRev)M3
- * </pre>
+ * 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);
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3);
- FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig);
+ FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null,
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3);
}
- /**
- * <pre>
+ /*
* CFG(R) ROOT(R)
* | \
* | \
* M2 M3
- * </pre>
*/
@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);
}
- /**
- * <pre>
+ /*
* CFG(R)
* |
* |
- * M2 <- M3
- * </pre>
+ * M2 <- M3
*/
@Test
public void testChainNotDepend() {
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3);
- FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig);
+ FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null,
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2);
}
- /**
- * <pre>
+ /*
* CFG(R)
* |
* |
- * M2 -> M3 -> M4 -> M5
- * </pre>
+ * M2 -> M3 -> M4 -> M5
*/
@Test
public void testChainDependMulti() {
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);
}
- /**
- * <pre>
+ /*
* CFG(R)
* |
* |
- * M2 -> M3 <- M4
- * </pre>
+ * M2 -> M3 <- M4
*/
@Test
public void testChainNotDependMulti() {
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4);
- FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig);
+ FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null,
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3);
}
- /**
- * <pre>
+ /*
* CFG(R)
* | \ \ \
* | \ \ \
* M2 M3 M4 M5
- * </pre>
*/
@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);
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);
}
- /**
- * <pre>
+ /*
* CFG(R)
* | \
* | \
- * M2 <- M3 M4=M3(Different revision)
- * </pre>
+ * M2 <- M3 M4=M3(Different revision)
*/
@Test
public void testBasicRevisionChange() throws Exception {
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4);
- FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig);
+ FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null,
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3);
}
- /**
- * <pre>
+ /*
* CFG(R)
* |
- * M2 -(no revision)-> M3(R2) ... M3(R1)
- * </pre>
+ * M2 -(no revision)-> M3(R2) ... M3(R1)
*/
@Test
public void testImportNoRevision() {
SchemaContext schemaContext = mockSchema(moduleConfig, module2, module30, module31);
- FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig);
+ FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null,
+ moduleConfig);
assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module31);
}
- /**
- * <pre>
+ /*
* CFG(R)
* | \
* | \
- * | M2 -> M3
+ * | M2 -> M3
* |
- * M41(S) => M4
- * </pre>
+ * M41(S) => M4
*/
@Test
public void testBasicSubmodule() {
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);
}
- /**
- * <pre>
- *
- * M2 -> M3 -> M4 -> M5
- *
- * </pre>
+ /*
+ * M2 -> M3 -> M4 -> M5
*/
@Test
public void testChainAdditionalModules() {
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);
}
- /**
- * <pre>
+ /*
*
* CFG(R)
* |
* | M5
* M2
*
- * M3 -> M4
- *
- * </pre>
+ * M3 -> M4
*/
@Test
public void testChainAdditionalModulesConfig() {
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);
}
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<DataSchemaNode> childNodes = Sets.newHashSet(mockedContainer);
+ final Set<DataSchemaNode> childNodes = Collections.singleton(mockedContainer);
doReturn(childNodes).when(moduleConfig).getChildNodes();
final Set<DataSchemaNode> dataDefinitions = filteringSchemaContextProxy.getDataDefinitions();
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<NotificationDefinition> notifications = Sets.newHashSet(mockedNotification);
+ final Set<NotificationDefinition> notifications = Collections.singleton(mockedNotification);
doReturn(notifications).when(moduleConfig).getNotifications();
- final Set<NotificationDefinition> schemaContextProxyNotifications = filteringSchemaContextProxy.getNotifications();
+ final Set<NotificationDefinition> schemaContextProxyNotifications =
+ filteringSchemaContextProxy.getNotifications();
assertTrue(schemaContextProxyNotifications.contains(mockedNotification));
}
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<RpcDefinition> rpcs = Sets.newHashSet(mockedRpc);
+ final Set<RpcDefinition> rpcs = Collections.singleton(mockedRpc);
doReturn(rpcs).when(moduleConfig).getRpcs();
final Set<RpcDefinition> operations = filteringSchemaContextProxy.getOperations();
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<ExtensionDefinition> extensions = Lists.newArrayList(mockedExtension);
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<UnknownSchemaNode> unknownSchemaNodes = Lists.newArrayList(mockedUnknownSchemaNode);
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<TypeDefinition<?>> typeDefinitions = Sets.newHashSet(mockedTypeDefinition);
+ final Set<TypeDefinition<?>> typeDefinitions = Collections.singleton(mockedTypeDefinition);
doReturn(typeDefinitions).when(moduleConfig).getTypeDefinitions();
- final Set<TypeDefinition<?>> schemaContextProxyTypeDefinitions = filteringSchemaContextProxy.getTypeDefinitions();
+ final Set<TypeDefinition<?>> schemaContextProxyTypeDefinitions = filteringSchemaContextProxy
+ .getTypeDefinitions();
assertTrue(schemaContextProxyTypeDefinitions.contains(mockedTypeDefinition));
}
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<DataSchemaNode> childNodes = Sets.newHashSet(mockedContainer);
+ final Set<DataSchemaNode> childNodes = Collections.singleton(mockedContainer);
doReturn(childNodes).when(moduleConfig).getChildNodes();
final Set<DataSchemaNode> schemaContextProxyChildNodes = filteringSchemaContextProxy.getChildNodes();
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<GroupingDefinition> groupings = Sets.newHashSet(mockedGrouping);
+ final Set<GroupingDefinition> groupings = Collections.singleton(mockedGrouping);
doReturn(groupings).when(moduleConfig).getGroupings();
final Set<GroupingDefinition> schemaContextProxyGroupings = filteringSchemaContextProxy.getGroupings();
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<Module> modSet = Sets.newHashSet();
-
- if (expected!=null) {
-
- modSet = Sets.newHashSet(expected);
- }
+ private static void assertProxyContext(final FilteringSchemaContextProxy filteringSchemaContextProxy,
+ final Module... expected) {
+ final Set<Module> modSet = expected != null ? ImmutableSet.copyOf(expected) : new HashSet<>();
Set<Module> 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<Module> 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());
}
private static FilteringSchemaContextProxy createProxySchemaCtx(final SchemaContext schemaContext,
final Set<Module> additionalModules, final Module... modules) {
-
Set<Module> 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<ModuleId> createModuleIds(final Set<Module> modules) {
-
- Set<ModuleId> moduleIds = Sets.newHashSet();
-
- if (modules!=null && modules.size()>0) {
-
+ Set<ModuleId> moduleIds = new HashSet<>();
+ if (modules != null) {
for (Module module : modules) {
-
moduleIds.add(new ModuleId(module.getName(), module.getRevision()));
}
}
}
private static void mockSubmodules(final Module mainModule, final Module... submodules) {
-
Set<Module> submodulesSet = new HashSet<>();
submodulesSet.addAll(Arrays.asList(submodules));
}
private static void mockModuleImport(final Module importer, final Module... imports) {
- Set<ModuleImport> mockedImports = Sets.newHashSet();
+ Set<ModuleImport> mockedImports = new HashSet<>();
for (final Module module : imports) {
mockedImports.add(new ModuleImport() {
@Override
@Override
public String toString() {
-
return String.format("Module: %s, revision:%s", module.getName(), module.getRevision());
}
});
}
//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);
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;
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
+}
*/
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 {
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;
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);
// // 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());
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());
}
}
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;
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<BinaryTypeDefinition> lengthRestrictedTypeBuilder = RestrictedTypes
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
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
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),
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);
}
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();
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");
@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());
@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");
@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);
}
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();
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);
}
@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);
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());