New test utility AssertDataObjects
[mdsal.git] / binding / mdsal-binding-test-utils / src / main / java / org / opendaylight / mdsal / binding / testutils / XtendBuilderExtensions.java
1 /**
2  * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.testutils;
9
10 import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
11 import org.opendaylight.yangtools.concepts.Builder;
12
13 /**
14  * Xtend extension method for >> operator support for {@link Builder}s.
15  *
16  * <pre>import static extension org.opendaylight.mdsal.binding.testutils
17  * .XtendBuilderExtensions.operator_doubleGreaterThan</pre>
18  *
19  * <p>allows to write (in an *.xtend, not *.java):
20  *
21  * <pre>new InterfaceBuilder &gt;&gt; [
22  *          name = "hello, world"
23  *      ]</pre>
24  *
25  * <p>instead of:
26  *
27  * <pre>(new InterfaceBuilder =&gt; [
28  *          name = "hello, world"
29  *      ]).build</pre>
30  *
31  * <p>See also org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow for background.
32  *
33  * @author Michael Vorburger
34  */
35 public final class XtendBuilderExtensions {
36
37     private XtendBuilderExtensions() { }
38
39     public static <P extends Object, T extends Builder<P>> P operator_doubleGreaterThan(
40             final T object, final Procedure1<? super T> block) {
41
42         block.apply(object);
43         return object.build();
44     }
45
46 }