package org.opendaylight.yangtools.util;
import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
final String outerName = Joiner.on(".").join(components.subList(0, length));
final String innerName = outerName + "$" + components.get(length);
return cls.loadClass(innerName);
- } else {
- throw e;
}
+
+ throw e;
}
}
}
private static String formatDuration(final DurationWithTime current) {
- if (current != null) {
- return formatDuration(current.getDuration(), current.getTimeMillis());
- } else {
+ if (current == null) {
return formatDuration(0, null);
}
+ return formatDuration(current.getDuration(), current.getTimeMillis());
}
private static TimeUnit chooseUnit(final long nanos) {
* Input will be thrown away, result will be retained for read-only access or
* {@link #takeSnapshot(Map)} purposes.
*
- * @param input
- * @return
+ * @param input non-optimized (read-write) map
+ * @return optimized read-only map
*/
public <K, V> Map<K, V> optimize(final Map<K, V> input) {
if (input instanceof ReadOnlyTrieMap) {
*/
public static <V> AsyncNotifyingListenableFutureTask<V> create(final Callable<V> callable,
@Nullable final Executor listenerExecutor) {
- if (listenerExecutor != null) {
- return new DelegatingAsyncNotifyingListenableFutureTask<>(callable, listenerExecutor);
- } else {
+ if (listenerExecutor == null) {
return new AsyncNotifyingListenableFutureTask<>(callable);
}
+ return new DelegatingAsyncNotifyingListenableFutureTask<>(callable, listenerExecutor);
}
/**
*/
public static <V> AsyncNotifyingListenableFutureTask<V> create(final Runnable runnable, @Nullable final V result,
@Nullable final Executor listenerExecutor) {
- if (listenerExecutor != null) {
- return new DelegatingAsyncNotifyingListenableFutureTask<>(runnable, result, listenerExecutor);
- } else {
+ if (listenerExecutor == null) {
return new AsyncNotifyingListenableFutureTask<>(runnable, result);
}
+ return new DelegatingAsyncNotifyingListenableFutureTask<>(runnable, result, listenerExecutor);
}
@Override
// If exception is ExecutionException whose cause is of the specified
// type, return the cause.
if (e instanceof ExecutionException && e.getCause() != null) {
- if (exceptionType.isAssignableFrom( e.getCause().getClass())) {
+ if (exceptionType.isAssignableFrom(e.getCause().getClass())) {
return (X) e.getCause();
- } else {
- return newWithCause(opName + " execution failed", e.getCause());
}
+ return newWithCause(opName + " execution failed", e.getCause());
}
// Otherwise return an instance of the specified type with the original
// cause.
if (e instanceof InterruptedException) {
- return newWithCause( opName + " was interupted.", e);
+ return newWithCause(opName + " was interupted.", e);
}
if (e instanceof CancellationException ) {
- return newWithCause( opName + " was cancelled.", e);
+ return newWithCause(opName + " was cancelled.", e);
}
// We really shouldn't get here but need to cover it anyway for completeness.
public class DeadlockDetectingListeningExecutorServiceTest {
interface InitialInvoker {
- void invokeExecutor( ListeningExecutorService executor, Runnable task );
+ void invokeExecutor(ListeningExecutorService executor, Runnable task);
}
static final InitialInvoker SUBMIT = ListeningExecutorService::submit;
static final InitialInvoker EXECUTE = Executor::execute;
- @SuppressWarnings("serial")
public static class TestDeadlockException extends Exception {
+ private static final long serialVersionUID = 1L;
+
}
private static final Supplier<Exception> DEADLOCK_EXECUTOR_SUPPLIER = TestDeadlockException::new;
@After
public void tearDown() {
- if (executor != null ) {
+ if (executor != null) {
executor.shutdownNow();
}
}
DeadlockDetectingListeningExecutorService newExecutor() {
- return new DeadlockDetectingListeningExecutorService( Executors.newSingleThreadExecutor(),
- DEADLOCK_EXECUTOR_SUPPLIER );
+ return new DeadlockDetectingListeningExecutorService(Executors.newSingleThreadExecutor(),
+ DEADLOCK_EXECUTOR_SUPPLIER);
}
@Test
ListenableFuture<String> future = executor.submit(() -> "foo");
- assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS ) );
+ assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS));
// Test submit with Runnable.
// Test submit with Runnable and value.
- future = executor.submit(() -> {
- }, "foo" );
+ future = executor.submit(() -> { }, "foo");
- assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS ) );
+ assertEquals("Future result", "foo", future.get(5, TimeUnit.SECONDS));
}
@Test
executor = newExecutor();
- testNonBlockingSubmitOnExecutorThread( SUBMIT, SUBMIT_CALLABLE );
- testNonBlockingSubmitOnExecutorThread( SUBMIT, SUBMIT_RUNNABLE );
- testNonBlockingSubmitOnExecutorThread( SUBMIT, SUBMIT_RUNNABLE_WITH_RESULT );
+ testNonBlockingSubmitOnExecutorThread(SUBMIT, SUBMIT_CALLABLE);
+ testNonBlockingSubmitOnExecutorThread(SUBMIT, SUBMIT_RUNNABLE);
+ testNonBlockingSubmitOnExecutorThread(SUBMIT, SUBMIT_RUNNABLE_WITH_RESULT);
- testNonBlockingSubmitOnExecutorThread( EXECUTE, SUBMIT_CALLABLE );
+ testNonBlockingSubmitOnExecutorThread(EXECUTE, SUBMIT_CALLABLE);
}
- void testNonBlockingSubmitOnExecutorThread( final InitialInvoker initialInvoker,
- final Invoker invoker ) throws Throwable {
+ void testNonBlockingSubmitOnExecutorThread(final InitialInvoker initialInvoker, final Invoker invoker)
+ throws Throwable {
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
- final CountDownLatch futureCompletedLatch = new CountDownLatch( 1 );
+ final CountDownLatch futureCompletedLatch = new CountDownLatch(1);
- Runnable task = () -> Futures.addCallback( invoker.invokeExecutor( executor, null ), new FutureCallback() {
+ Runnable task = () -> Futures.addCallback(invoker.invokeExecutor(executor, null), new FutureCallback<Object>() {
@Override
- public void onSuccess( final Object result ) {
+ public void onSuccess(final Object result) {
futureCompletedLatch.countDown();
}
@Override
- public void onFailure( final Throwable t ) {
- caughtEx.set( t );
+ public void onFailure(final Throwable t) {
+ caughtEx.set(t);
futureCompletedLatch.countDown();
}
- } );
+ });
- initialInvoker.invokeExecutor( executor, task );
+ initialInvoker.invokeExecutor(executor, task);
- assertTrue( "Task did not complete - executor likely deadlocked",
- futureCompletedLatch.await( 5, TimeUnit.SECONDS ) );
+ assertTrue("Task did not complete - executor likely deadlocked",
+ futureCompletedLatch.await(5, TimeUnit.SECONDS));
- if (caughtEx.get() != null ) {
+ if (caughtEx.get() != null) {
throw caughtEx.get();
}
}
executor = newExecutor();
- testBlockingSubmitOnExecutorThread( SUBMIT, SUBMIT_CALLABLE );
- testBlockingSubmitOnExecutorThread( SUBMIT, SUBMIT_RUNNABLE );
- testBlockingSubmitOnExecutorThread( SUBMIT, SUBMIT_RUNNABLE_WITH_RESULT );
+ testBlockingSubmitOnExecutorThread(SUBMIT, SUBMIT_CALLABLE);
+ testBlockingSubmitOnExecutorThread(SUBMIT, SUBMIT_RUNNABLE);
+ testBlockingSubmitOnExecutorThread(SUBMIT, SUBMIT_RUNNABLE_WITH_RESULT);
- testBlockingSubmitOnExecutorThread( EXECUTE, SUBMIT_CALLABLE );
+ testBlockingSubmitOnExecutorThread(EXECUTE, SUBMIT_CALLABLE);
}
- void testBlockingSubmitOnExecutorThread( final InitialInvoker initialInvoker,
- final Invoker invoker ) throws Exception {
+ void testBlockingSubmitOnExecutorThread(final InitialInvoker initialInvoker, final Invoker invoker)
+ throws Exception {
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
- final CountDownLatch latch = new CountDownLatch( 1 );
+ final CountDownLatch latch = new CountDownLatch(1);
Runnable task = () -> {
try {
- invoker.invokeExecutor( executor, null ).get();
- } catch( ExecutionException e ) {
- caughtEx.set( e.getCause() );
- } catch( Throwable e ) {
- caughtEx.set( e );
+ invoker.invokeExecutor(executor, null).get();
+ } catch(ExecutionException e) {
+ caughtEx.set(e.getCause());
+ } catch(Throwable e) {
+ caughtEx.set(e);
} finally {
latch.countDown();
}
};
- initialInvoker.invokeExecutor( executor, task );
-
- assertTrue( "Task did not complete - executor likely deadlocked",
- latch.await( 5, TimeUnit.SECONDS ) );
+ initialInvoker.invokeExecutor(executor, task);
- assertNotNull( "Expected exception thrown", caughtEx.get() );
- assertEquals( "Caught exception type", TestDeadlockException.class, caughtEx.get().getClass() );
+ assertTrue("Task did not complete - executor likely deadlocked", latch.await( 5, TimeUnit.SECONDS));
+ assertNotNull("Expected exception thrown", caughtEx.get());
+ assertEquals("Caught exception type", TestDeadlockException.class, caughtEx.get().getClass());
}
@Test
public void testListenableFutureCallbackWithExecutor() throws InterruptedException {
String listenerThreadPrefix = "ListenerThread";
- ExecutorService listenerExecutor = Executors.newFixedThreadPool( 1,
- new ThreadFactoryBuilder().setNameFormat( listenerThreadPrefix + "-%d" ).build() );
+ ExecutorService listenerExecutor = Executors.newFixedThreadPool(1,
+ new ThreadFactoryBuilder().setNameFormat(listenerThreadPrefix + "-%d").build());
executor = new DeadlockDetectingListeningExecutorService(
- Executors.newSingleThreadExecutor(
- new ThreadFactoryBuilder().setNameFormat( "SingleThread" ).build() ),
- DEADLOCK_EXECUTOR_SUPPLIER, listenerExecutor );
+ Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("SingleThread").build()),
+ DEADLOCK_EXECUTOR_SUPPLIER, listenerExecutor);
try {
- testListenerCallback( executor, SUBMIT_CALLABLE, listenerThreadPrefix );
- testListenerCallback( executor, SUBMIT_RUNNABLE, listenerThreadPrefix );
- testListenerCallback( executor, SUBMIT_RUNNABLE_WITH_RESULT, listenerThreadPrefix );
+ testListenerCallback(executor, SUBMIT_CALLABLE, listenerThreadPrefix);
+ testListenerCallback(executor, SUBMIT_RUNNABLE, listenerThreadPrefix);
+ testListenerCallback(executor, SUBMIT_RUNNABLE_WITH_RESULT, listenerThreadPrefix);
} finally {
listenerExecutor.shutdownNow();
}
}
/**
- *
* Creates new QName.
*
* @param namespace
* in format <code>YYYY-mm-dd</code>.
* @param localName
* Local name part of QName. MUST NOT BE null.
- * @return
+ * @return A new QName
* @throws NullPointerException
* If any of parameters is null.
* @throws IllegalArgumentException
* Namespace of QName, MUST NOT BE Null.
* @param localName
* Local name part of QName. MUST NOT BE null.
- * @return
+ * @return A new QName
* @throws NullPointerException
* If any of parameters is null.
* @throws IllegalArgumentException
boolean pathArgumentsEqual(final YangInstanceIdentifier other) {
if (other instanceof FixedYangInstanceIdentifier) {
return path.equals(((FixedYangInstanceIdentifier) other).path);
- } else {
- return super.pathArgumentsEqual(other);
}
+ return super.pathArgumentsEqual(other);
}
@Override
public PathArgument get(final int index) {
if (index < base.size()) {
return base.get(index);
- } else {
- return stack.get(index - base.size());
}
+ return stack.get(index - base.size());
}
@Override
if (other instanceof StackedYangInstanceIdentifier) {
final StackedYangInstanceIdentifier stacked = (StackedYangInstanceIdentifier) other;
return pathArgument.equals(stacked.pathArgument) && parent.equals(stacked.parent);
- } else {
- return super.pathArgumentsEqual(other);
}
+ return super.pathArgumentsEqual(other);
}
private void readObject(final ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
package org.opendaylight.yangtools.yang.data.api.schema;
import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
public static Optional<NormalizedNode<?, ?>> findNode(final YangInstanceIdentifier rootPath, final NormalizedNode<?, ?> rootNode, final YangInstanceIdentifier childPath) {
final Optional<YangInstanceIdentifier> relativePath = childPath.relativeTo(rootPath);
- if (relativePath.isPresent()) {
- return findNode(rootNode, relativePath.get());
- } else {
- return Optional.absent();
- }
+ return relativePath.isPresent() ? findNode(rootNode, relativePath.get()) : Optional.absent();
}
public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent, final Iterable<PathArgument> relativePath) {
package org.opendaylight.yangtools.yang.data.api.schema.stream;
import static org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter.UNKNOWN_SIZE;
+
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
* @return A new instance.
*/
public static NormalizedNodeWriter forStreamWriter(final NormalizedNodeStreamWriter writer, final boolean orderKeyLeaves) {
- if (orderKeyLeaves) {
- return new OrderedNormalizedNodeWriter(writer);
- } else {
- return new NormalizedNodeWriter(writer);
- }
+ return orderKeyLeaves ? new OrderedNormalizedNodeWriter(writer) : new NormalizedNodeWriter(writer);
}
/**
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.Collections;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public Collection<DataTreeCandidateNode> getChildNodes() {
if (data instanceof NormalizedNodeContainer) {
return Collections2.transform(((NormalizedNodeContainer<?, ?, ?>) data).getValue(), FACTORY_FUNCTION);
- } else {
- return Collections.emptyList();
}
+ return ImmutableList.of();
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
final Optional<? extends NormalizedNode<?, ?>> child = ((NormalizedNodeContainer)data).getChild(identifier);
return FACTORY_FUNCTION.apply(child.orNull());
- } else {
- return null;
}
+ return null;
}
@Override
@Override
public String deserialize(final String s) {
- if (values != null) {
- // Lookup the serialized string in the values. Returned string is the interned instance, which we want
- // to use as the result.
- final String result = values.get(s);
- Preconditions.checkArgument(result != null, "Invalid value '%s' for enum type. Allowed values are: %s",
- s, values.keySet());
- return result;
- } else {
+ if (values == null) {
return s;
}
+
+ // Lookup the serialized string in the values. Returned string is the interned instance, which we want
+ // to use as the result.
+ final String result = values.get(s);
+ Preconditions.checkArgument(result != null, "Invalid value '%s' for enum type. Allowed values are: %s",
+ s, values.keySet());
+ return result;
}
@Override
final Object parent = getParent();
if (parent instanceof LeafListSchemaNode) {
return (LeafListSchemaNode) parent;
- } else {
- final SchemaNode child = SchemaUtils.findChildSchemaByQName((SchemaNode) parent, qname);
- Preconditions.checkArgument(child instanceof LeafListSchemaNode,
- "Node %s is neither a leaf-list nor currently in a leaf-list", child.getPath());
- return (LeafListSchemaNode) child;
}
+
+ final SchemaNode child = SchemaUtils.findChildSchemaByQName((SchemaNode) parent, qname);
+ Preconditions.checkArgument(child instanceof LeafListSchemaNode,
+ "Node %s is neither a leaf-list nor currently in a leaf-list", child.getPath());
+ return (LeafListSchemaNode) child;
}
public ChoiceSchemaNode startChoiceNode(final NodeIdentifier name) {
public String serialize(final Object data) {
if (data instanceof byte[]) {
return BaseEncoding.base64().encode((byte[]) data);
- } else {
- return Objects.toString(data, "");
}
+ return Objects.toString(data, "");
}
@Override
throw new UnsupportedOperationException();
}
- public static LeafRefContext getLeafRefReferencingContext(final SchemaNode node,
- final LeafRefContext root) {
+ public static LeafRefContext getLeafRefReferencingContext(final SchemaNode node, final LeafRefContext root) {
final SchemaPath schemaPath = node.getPath();
return getLeafRefReferencingContext(schemaPath, root);
}
return getLeafRefReferencingContext(pathFromRoot, root);
}
- public static LeafRefContext getLeafRefReferencingContext(
- final Iterable<QName> pathFromRoot, LeafRefContext root) {
-
+ public static LeafRefContext getLeafRefReferencingContext(final Iterable<QName> pathFromRoot, LeafRefContext root) {
LeafRefContext leafRefCtx = null;
final Iterator<QName> iterator = pathFromRoot.iterator();
while (iterator.hasNext() && root != null) {
return leafRefCtx;
}
- public static LeafRefContext getLeafRefReferencedByContext(final SchemaNode node,
- final LeafRefContext root) {
+ public static LeafRefContext getLeafRefReferencedByContext(final SchemaNode node, final LeafRefContext root) {
final SchemaPath schemaPath = node.getPath();
return getLeafRefReferencedByContext(schemaPath, root);
}
return getLeafRefReferencedByContext(pathFromRoot, root);
}
- public static LeafRefContext getLeafRefReferencedByContext(
- final Iterable<QName> pathFromRoot, LeafRefContext root) {
+ public static LeafRefContext getLeafRefReferencedByContext(final Iterable<QName> pathFromRoot,
+ LeafRefContext root) {
LeafRefContext leafRefCtx = null;
final Iterator<QName> iterator = pathFromRoot.iterator();
}
public static boolean isLeafRef(final SchemaNode node, final LeafRefContext root) {
-
if (node == null || root == null) {
return false;
}
- final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(
- node, root);
+ final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node, root);
if (leafRefReferencingContext == null) {
return false;
}
}
public static boolean hasLeafRefChild(final SchemaNode node, final LeafRefContext root) {
-
if (node == null || root == null) {
return false;
}
- final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(
- node, root);
+ final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(node, root);
if (leafRefReferencingContext == null) {
return false;
}
return leafRefReferencingContext.hasReferencingChild();
}
- public static boolean isReferencedByLeafRef(final SchemaNode node,
- final LeafRefContext root) {
-
+ public static boolean isReferencedByLeafRef(final SchemaNode node, final LeafRefContext root) {
if (node == null || root == null) {
return false;
}
- final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(
- node, root);
+ final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node, root);
if (leafRefReferencedByContext == null) {
return false;
}
return leafRefReferencedByContext.isReferenced();
}
- public static boolean hasChildReferencedByLeafRef(final SchemaNode node,
- final LeafRefContext root) {
-
- if ((node == null) || (root == null)) {
+ public static boolean hasChildReferencedByLeafRef(final SchemaNode node, final LeafRefContext root) {
+ if (node == null || root == null) {
return false;
}
- final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(
- node, root);
+ final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(node, root);
if (leafRefReferencedByContext == null) {
return false;
}
return leafRefReferencedByContext.hasReferencedChild();
}
- public static List<LeafRefContext> findAllLeafRefChilds(final SchemaNode node,
- final LeafRefContext root) {
-
+ public static List<LeafRefContext> findAllLeafRefChilds(final SchemaNode node, final LeafRefContext root) {
return findAllLeafRefChilds(node.getPath(), root);
}
- public static List<LeafRefContext> findAllLeafRefChilds(
- final SchemaPath schemaPath, final LeafRefContext root) {
-
+ public static List<LeafRefContext> findAllLeafRefChilds(final SchemaPath schemaPath, final LeafRefContext root) {
return findAllLeafRefChilds(schemaPath.getPathFromRoot(), root);
}
- public static List<LeafRefContext> findAllLeafRefChilds(
- final Iterable<QName> pathFromRoot, final LeafRefContext root) {
-
- final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(
- pathFromRoot, root);
+ public static List<LeafRefContext> findAllLeafRefChilds(final Iterable<QName> pathFromRoot,
+ final LeafRefContext root) {
+ final LeafRefContext leafRefReferencingContext = getLeafRefReferencingContext(pathFromRoot, root);
final List<LeafRefContext> allLeafRefsChilds = findAllLeafRefChilds(leafRefReferencingContext);
return allLeafRefsChilds;
}
- public static List<LeafRefContext> findAllLeafRefChilds(
- final LeafRefContext parent) {
-
+ public static List<LeafRefContext> findAllLeafRefChilds(final LeafRefContext parent) {
final LinkedList<LeafRefContext> leafRefChilds = new LinkedList<>();
-
if (parent == null) {
return leafRefChilds;
}
if (parent.isReferencing()) {
leafRefChilds.add(parent);
return leafRefChilds;
- } else {
- final Set<Entry<QName, LeafRefContext>> childs = parent
- .getReferencingChilds().entrySet();
- for (final Entry<QName, LeafRefContext> child : childs) {
- leafRefChilds.addAll(findAllLeafRefChilds(child.getValue()));
- }
+ }
+
+ final Set<Entry<QName, LeafRefContext>> childs = parent.getReferencingChilds().entrySet();
+ for (final Entry<QName, LeafRefContext> child : childs) {
+ leafRefChilds.addAll(findAllLeafRefChilds(child.getValue()));
}
return leafRefChilds;
}
- public static List<LeafRefContext> findAllChildsReferencedByLeafRef(
- final SchemaNode node, final LeafRefContext root) {
-
+ public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final SchemaNode node,
+ final LeafRefContext root) {
return findAllChildsReferencedByLeafRef(node.getPath(), root);
}
- public static List<LeafRefContext> findAllChildsReferencedByLeafRef(
- final SchemaPath schemaPath, final LeafRefContext root) {
-
- return findAllChildsReferencedByLeafRef(schemaPath.getPathFromRoot(),
- root);
+ public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final SchemaPath schemaPath,
+ final LeafRefContext root) {
+ return findAllChildsReferencedByLeafRef(schemaPath.getPathFromRoot(), root);
}
- public static List<LeafRefContext> findAllChildsReferencedByLeafRef(
- final Iterable<QName> pathFromRoot, final LeafRefContext root) {
+ public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final Iterable<QName> pathFromRoot,
+ final LeafRefContext root) {
- final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(
- pathFromRoot, root);
- final List<LeafRefContext> allChildsReferencedByLeafRef = findAllChildsReferencedByLeafRef(leafRefReferencedByContext);
+ final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(pathFromRoot, root);
+ final List<LeafRefContext> allChildsReferencedByLeafRef =
+ findAllChildsReferencedByLeafRef(leafRefReferencedByContext);
return allChildsReferencedByLeafRef;
}
- public static List<LeafRefContext> findAllChildsReferencedByLeafRef(
- final LeafRefContext parent) {
-
+ public static List<LeafRefContext> findAllChildsReferencedByLeafRef(final LeafRefContext parent) {
final LinkedList<LeafRefContext> childsReferencedByLeafRef = new LinkedList<>();
-
if (parent == null) {
return childsReferencedByLeafRef;
}
if (parent.isReferenced()) {
childsReferencedByLeafRef.add(parent);
return childsReferencedByLeafRef;
- } else {
- final Set<Entry<QName, LeafRefContext>> childs = parent
- .getReferencedByChilds().entrySet();
- for (final Entry<QName, LeafRefContext> child : childs) {
- childsReferencedByLeafRef
- .addAll(findAllChildsReferencedByLeafRef(child
- .getValue()));
- }
+ }
+
+ final Set<Entry<QName, LeafRefContext>> childs = parent.getReferencedByChilds().entrySet();
+ for (final Entry<QName, LeafRefContext> child : childs) {
+ childsReferencedByLeafRef.addAll(findAllChildsReferencedByLeafRef(child.getValue()));
}
return childsReferencedByLeafRef;
}
return getAllLeafRefsReferencingThisNode(node.getPath(), root);
}
- public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(
- final SchemaPath path, final LeafRefContext root) {
+ public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(final SchemaPath path,
+ final LeafRefContext root) {
return getAllLeafRefsReferencingThisNode(path.getPathFromRoot(), root);
}
- public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(
- final Iterable<QName> pathFromRoot, final LeafRefContext root) {
-
- final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(
- pathFromRoot, root);
+ public static Map<QName, LeafRefContext> getAllLeafRefsReferencingThisNode(final Iterable<QName> pathFromRoot,
+ final LeafRefContext root) {
+ final LeafRefContext leafRefReferencedByContext = getLeafRefReferencedByContext(pathFromRoot, root);
if (leafRefReferencedByContext == null) {
return new HashMap<>();
}
return leafRefReferencedByContext.getAllReferencedByLeafRefCtxs();
}
-
}
* @return A new child path
*/
public LeafRefPath createChild(final LeafRefPath relative) {
- Preconditions.checkArgument(!relative.isAbsolute(),
- "Child creation requires relative path");
+ Preconditions.checkArgument(!relative.isAbsolute(), "Child creation requires relative path");
LeafRefPath parent = this;
for (QNameWithPredicate qname : relative.getPathFromRoot()) {
@Override
public QNameWithPredicate next() {
- if (current.parent != null) {
- final QNameWithPredicate ret = current.qname;
- current = current.parent;
- return ret;
- } else {
- throw new NoSuchElementException(
- "No more elements available");
+ if (current.parent == null) {
+ throw new NoSuchElementException("No more elements available");
}
+
+ final QNameWithPredicate ret = current.qname;
+ current = current.parent;
+ return ret;
}
@Override
public void remove() {
- throw new UnsupportedOperationException(
- "Component removal not supported");
+ throw new UnsupportedOperationException("Component removal not supported");
}
};
}
}
if (augmentation != null) {
return new InstanceIdToCompositeNodes.AugmentationNormalization(augmentation, parent);
- } else {
- return fromDataSchemaNode(child);
}
+ return fromDataSchemaNode(child);
}
static InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
dirty = true;
if (value.isEmpty()) {
return new EmptyImmutableUnkeyedListNode(nodeIdentifier);
- } else {
- return new ImmutableUnkeyedListNode(nodeIdentifier, ImmutableList.copyOf(value));
}
+ return new ImmutableUnkeyedListNode(nodeIdentifier, ImmutableList.copyOf(value));
}
@Override
return withoutChild(key);
}
- protected static final class EmptyImmutableUnkeyedListNode extends AbstractImmutableNormalizedNode<NodeIdentifier, Collection<UnkeyedListEntryNode>> implements Immutable, UnkeyedListNode {
+ protected static final class EmptyImmutableUnkeyedListNode extends
+ AbstractImmutableNormalizedNode<NodeIdentifier, Collection<UnkeyedListEntryNode>> implements Immutable,
+ UnkeyedListNode {
protected EmptyImmutableUnkeyedListNode(final NodeIdentifier nodeIdentifier) {
super(nodeIdentifier);
}
private static Optional<NormalizedNode<?, ?>> getChild(
final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container,
final PathArgument identifier) {
- if (container != null) {
- return container.getChild(identifier);
- } else {
- return Optional.absent();
- }
+ return container == null ? Optional.absent() : container.getChild(identifier);
}
static DataTreeCandidateNode deltaChild(
final NormalizedNode<?, ?> oldChild = maybeOldChild.get();
if (maybeNewChild.isPresent()) {
return AbstractRecursiveCandidateNode.replaceNode(oldChild, maybeNewChild.get());
- } else {
- return AbstractRecursiveCandidateNode.deleteNode(oldChild);
- }
- } else {
- if (maybeNewChild.isPresent()) {
- return AbstractRecursiveCandidateNode.writeNode(maybeNewChild.get());
- } else {
- return null;
}
+ return AbstractRecursiveCandidateNode.deleteNode(oldChild);
}
+
+ return maybeNewChild.isPresent() ? AbstractRecursiveCandidateNode.writeNode(maybeNewChild.get()) : null;
}
- static Collection<DataTreeCandidateNode> deltaChildren(@Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
+ static Collection<DataTreeCandidateNode> deltaChildren(
+ @Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
@Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
Preconditions.checkArgument(newData != null || oldData != null,
"No old or new data, modification type should be NONE and deltaChildren() mustn't be called.");
import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
import java.util.Collection;
-import java.util.Collections;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
}
private static TreeNode childMeta(final TreeNode parent, final PathArgument id) {
- if (parent != null) {
- return parent.getChild(id).orNull();
- } else {
- return null;
- }
+ return parent == null ? null : parent.getChild(id).orNull();
}
private static boolean canHaveChildren(@Nullable final TreeNode oldMeta, @Nullable final TreeNode newMeta) {
case UNMODIFIED:
// Unmodified node, but we still need to resolve potential children. canHaveChildren returns
// false if both arguments are null.
- if (canHaveChildren(oldMeta, newMeta)) {
- return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
- AbstractRecursiveCandidateNode::unmodifiedNode);
- } else {
- return Collections.emptyList();
+ if (!canHaveChildren(oldMeta, newMeta)) {
+ return ImmutableList.of();
}
+
+ return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
+ AbstractRecursiveCandidateNode::unmodifiedNode);
case DELETE:
case WRITE:
// This is unusual, the user is requesting we follow into an otherwise-terminal node.
// We need to fudge things based on before/after data to correctly fake the expectations.
- if (canHaveChildren(oldMeta, newMeta)) {
- return AbstractDataTreeCandidateNode.deltaChildren(getContainer(oldMeta), getContainer(newMeta));
- } else {
- return Collections.emptyList();
+ if (!canHaveChildren(oldMeta, newMeta)) {
+ return ImmutableList.of();
}
+ return AbstractDataTreeCandidateNode.deltaChildren(getContainer(oldMeta), getContainer(newMeta));
default:
throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
}
private static Optional<NormalizedNode<?, ?>> optionalData(final TreeNode meta) {
- if (meta != null) {
- return Optional.of(meta.getData());
- } else {
- return Optional.absent();
- }
+ return meta == null ? Optional.absent() : Optional.of(meta.getData());
}
@Override
}
return null;
case UNMODIFIED:
- if (canHaveChildren(oldMeta, newMeta)) {
- final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta).getChild(identifier);
- if (maybeChild.isPresent()) {
- return AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get());
- } else {
- return null;
- }
- } else {
+ if (!canHaveChildren(oldMeta, newMeta)) {
return null;
}
+ final Optional<NormalizedNode<?, ?>> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta)
+ .getChild(identifier);
+ return maybeChild.isPresent() ? AbstractRecursiveCandidateNode.unmodifiedNode(maybeChild.get()) : null;
case DELETE:
case WRITE:
- if (canHaveChildren(oldMeta, newMeta)) {
- return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta), identifier);
- } else {
+ if (!canHaveChildren(oldMeta, newMeta)) {
return null;
}
+ return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta), identifier);
default:
throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
}
private DataTreeCandidateNode createChild(final NormalizedNode<?, ?> childData) {
if (isContainer(childData)) {
return createContainer((NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) childData);
- } else {
- return createLeaf(childData);
}
+ return createLeaf(childData);
}
protected abstract DataTreeCandidateNode createContainer(NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData);
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import java.io.ByteArrayOutputStream;
final QName moduleQName = QName.create(namespace, revision, "module");
final QNameModule module = QNameModule.create(moduleQName.getNamespace(), moduleQName.getRevision());
return QName.create(module, localName);
- } else {
- return QName.create(namespace, revision, localName);
}
+ return QName.create(namespace, revision, localName);
}
private LeafSchemaNode findSchemaNodeWithLeafrefType(final DataNodeContainer module, final String nodeName) {
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
+
import com.google.common.base.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
*
* </pre>
*
- * @return
+ * @return A test document
*/
public NormalizedNode<?, ?> createDocumentOne() {
return ImmutableContainerNodeBuilder
XMLAssert.assertXMLIdentical(new Diff(EXPECTED_2, stringWriter.toString()), true);
}
- private SchemaContext getSchemaContext(String filePath) throws URISyntaxException, ReactorException, FileNotFoundException {
+ private SchemaContext getSchemaContext(final String filePath) throws URISyntaxException, ReactorException, FileNotFoundException {
final InputStream resourceStream = getClass().getResourceAsStream(filePath);
final YangStatementSourceImpl source = new YangStatementSourceImpl(resourceStream);
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
return reactor.buildEffective();
}
- private YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(String ns, String name) {
+ private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String ns, final String name) {
return YangInstanceIdentifier.NodeIdentifier.create(createQName(ns, name));
}
- private QName createQName(String ns, String name) {
+ private static QName createQName(final String ns, final String name) {
return QName.create(ns, "2016-02-17", name);
}
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
*
* </pre>
*
- * @return
+ * @return a test document
*/
public NormalizedNode<?, ?> createDocumentOne() {
return ImmutableContainerNodeBuilder
public QName getFrom(final NamespaceStorageNode storage, final QName key) {
final NamespaceStorageNode root = getRoot(storage);
final QName stored = root.getFromLocalStorage(QNameCacheNamespace.class, key);
- if (stored == null) {
- root.addToLocalStorage(QNameCacheNamespace.class, key, key);
- return key;
- } else {
+ if (stored != null) {
return stored;
}
+
+ root.addToLocalStorage(QNameCacheNamespace.class, key, key);
+ return key;
}
@Override
*/
if (!Utils.belongsToTheSameModule(targetStmtQName, sourceStmtQName)) {
return true;
- } else {
- /*
- * If target or one of its parent is a presence container from
- * the same module, return false and skip mandatory nodes
- * validation
- */
- if (StmtContextUtils.isPresenceContainer(targetCtx)) {
- return false;
- }
+ }
+
+ /*
+ * If target or one of its parent is a presence container from
+ * the same module, return false and skip mandatory nodes
+ * validation
+ */
+ if (StmtContextUtils.isPresenceContainer(targetCtx)) {
+ return false;
}
} while ((targetCtx = targetCtx.getParentContext()) != root);
QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
- };
+ }
@Override
public void onLinkageDeclared(final Mutable<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> stmt) {
@Override
public DataSchemaNode getDataChildByName(final QName name) {
- if (getQName().equals(name)) {
- return caseShorthandNode;
- } else {
- return null;
- }
+ return getQName().equals(name) ? caseShorthandNode : null;
}
@Override
@Override
public String toString() {
- return CaseShorthandImpl.class.getSimpleName() + "[" +
- "qname=" +
- getQName() +
- "]";
+ return CaseShorthandImpl.class.getSimpleName() + "[" + "qname=" + getQName() + "]";
}
private static ChoiceCaseNode getOriginalIfPresent(final SchemaNode caseShorthandNode) {
public class NamedByteArrayInputStream extends ByteArrayInputStream implements NamedInputStream {
private final String toString;
- public NamedByteArrayInputStream(byte[] buf, String toString) {
+ public NamedByteArrayInputStream(final byte[] buf, final String toString) {
super(buf);
this.toString = toString;
}
- public static ByteArrayInputStream create(InputStream originalIS) throws IOException {
+ public static ByteArrayInputStream create(final InputStream originalIS) throws IOException {
final byte[] data = ByteStreams.toByteArray(originalIS);
if (originalIS instanceof NamedInputStream) {
return new NamedByteArrayInputStream(data, originalIS.toString());
- } else {
- return new ByteArrayInputStream(data);
}
+ return new ByteArrayInputStream(data);
}
@Override