daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Builder
  2. XYZClientWrapper{
  3.     String name;
  4.     String domain;
  5.     XYZClient client;
  6. }
  7.    
  8. @Builder
  9. public class MyClass {
  10.    private String myField;
  11.  
  12.    private final String excludeThisField = "bar";
  13. }
  14.    
  15. package com.something;
  16.  
  17. import lombok.AccessLevel;
  18. import lombok.AllArgsConstructor;
  19. import lombok.Builder;
  20. import lombok.Data;
  21. import lombok.Getter;
  22. import lombok.NoArgsConstructor;
  23. import lombok.Setter;
  24.  
  25. import javax.persistence.AttributeOverride;
  26. import javax.persistence.AttributeOverrides;
  27. import javax.persistence.Column;
  28. import javax.persistence.Embedded;
  29. import javax.persistence.Entity;
  30. import java.time.ZonedDateTime;
  31.  
  32. @Data
  33. @Entity
  34. @Builder
  35. @AllArgsConstructor
  36. @NoArgsConstructor
  37. public class MyClass{
  38.  
  39.     //The builder will generate a method for this property for us.
  40.     private String anotherProperty;
  41.  
  42.     @Embedded
  43.     @AttributeOverrides({
  44.             @AttributeOverride(name = "localDateTime", column = @Column(name = "some_date_local_date_time")),
  45.             @AttributeOverride(name = "zoneId", column = @Column(name = "some__date_zone_id"))
  46.     })
  47.     @Getter(AccessLevel.PRIVATE)
  48.     @Setter(AccessLevel.PRIVATE)
  49.     private ZonedDateTimeEmbeddable someDateInternal;
  50.  
  51.     public ZonedDateTime getSomeDate() {
  52.         return someDateInternal.toZonedDateTime();
  53.     }
  54.  
  55.     public void setSomeDate(ZonedDateTime someDate) {
  56.         someDateInternal = new ZonedDateTimeEmbeddable(someDate);
  57.     }
  58.  
  59.     public static class MyClassBuilder {
  60.         //Prevent direct access to the internal private field by pre-creating builder method with private access.
  61.         private MyClassBuilder shipmentDateInternal(ZonedDateTimeEmbeddable zonedDateTimeEmbeddable) {
  62.             return this;
  63.         }
  64.  
  65.         //Add a builder method because we don't have a field for this Type
  66.         public MyClassBuilder someDate(ZonedDateTime someDate) {
  67.             someDateInternal = new ZonedDateTimeEmbeddable(someDate);
  68.             return this;
  69.         }
  70.     }
  71.  
  72. }
  73.    
  74. @Builder
  75. XYZClientWrapper{
  76.     String name;
  77.     String domain;
  78.     XYZClient client;
  79.  
  80.     public static class XYZClientWrapperBuilder {
  81.         private XYZClientWrapperBuilder client(XYZClient client) { return this; }
  82.     }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top