*/
package org.opendaylight.yangtools.objcache.spi;
-import org.opendaylight.yangtools.objcache.ObjectCache;
-
public final class NoopObjectCacheBinder extends AbstractObjectCacheBinder {
public static final NoopObjectCacheBinder INSTANCE = new NoopObjectCacheBinder();
private NoopObjectCacheBinder() {
- super(new IObjectCacheFactory() {
- @Override
- public ObjectCache getObjectCache(final Class<?> objClass) {
- return NoopObjectCache.getInstance();
- }
- });
+ super(objClass -> NoopObjectCache.getInstance());
}
}
*/
package org.opendaylight.yangtools.objcache.impl;
-import org.opendaylight.yangtools.objcache.ObjectCache;
import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder;
-import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
import org.opendaylight.yangtools.objcache.spi.NoopObjectCache;
public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder {
private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder();
private StaticObjectCacheBinder() {
- super(new IObjectCacheFactory() {
- @Override
- public ObjectCache getObjectCache(final Class<?> objClass) {
- return NoopObjectCache.getInstance();
- }
- });
+ super(objClass -> NoopObjectCache.getInstance());
}
public static StaticObjectCacheBinder getInstance() {
@Test
public void testDelegatedMethods() throws InterruptedException {
- Runnable task = new Runnable() {
- @Override
- public void run(){
- }
+ Runnable task = () -> {
};
List<Runnable> taskList = Lists.newArrayList();
CountDownLatch blockingLatch );
}
- public static final Invoker SUBMIT_CALLABLE = new Invoker() {
+ public static final Invoker SUBMIT_CALLABLE = (executor, blockingLatch) -> executor.submit(new Callable<Void>() {
@Override
- public ListenableFuture<?> invokeExecutor( ListeningExecutorService executor,
- final CountDownLatch blockingLatch ) {
- return executor.submit( new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- if (blockingLatch != null ) {
- Uninterruptibles.awaitUninterruptibly( blockingLatch );
- }
- return null;
- }
- } );
+ public Void call() throws Exception {
+ if (blockingLatch != null ) {
+ Uninterruptibles.awaitUninterruptibly( blockingLatch );
+ }
+ return null;
}
- };
+ } );
- public static final Invoker SUBMIT_RUNNABLE = new Invoker() {
- @Override
- public ListenableFuture<?> invokeExecutor( ListeningExecutorService executor,
- final CountDownLatch blockingLatch ) {
- return executor.submit( new Runnable() {
- @Override
- public void run() {
- if (blockingLatch != null ) {
- Uninterruptibles.awaitUninterruptibly( blockingLatch );
- }
- }
- } );
+ public static final Invoker SUBMIT_RUNNABLE = (executor, blockingLatch) -> executor.submit(() -> {
+ if (blockingLatch != null ) {
+ Uninterruptibles.awaitUninterruptibly( blockingLatch );
}
- };
+ });
- public static final Invoker SUBMIT_RUNNABLE_WITH_RESULT = new Invoker() {
- @Override
- public ListenableFuture<?> invokeExecutor( ListeningExecutorService executor,
- final CountDownLatch blockingLatch ) {
- return executor.submit( new Runnable() {
- @Override
- public void run() {
- if (blockingLatch != null ) {
- Uninterruptibles.awaitUninterruptibly( blockingLatch );
- }
- }
- }, "foo" );
+ public static final Invoker SUBMIT_RUNNABLE_WITH_RESULT = (executor, blockingLatch) -> executor.submit(() -> {
+ if (blockingLatch != null ) {
+ Uninterruptibles.awaitUninterruptibly( blockingLatch );
}
- };
+ }, "foo" );
}
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
void invokeExecutor( ListeningExecutorService executor, Runnable task );
}
- static final InitialInvoker SUBMIT = new InitialInvoker() {
- @Override
- public void invokeExecutor( final ListeningExecutorService executor, final Runnable task ) {
- executor.submit( task );
- }
- };
+ static final InitialInvoker SUBMIT = ListeningExecutorService::submit;
- static final InitialInvoker EXECUTE = new InitialInvoker() {
- @Override
- public void invokeExecutor( final ListeningExecutorService executor, final Runnable task ) {
- executor.execute( task );
- }
- };
+ static final InitialInvoker EXECUTE = Executor::execute;
@SuppressWarnings("serial")
public static class TestDeadlockException extends Exception {
}
- private static final Supplier<Exception> DEADLOCK_EXECUTOR_SUPPLIER = new Supplier<Exception>() {
- @Override
- public Exception get() {
- return new TestDeadlockException();
- }
- };
+ private static final Supplier<Exception> DEADLOCK_EXECUTOR_SUPPLIER = TestDeadlockException::new;
DeadlockDetectingListeningExecutorService executor;
// Test submit with Callable.
- ListenableFuture<String> future = executor.submit( new Callable<String>() {
- @Override
- public String call() throws Exception{
- return "foo";
- }
- } );
+ ListenableFuture<String> future = executor.submit(() -> "foo");
assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS ) );
// Test submit with Runnable.
- executor.submit( new Runnable() {
- @Override
- public void run(){
- }
- } ).get();
+ executor.submit(() -> {
+ }).get();
// Test submit with Runnable and value.
- future = executor.submit( new Runnable() {
- @Override
- public void run(){
- }
+ future = executor.submit(() -> {
}, "foo" );
assertEquals( "Future result", "foo", future.get( 5, TimeUnit.SECONDS ) );
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
final CountDownLatch futureCompletedLatch = new CountDownLatch( 1 );
- Runnable task = new Runnable() {
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ Runnable task = () -> Futures.addCallback( invoker.invokeExecutor( executor, null ), new FutureCallback() {
@Override
- public void run() {
-
- Futures.addCallback( invoker.invokeExecutor( executor, null ), new FutureCallback() {
- @Override
- public void onSuccess( final Object result ) {
- futureCompletedLatch.countDown();
- }
-
- @Override
- public void onFailure( final Throwable t ) {
- caughtEx.set( t );
- futureCompletedLatch.countDown();
- }
- } );
+ public void onSuccess( final Object result ) {
+ futureCompletedLatch.countDown();
}
- };
+ @Override
+ public void onFailure( final Throwable t ) {
+ caughtEx.set( t );
+ futureCompletedLatch.countDown();
+ }
+ } );
initialInvoker.invokeExecutor( executor, task );
final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch( 1 );
- Runnable task = new Runnable() {
- @Override
- public void run() {
-
- try {
- invoker.invokeExecutor( executor, null ).get();
- } catch( ExecutionException e ) {
- caughtEx.set( e.getCause() );
- } catch( Throwable e ) {
- caughtEx.set( e );
- } finally {
- latch.countDown();
- }
- }
+ Runnable task = () -> {
+ try {
+ 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 );
final Writer writer = new StringWriter();
final NormalizedNode<?, ?> leafNodeInContainer = TestingNormalizedNodeStructuresCreator.leafNodeInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafNodeInContainer);
- new JsonValidator() {
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
-
- final JsonPrimitive lf11 = childPrimitive(cont1, "complexjson:lf11", "lf11");
- assertNotNull(lf11);
- final int asInt = lf11.getAsInt();
- assertEquals(453, asInt);
- }
- }.validate(jsonOutput);
+ final JsonPrimitive lf11 = childPrimitive(cont1, "complexjson:lf11", "lf11");
+ assertNotNull(lf11);
+ final int asInt = lf11.getAsInt();
+ assertEquals(453, asInt);
+ }).validate(jsonOutput);
}
final NormalizedNode<?, ?> leafListNodeInContainer = TestingNormalizedNodeStructuresCreator
.leafListNodeInContainerMultiline();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
- final JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11");
- assertNotNull(lflst11);
-
- final HashSet<Object> lflst11Values = Sets.newHashSet();
- for (final JsonElement jsonElement : lflst11) {
- assertTrue(jsonElement instanceof JsonPrimitive);
- lflst11Values.add(jsonElement.getAsString());
- }
-
- assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"),
- lflst11Values);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+ final JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11");
+ assertNotNull(lflst11);
+
+ final HashSet<Object> lflst11Values = Sets.newHashSet();
+ for (final JsonElement jsonElement : lflst11) {
+ assertTrue(jsonElement instanceof JsonPrimitive);
+ lflst11Values.add(jsonElement.getAsString());
}
- }.validate(jsonOutput);
+
+ assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"),
+ lflst11Values);
+ }).validate(jsonOutput);
}
final NormalizedNode<?, ?> leafNodeViaAugmentationInContainer = TestingNormalizedNodeStructuresCreator
.leafNodeViaAugmentationInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafNodeViaAugmentationInContainer);
- new JsonValidator() {
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
-
- final JsonPrimitive lf12_1 = childPrimitive(cont1, "complexjson:lf12_1", "lf12_1");
- assertNotNull(lf12_1);
- final String asString = lf12_1.getAsString();
- assertEquals("lf12 value", asString);
- }
- }.validate(jsonOutput);
+ final JsonPrimitive lf12_1 = childPrimitive(cont1, "complexjson:lf12_1", "lf12_1");
+ assertNotNull(lf12_1);
+ final String asString = lf12_1.getAsString();
+ assertEquals("lf12 value", asString);
+ }).validate(jsonOutput);
}
final NormalizedNode<?, ?> leafListNodeInContainer = TestingNormalizedNodeStructuresCreator
.leafListNodeInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
- final JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11");
- assertNotNull(lflst11);
-
- final HashSet<Object> lflst11Values = Sets.newHashSet();
- for (final JsonElement jsonElement : lflst11) {
- assertTrue(jsonElement instanceof JsonPrimitive);
- lflst11Values.add(jsonElement.getAsString());
- }
-
- assertEquals(Sets.newHashSet("lflst11 value2", "lflst11 value1"), lflst11Values);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+ final JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11");
+ assertNotNull(lflst11);
+
+ final HashSet<Object> lflst11Values = Sets.newHashSet();
+ for (final JsonElement jsonElement : lflst11) {
+ assertTrue(jsonElement instanceof JsonPrimitive);
+ lflst11Values.add(jsonElement.getAsString());
}
- }.validate(jsonOutput);
+
+ assertEquals(Sets.newHashSet("lflst11 value2", "lflst11 value1"), lflst11Values);
+ }).validate(jsonOutput);
}
@Test
final NormalizedNode<?, ?> keyedListNodeInContainer = TestingNormalizedNodeStructuresCreator
.keyedListNodeInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, keyedListNodeInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
- final JsonArray lst11 = childArray(cont1, "complexjson:lst11", "lst11");
- assertNotNull(lst11);
-
- final Iterator<JsonElement> iterator = lst11.iterator();
- assertTrue(iterator.hasNext());
- final JsonElement lst11Entry1Raw = iterator.next();
- assertFalse(iterator.hasNext());
- assertTrue(lst11Entry1Raw instanceof JsonObject);
- final JsonObject lst11Entry1 = (JsonObject) lst11Entry1Raw;
-
- final JsonPrimitive key111 = childPrimitive(lst11Entry1, "complexjson:key111", "key111");
- assertNotNull(key111);
- final JsonPrimitive lf112 = childPrimitive(lst11Entry1, "complexjson:lf112", "lf112");
- assertNotNull(lf112);
- final JsonPrimitive lf113 = childPrimitive(lst11Entry1, "complexjson:lf113", "lf113");
- assertNotNull(lf113);
- final JsonPrimitive lf111 = childPrimitive(lst11Entry1, "complexjson:lf111", "lf111");
- assertNotNull(lf111);
-
- assertEquals("key111 value", key111.getAsString());
- assertEquals("/complexjson:cont1/complexjson:lflst11[.='foo']", lf112.getAsString());
- assertEquals("lf113 value", lf113.getAsString());
- assertEquals("lf111 value", lf111.getAsString());
- }
- }.validate(jsonOutput);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+ final JsonArray lst11 = childArray(cont1, "complexjson:lst11", "lst11");
+ assertNotNull(lst11);
+
+ final Iterator<JsonElement> iterator = lst11.iterator();
+ assertTrue(iterator.hasNext());
+ final JsonElement lst11Entry1Raw = iterator.next();
+ assertFalse(iterator.hasNext());
+ assertTrue(lst11Entry1Raw instanceof JsonObject);
+ final JsonObject lst11Entry1 = (JsonObject) lst11Entry1Raw;
+
+ final JsonPrimitive key111 = childPrimitive(lst11Entry1, "complexjson:key111", "key111");
+ assertNotNull(key111);
+ final JsonPrimitive lf112 = childPrimitive(lst11Entry1, "complexjson:lf112", "lf112");
+ assertNotNull(lf112);
+ final JsonPrimitive lf113 = childPrimitive(lst11Entry1, "complexjson:lf113", "lf113");
+ assertNotNull(lf113);
+ final JsonPrimitive lf111 = childPrimitive(lst11Entry1, "complexjson:lf111", "lf111");
+ assertNotNull(lf111);
+
+ assertEquals("key111 value", key111.getAsString());
+ assertEquals("/complexjson:cont1/complexjson:lflst11[.='foo']", lf112.getAsString());
+ assertEquals("lf113 value", lf113.getAsString());
+ assertEquals("lf111 value", lf111.getAsString());
+ }).validate(jsonOutput);
}
@Test
final NormalizedNode<?, ?> choiceNodeInContainer = TestingNormalizedNodeStructuresCreator
.choiceNodeInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, choiceNodeInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
- final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13");
- assertNotNull(lf13);
-
- assertEquals("lf13 value", lf13.getAsString());
- }
- }.validate(jsonOutput);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+ final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13");
+ assertNotNull(lf13);
+
+ assertEquals("lf13 value", lf13.getAsString());
+ }).validate(jsonOutput);
}
/**
.caseNodeAugmentationInChoiceInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer,
caseNodeAugmentationInChoiceInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
-
- final JsonPrimitive lf15_21 = childPrimitive(cont1, "complexjson:lf15_21", "lf15_21");
- assertNotNull(lf15_21);
- final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13");
- assertNotNull(lf13);
- final JsonPrimitive lf15_11 = childPrimitive(cont1, "complexjson:lf15_11", "lf15_11");
- assertNotNull(lf15_11);
- final JsonPrimitive lf15_12 = childPrimitive(cont1, "complexjson:lf15_12", "lf15_12");
- assertNotNull(lf15_12);
-
- assertEquals("lf15_21 value", lf15_21.getAsString());
- assertEquals("lf13 value", lf13.getAsString());
- assertTrue("one two".equals(lf15_11.getAsString()) || "two one".equals(lf15_11.getAsString()));
- assertEquals("complexjson:lf11", lf15_12.getAsString());
-
- }
- }.validate(jsonOutput);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+
+ final JsonPrimitive lf15_21 = childPrimitive(cont1, "complexjson:lf15_21", "lf15_21");
+ assertNotNull(lf15_21);
+ final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13");
+ assertNotNull(lf13);
+ final JsonPrimitive lf15_11 = childPrimitive(cont1, "complexjson:lf15_11", "lf15_11");
+ assertNotNull(lf15_11);
+ final JsonPrimitive lf15_12 = childPrimitive(cont1, "complexjson:lf15_12", "lf15_12");
+ assertNotNull(lf15_12);
+
+ assertEquals("lf15_21 value", lf15_21.getAsString());
+ assertEquals("lf13 value", lf13.getAsString());
+ assertTrue("one two".equals(lf15_11.getAsString()) || "two one".equals(lf15_11.getAsString()));
+ assertEquals("complexjson:lf11", lf15_12.getAsString());
+
+ }).validate(jsonOutput);
}
/**
.caseNodeExternalAugmentationInChoiceInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer,
caseNodeExternalAugmentationInChoiceInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
-
- final JsonPrimitive lf15_11Augment = childPrimitive(cont1, "complexjson-augmentation:lf15_11");
- assertNotNull(lf15_11Augment);
- final JsonPrimitive lf15_12Augment = childPrimitive(cont1, "complexjson-augmentation:lf15_12");
- assertNotNull(lf15_12Augment);
- final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13");
- assertNotNull(lf13);
- final JsonPrimitive lf15_11 = childPrimitive(cont1, "complexjson:lf15_11", "lf15_11");
- assertNotNull(lf15_11);
- final JsonPrimitive lf15_12 = childPrimitive(cont1, "complexjson:lf15_12", "lf15_12");
- assertNotNull(lf15_12);
-
- assertEquals("lf15_11 value from augmentation", lf15_11Augment.getAsString());
- assertEquals("lf15_12 value from augmentation", lf15_12Augment.getAsString());
- assertEquals("lf13 value", lf13.getAsString());
- assertTrue("one two".equals(lf15_11.getAsString()) || "two one".equals(lf15_11.getAsString()));
- assertEquals("complexjson:lf11", lf15_12.getAsString());
-
- }
- }.validate(jsonOutput);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+
+ final JsonPrimitive lf15_11Augment = childPrimitive(cont1, "complexjson-augmentation:lf15_11");
+ assertNotNull(lf15_11Augment);
+ final JsonPrimitive lf15_12Augment = childPrimitive(cont1, "complexjson-augmentation:lf15_12");
+ assertNotNull(lf15_12Augment);
+ final JsonPrimitive lf13 = childPrimitive(cont1, "complexjson:lf13", "lf13");
+ assertNotNull(lf13);
+ final JsonPrimitive lf15_11 = childPrimitive(cont1, "complexjson:lf15_11", "lf15_11");
+ assertNotNull(lf15_11);
+ final JsonPrimitive lf15_12 = childPrimitive(cont1, "complexjson:lf15_12", "lf15_12");
+ assertNotNull(lf15_12);
+
+ assertEquals("lf15_11 value from augmentation", lf15_11Augment.getAsString());
+ assertEquals("lf15_12 value from augmentation", lf15_12Augment.getAsString());
+ assertEquals("lf13 value", lf13.getAsString());
+ assertTrue("one two".equals(lf15_11.getAsString()) || "two one".equals(lf15_11.getAsString()));
+ assertEquals("complexjson:lf11", lf15_12.getAsString());
+
+ }).validate(jsonOutput);
}
/**
final NormalizedNode<?, ?> choiceNodeAugmentationInContainer = TestingNormalizedNodeStructuresCreator
.choiceNodeAugmentationInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, choiceNodeAugmentationInContainer);
- new JsonValidator() {
-
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
-
- final JsonPrimitive lf17 = childPrimitive(cont1, "complexjson:lf17", "lf17");
- assertNotNull(lf17);
- assertEquals("lf17 value", lf17.getAsString());
- }
- }.validate(jsonOutput);
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
+
+ final JsonPrimitive lf17 = childPrimitive(cont1, "complexjson:lf17", "lf17");
+ assertNotNull(lf17);
+ assertEquals("lf17 value", lf17.getAsString());
+ }).validate(jsonOutput);
}
@Test
final NormalizedNode<?, ?> unkeyedNodeInContainer = TestingNormalizedNodeStructuresCreator
.unkeyedNodeInContainer();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, unkeyedNodeInContainer);
- new JsonValidator() {
+ ((JsonValidator) jsonOutput1 -> {
+ final JsonObject cont1 = resolveCont1(jsonOutput1);
+ assertNotNull(cont1);
- @Override
- public void validate(final String jsonOutput) {
- final JsonObject cont1 = resolveCont1(jsonOutput);
- assertNotNull(cont1);
+ final JsonArray lst12 = childArray(cont1, "complexjson:lst12", "lst12");
+ assertNotNull(lst12);
- final JsonArray lst12 = childArray(cont1, "complexjson:lst12", "lst12");
- assertNotNull(lst12);
+ final Iterator<JsonElement> iterator = lst12.iterator();
+ assertTrue(iterator.hasNext());
+ final JsonElement lst12Entry1Raw = iterator.next();
+ assertFalse(iterator.hasNext());
- final Iterator<JsonElement> iterator = lst12.iterator();
- assertTrue(iterator.hasNext());
- final JsonElement lst12Entry1Raw = iterator.next();
- assertFalse(iterator.hasNext());
+ assertTrue(lst12Entry1Raw instanceof JsonObject);
+ final JsonObject lst12Entry1 = (JsonObject) lst12Entry1Raw;
+ final JsonPrimitive lf121 = childPrimitive(lst12Entry1, "complexjson:lf121", "lf121");
+ assertNotNull(lf121);
- assertTrue(lst12Entry1Raw instanceof JsonObject);
- final JsonObject lst12Entry1 = (JsonObject) lst12Entry1Raw;
- final JsonPrimitive lf121 = childPrimitive(lst12Entry1, "complexjson:lf121", "lf121");
- assertNotNull(lf121);
+ assertEquals("lf121 value", lf121.getAsString());
- assertEquals("lf121 value", lf121.getAsString());
-
- }
- }.validate(jsonOutput);
+ }).validate(jsonOutput);
}
* JAXP API.
*/
public final class XmlUtils {
- public static final XmlCodecProvider DEFAULT_XML_CODEC_PROVIDER = new XmlCodecProvider() {
- @Override
- public TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codecFor(final TypeDefinition<?> baseType) {
- return TypeDefinitionAwareCodec.from(baseType);
- }
- };
+ public static final XmlCodecProvider DEFAULT_XML_CODEC_PROVIDER =
+ TypeDefinitionAwareCodec::from;
private XmlUtils() {
throw new UnsupportedOperationException();
-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* the schema node towards the root.
*/
public Iterable<QNameWithPredicate> getPathTowardsRoot() {
- return new Iterable<QNameWithPredicate>() {
+ return () -> new Iterator<QNameWithPredicate>() {
+ private LeafRefPath current = LeafRefPath.this;
+
+ @Override
+ public boolean hasNext() {
+ return current.parent != null;
+ }
+
+ @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");
+ }
+ }
+
@Override
- public Iterator<QNameWithPredicate> iterator() {
- return new Iterator<QNameWithPredicate>() {
- private LeafRefPath current = LeafRefPath.this;
-
- @Override
- public boolean hasNext() {
- return current.parent != null;
- }
-
- @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");
- }
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException(
- "Component removal not supported");
- }
- };
+ public void remove() {
+ throw new UnsupportedOperationException(
+ "Component removal not supported");
}
};
}
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
static final Document DOC = XmlDocumentUtils.getDocument();
static final Element DATA = DOC.createElement("data");
static final NodeSerializerDispatcher MOCK_DISPATCHER = Mockito.mock(NodeSerializerDispatcher.class);
- static final XmlCodecProvider CODEC_PROVIDER = new XmlCodecProvider() {
- @Override
- public TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> codecFor(TypeDefinition<?> baseType) {
- return TypeDefinitionAwareCodec.from(baseType);
- }
- };
+ static final XmlCodecProvider CODEC_PROVIDER = TypeDefinitionAwareCodec::from;
private DomSerializerTestUtils() {
throw new UnsupportedOperationException("Utility class");
import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.choiceBuilder;
import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.containerBuilder;
import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
-import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
List<InputStream> getTestYangs(final String... yangPaths) {
return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths),
- new Function<String, InputStream>() {
- @Override
- public InputStream apply(final String input) {
- final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(input);
- Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
- return resourceAsStream;
- }
+ input -> {
+ final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(input);
+ Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
+ return resourceAsStream;
}));
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import java.util.Collection;
import java.util.List;
import javax.xml.xpath.XPathExpressionException;
import org.jaxen.BaseXPath;
import org.jaxen.expr.Expr;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathBooleanResult;
import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathDocument;
import org.opendaylight.yangtools.yang.data.api.schema.xpath.XPathExpression;
}
if (result instanceof String) {
- return Optional.of(new XPathStringResult() {
- @Override
- public String getValue() {
- return (String)result;
- }
- });
+ return Optional.of((XPathStringResult) () -> (String)result);
} else if (result instanceof Number) {
- return Optional.of(new XPathNumberResult() {
- @Override
- public Number getValue() {
- return (Number) result;
- }
- });
+ return Optional.of((XPathNumberResult) () -> (Number) result);
} else if (result instanceof Boolean) {
- return Optional.of(new XPathBooleanResult() {
- @Override
- public Boolean getValue() {
- return (Boolean) result;
- }
- });
+ return Optional.of((XPathBooleanResult) () -> (Boolean) result);
} else if (result != null){
- return Optional.of(new XPathNodesetResult() {
- @SuppressWarnings("unchecked")
- @Override
- public Collection<NormalizedNode<?, ?>> getValue() {
- // XXX: Will this really work, or do we need to perform deep transformation?
- return Lists.transform((List<NormalizedNodeContext>) result, NormalizedNodeContext::getNode);
- }
+ return Optional.of((XPathNodesetResult) () -> {
+ // XXX: Will this really work, or do we need to perform deep transformation?
+ return Lists.transform((List<NormalizedNodeContext>) result, NormalizedNodeContext::getNode);
});
} else {
return Optional.absent();
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
//FIXME: code duplicate
File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING);
if (yangDir.exists() && yangDir.isDirectory()) {
- File[] yangFiles = yangDir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".yang") && new File(dir, name).isFile();
- }
- });
+ File[] yangFiles = yangDir.listFiles(
+ (dir, name) -> name.endsWith(".yang") && new File(dir, name).isFile());
for (final File yangFile : yangFiles) {
yangsFromDependencies.add(new YangSourceFromFile(yangFile));
}
//FIXME: code duplicate
File yangDir = new File(file, YangToSourcesProcessor.META_INF_YANG_STRING);
if (yangDir.exists() && yangDir.isDirectory()) {
- File[] yangFiles = yangDir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".yang") && new File(dir, name).isFile();
- }
- });
+ File[] yangFiles = yangDir.listFiles(
+ (dir, name) -> name.endsWith(".yang") && new File(dir, name).isFile());
yangsFilesFromDependencies.addAll(Arrays.asList(yangFiles));
}
import com.google.common.collect.UnmodifiableIterator;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
* path from the schema node towards the root.
*/
public Iterable<QName> getPathTowardsRoot() {
- return new Iterable<QName>() {
+ return () -> new UnmodifiableIterator<QName>() {
+ private SchemaPath current = SchemaPath.this;
+
+ @Override
+ public boolean hasNext() {
+ return current.parent != null;
+ }
+
@Override
- public Iterator<QName> iterator() {
- return new UnmodifiableIterator<QName>() {
- private SchemaPath current = SchemaPath.this;
-
- @Override
- public boolean hasNext() {
- return current.parent != null;
- }
-
- @Override
- public QName next() {
- if (current.parent != null) {
- final QName ret = current.qname;
- current = current.parent;
- return ret;
- } else {
- throw new NoSuchElementException("No more elements available");
- }
- }
- };
+ public QName next() {
+ if (current.parent != null) {
+ final QName ret = current.qname;
+ current = current.parent;
+ return ret;
+ } else {
+ throw new NoSuchElementException("No more elements available");
+ }
}
};
}
import com.google.common.collect.Iterables;
import com.google.common.collect.UnmodifiableIterator;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
* path from the schema node towards the root.
*/
public Iterable<QName> getPathTowardsRoot() {
- return new Iterable<QName>() {
+ return () -> new UnmodifiableIterator<QName>() {
+ private SchemaNodeIdentifier current = SchemaNodeIdentifier.this;
+
+ @Override
+ public boolean hasNext() {
+ return current.parent != null;
+ }
+
@Override
- public Iterator<QName> iterator() {
- return new UnmodifiableIterator<QName>() {
- private SchemaNodeIdentifier current = SchemaNodeIdentifier.this;
-
- @Override
- public boolean hasNext() {
- return current.parent != null;
- }
-
- @Override
- public QName next() {
- if (current.parent != null) {
- final QName ret = current.qname;
- current = current.parent;
- return ret;
- } else {
- throw new NoSuchElementException("No more elements available");
- }
- }
- };
+ public QName next() {
+ if (current.parent != null) {
+ final QName ret = current.qname;
+ current = current.parent;
+ return ret;
+ } else {
+ throw new NoSuchElementException("No more elements available");
+ }
}
};
}
final class StmtTestUtils {
- final static FileFilter YANG_FILE_FILTER = new FileFilter() {
- @Override
- public boolean accept(File file) {
- String name = file.getName().toLowerCase();
- return name.endsWith(".yang") && file.isFile();
- }
+ final static FileFilter YANG_FILE_FILTER = file -> {
+ String name = file.getName().toLowerCase();
+ return name.endsWith(".yang") && file.isFile();
};
private StmtTestUtils() {
}
private static TreeMultimap<String, Module> getStringModuleTreeMultimap() {
- return TreeMultimap.create((o1, o2) -> o1.compareTo(o2), REVISION_COMPARATOR);
+ return TreeMultimap.create(String::compareTo, REVISION_COMPARATOR);
}
private static void processForAdditionalModules(final SchemaContext delegate,
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.collect.Collections2;
}
private static Collection<String> filesToFilenamesWithoutRevision(final List<File> storedFiles) {
- return Collections2.transform(storedFiles, new Function<File, String>() {
- @Override
- public String apply(final File input) {
- return Files.getNameWithoutExtension(input.getName());
- }
- });
+ return Collections2.transform(storedFiles, input -> Files.getNameWithoutExtension(input.getName()));
}
@Test
* Comparator based on alphabetical order of local name of SchemaNode's
* qname.
*/
- private static final Comparator<SchemaNode> SCHEMA_NODE_COMP = (o1, o2) -> {
- return o1.getQName().compareTo(o2.getQName());
- };
+ private static final Comparator<SchemaNode> SCHEMA_NODE_COMP = (o1, o2) -> o1.getQName().compareTo(o2.getQName());
private final ChoiceSchemaNode original;
private final String defaultCase;
assertEquals(4, listener.registeredSources.size());
- final Function<PotentialSchemaSource<?>, SourceIdentifier> potSourceToSID = new Function<PotentialSchemaSource<?>, SourceIdentifier>() {
- @Override
- public SourceIdentifier apply(final PotentialSchemaSource<?> input) {
- return input.getSourceIdentifier();
- }
- };
+ final Function<PotentialSchemaSource<?>, SourceIdentifier> potSourceToSID =
+ PotentialSchemaSource::getSourceIdentifier;
assertThat(Collections2.transform(listener.registeredSources, potSourceToSID),
both(hasItem(RevisionSourceIdentifier.create("test", Optional.absent())))
.and(hasItem(RevisionSourceIdentifier.create("test", Optional.of("2012-12-12"))))
public class StmtTestUtils {
- final public static FileFilter YANG_FILE_FILTER = new FileFilter() {
- @Override
- public boolean accept(File file) {
- String name = file.getName().toLowerCase();
- return name.endsWith(".yang") && file.isFile();
- }
+ final public static FileFilter YANG_FILE_FILTER = file -> {
+ String name = file.getName().toLowerCase();
+ return name.endsWith(".yang") && file.isFile();
};
- final public static FileFilter YIN_FILE_FILTER = new FileFilter() {
- @Override
- public boolean accept(File file) {
- String name = file.getName().toLowerCase();
- return name.endsWith(".xml") && file.isFile();
- }
+ final public static FileFilter YIN_FILE_FILTER = file -> {
+ String name = file.getName().toLowerCase();
+ return name.endsWith(".xml") && file.isFile();
};
private static final Logger LOG = LoggerFactory.getLogger(StmtTestUtils.class);