Last active
August 29, 2015 14:14
-
-
Save Alotor/c3077f79a9c7c1e2c581 to your computer and use it in GitHub Desktop.
Databinding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test { | |
String a | |
String b | |
String c | |
} | |
class Test2 { | |
String a | |
String b | |
String c | |
String d | |
} | |
def tmp = new Test(a: "asdf", b: "ddd", c: "eeee") | |
def tmp2 = new Test2(tmp.properties - [class: Test]) | |
println tmp2.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.transform.ToString | |
trait Mergeable { | |
def leftShift(Object value) { | |
println "$this << $value" | |
this.properties.each { | |
if (value.properties.containsKey(it.key) && it.key != "class") { | |
this."${it.key}" = value."${it.key}" | |
} | |
} | |
return this | |
} | |
} | |
@ToString | |
class Test { | |
String a | |
String b | |
String c | |
} | |
@ToString | |
class Test2 implements Mergeable { | |
String b | |
String c | |
String d | |
} | |
def tmp = new Test(a: "asdf", b: "ddd", c: "eeee") | |
def tmp2 = new Test2() << tmp | |
println tmp2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment