Skip to content

Instantly share code, notes, and snippets.

Liviu Tudor liviutudor

Block or report user

Report or block liviutudor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@liviutudor
liviutudor / DelegationBean.groovy
Created Oct 31, 2017
after handcrafting the comparison in the beans we are delegating to
View DelegationBean.groovy
package delegation
import groovy.transform.Sortable
class DelegationBean {
@Delegate
BeanOne person
@Delegate
BeanTwo dateOfBirth
@liviutudor
liviutudor / BeanTwo.groovy
Created Oct 31, 2017
Bean two with handcrafted comparison
View BeanTwo.groovy
package delegation
import groovy.transform.TupleConstructor
@TupleConstructor
class BeanTwo implements Comparable<BeanTwo> {
int yob
public int getAge() {
new Date().year - yob
@liviutudor
liviutudor / BeanOne.groovy
Created Oct 31, 2017
Groovy bean one with handcrafted comparison
View BeanOne.groovy
package delegation
import groovy.transform.TupleConstructor
@TupleConstructor
class BeanOne implements Comparable<BeanOne> {
String firstName
String familyName
public String getFullName() {
@liviutudor
liviutudor / DelegationBean.groovy
Last active Sep 22, 2017
Aggregation 2 classes with @DeleGate
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))
@liviutudor
liviutudor / BeanTwo.groovy
Created Sep 21, 2017
Using @DeleGate in groovy, second bean
View BeanTwo.groovy
import groovy.transform.Sortable
import groovy.transform.TupleConstructor
@Sortable
@TupleConstructor
class BeanTwo {
int yob
public int getAge() {
new Date().year - yob
@liviutudor
liviutudor / BeanOne.groovy
Created Sep 21, 2017
Using @DeleGate in groovy, first bean
View BeanOne.groovy
import groovy.transform.Sortable
import groovy.transform.TupleConstructor
@Sortable
@TupleConstructor
class BeanOne {
String firstName
String familyName
public String getFullName() {
@liviutudor
liviutudor / JacksonBean.java
Created Sep 16, 2017
Usage of ConstructorProperties annotation when removing setters and zero-args constructor
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;
@liviutudor
liviutudor / JacksonBean.java
Created Sep 16, 2017
Usage of Jackson annotations when removing setters and zero-args constructor
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;
@liviutudor
liviutudor / Sample.java
Created Jun 28, 2017
Writing the same code using RxJava Observable
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
);
}
@liviutudor
liviutudor / Sample.java
Created Jun 28, 2017
Sample on how to process a http request sequentially in Java
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);
}
You can’t perform that action at this time.