Instantly share code, notes, and snippets.

Liviu Tudor liviutudor

View GitHub Profile
View DelegationBean.groovy
package delegation
import groovy.transform.Sortable
class DelegationBean {
@Delegate
BeanOne person
@Delegate
BeanTwo dateOfBirth
View BeanTwo.groovy
package delegation
import groovy.transform.TupleConstructor
@TupleConstructor
class BeanTwo implements Comparable<BeanTwo> {
int yob
public int getAge() {
new Date().year - yob
View BeanOne.groovy
package delegation
import groovy.transform.TupleConstructor
@TupleConstructor
class BeanOne implements Comparable<BeanOne> {
String firstName
String familyName
public String getFullName() {
View DelegationBean.groovy
class DelegationBean {
@Delegate
BeanOne person
@Delegate
BeanTwo dateOfBirth
static void main(String... args) {
DelegationBean one = new DelegationBean(person: new BeanOne("Liviu", "Tudor"), dateOfBirth: new BeanTwo(yob: 1975))
DelegationBean two = new DelegationBean(person: new BeanOne("William", "Shakespeare"), dateOfBirth: new BeanTwo(yob: 1564))
View BeanTwo.groovy
import groovy.transform.Sortable
import groovy.transform.TupleConstructor
@Sortable
@TupleConstructor
class BeanTwo {
int yob
public int getAge() {
new Date().year - yob
View BeanOne.groovy
import groovy.transform.Sortable
import groovy.transform.TupleConstructor
@Sortable
@TupleConstructor
class BeanOne {
String firstName
String familyName
public String getFullName() {
View JacksonBean.java
import java.beans.ConstructorProperties;
public class JacksonBean {
private final int value;
private final String another;
@ConstructorProperties({"value", "another"})
public JacksonBean(int value, String another) {
this.value = value;
this.another = another;
View JacksonBean.java
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class JacksonBean {
private final int value;
private final String another;
@JsonCreator
public JacksonBean(@JsonProperty("value") int value, @JsonProperty("another") String another) {
this.value = value;
View Sample.java
@GET
public Observable<Response> processRequest( @QueryParam("id")String id, @QueryParam("userId")String userId ) {
return Observable.zip(
Observable.fromCallable(() -> database.retrieveRecord(id)),
Observable.fromCallable(() -> userStore.retrieve(userId)),
Observable.fromCallable(() -> logger.writeEntryFor(id, userId)),
this::generateAdResponse
);
}
View Sample.java
@GET
public Response processRequest( @QueryParam("id")String id, @QueryParam("userId")String userId ) {
Record retrieve = database.retrieveRecord(id);
logger.writeEntryFor( id, userId );
UserProfile profile = userStore.retrieve(userId);
generateAdResponse(retrieve, profile);
}