beng

Untitled

Jan 13th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.13 KB | None | 0 0
  1. % cat com/facebook/test/Test.java
  2. package com.facebook.test;
  3.  
  4. import org.immutables.value.Value;
  5.  
  6. public class Test {
  7.   @Value.Immutable
  8.   public static interface InnerType {
  9.     int value();
  10.   }
  11. }
  12.  
  13. % javac -d gen -s gen -cp third-party/guava-18.0.jar:third-party/jsr305.jar:third-party/value-standalone-1.1.jar com/facebook/test/Test.java
  14.  
  15. % javadoc -d doc -classpath third-party/guava-18.0.jar:third-party/jsr305.jar:third-party/value-standalone-1.1.jar com.facebook.test com/facebook/test/*.java gen/com/facebook/test/*.java          
  16. Loading source file com/facebook/test/ImmutableInnerType.java...
  17. Loading source file com/facebook/test/Test.java...
  18. Loading source file gen/com/facebook/test/ImmutableInnerType.java...
  19. Loading source files for package com.facebook.test...
  20. javadoc: warning - No source files for package com.facebook.test
  21. Constructing Javadoc information...
  22. Standard Doclet version 1.7.0_71
  23. Building tree for all the packages and classes...
  24. Generating doc/com/facebook/test/ImmutableInnerType.html...
  25. com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
  26. com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
  27. Generating doc/com/facebook/test/ImmutableInnerType.Builder.html...
  28. com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
  29. com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
  30. com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
  31. com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
  32. Generating doc/com/facebook/test/Test.html...
  33. Generating doc/com/facebook/test/Test.InnerType.html...
  34. Generating doc/com/facebook/test/package-frame.html...
  35. Generating doc/com/facebook/test/package-summary.html...
  36. Generating doc/com/facebook/test/package-tree.html...
  37. Generating doc/constant-values.html...
  38. Generating doc/serialized-form.html...
  39. Building index for all the packages and classes...
  40. Generating doc/overview-tree.html...
  41. Generating doc/index-all.html...
  42. com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
  43. com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
  44. com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
  45. com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
  46. com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
  47. com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
  48. Generating doc/deprecated-list.html...
  49. Building index for all classes...
  50. Generating doc/allclasses-frame.html...
  51. Generating doc/allclasses-noframe.html...
  52. Generating doc/index.html...
  53. Generating doc/help-doc.html...
  54. 13 warnings
  55.  
  56. % cat gen/com/facebook/test/ImmutableInnerType.java
  57. package com.facebook.test;
  58. import com.facebook.test.ImmutableInnerType;
  59. import com.google.common.base.MoreObjects;
  60. import com.google.common.base.Preconditions;
  61. import javax.annotation.Generated;
  62. import javax.annotation.Nullable;
  63. import javax.annotation.ParametersAreNonnullByDefault;
  64. import javax.annotation.concurrent.Immutable;
  65. import javax.annotation.concurrent.NotThreadSafe;
  66.  
  67. /**
  68.  * Immutable implementation of {@link Test.InnerType}.
  69.  * <p>
  70.  * Use builder to create immutable instances:
  71.  * {@code ImmutableInnerType.builder()}.
  72.  */
  73. @SuppressWarnings("all")
  74. @ParametersAreNonnullByDefault
  75. @Generated({"Immutables.generator", "Test.InnerType"})
  76. @Immutable
  77. public final class ImmutableInnerType
  78.     implements com.facebook.test.Test.InnerType {
  79.   private final int value;
  80.  
  81.   private ImmutableInnerType(ImmutableInnerType.Builder builder) {
  82.     this.value = builder.value;
  83.   }
  84.  
  85.   private ImmutableInnerType(
  86.       ImmutableInnerType original,
  87.       int value) {
  88.     this.value = value;
  89.   }
  90.  
  91.   /**
  92.    * Copy current immutable object by setting value for {@link InnerType#value() value}.
  93.    * Value equality check is used to prevent copying of the same value by returning {@code this}.
  94.    * @param value new value for value, non-null
  95.    * @return modified copy of the {@code this} object
  96.    */
  97.   public final ImmutableInnerType withValue(int value) {
  98.     if (this.value == value) {
  99.       return this;
  100.     }
  101.     int newValue = value;
  102.     return checkPreconditions(new ImmutableInnerType(
  103.         this,
  104.         newValue));
  105.   }
  106.  
  107.   /**
  108.    * {@inheritDoc}
  109.    * @return value of {@code value} attribute
  110.    */
  111.   @Override
  112.   public int value() {
  113.     return value;
  114.   }
  115.  
  116.   /**
  117.    * This instance is equal to instances of {@code ImmutableInnerType} with equal attribute values.
  118.    * @return {@code true} if {@code this} is equal to {@code another} instance
  119.    */
  120.   @Override
  121.   public boolean equals(@Nullable Object another) {
  122.     return this == another
  123.         || (another instanceof ImmutableInnerType && equalTo((ImmutableInnerType) another));
  124.   }
  125.  
  126.   private boolean equalTo(ImmutableInnerType another) {
  127.     return value == another.value;
  128.   }
  129.  
  130.   private int computeHashCode() {
  131.     int h = 31;
  132.     h = h * 17 + value;
  133.     return h;
  134.   }
  135.   /**
  136.    * Computes hash code from attributes: {@code value}.
  137.    * @return hashCode value
  138.    */
  139.   @Override
  140.   public int hashCode() {
  141.     return computeHashCode();
  142.   }
  143.  
  144.   /**
  145.    * Prints immutable value {@code InnerType{...}} with attribute values,
  146.    * excluding any non-generated and auxiliary attributes.
  147.    * @return string representation of value
  148.    */
  149.   @Override
  150.   public String toString() {
  151.     return MoreObjects.toStringHelper("InnerType")
  152.         .omitNullValues()
  153.         .add("value", value)
  154.         .toString();
  155.   }
  156.  
  157.   private static ImmutableInnerType checkPreconditions(ImmutableInnerType instance) {
  158.     return instance;
  159.   }
  160.  
  161.   /**
  162.    * Creates immutable copy of {@link Test.InnerType}.
  163.    * Uses accessors to get values to initialize new immutable instance.
  164.    * If instance is already immutable, it returns it unchanged.
  165.    */
  166.   public static ImmutableInnerType copyOf(com.facebook.test.Test.InnerType instance) {
  167.     if (instance instanceof ImmutableInnerType) {
  168.       return (ImmutableInnerType) instance;
  169.     }
  170.     Preconditions.checkNotNull(instance);
  171.     return builder()
  172.         .value(instance.value())
  173.         .build();
  174.   }
  175.  
  176.   /**
  177.    * @deprecated Already an immutable object, no need to create immutable copy
  178.    */
  179.   @Deprecated
  180.   public static ImmutableInnerType copyOf(ImmutableInnerType instance) {
  181.     return Preconditions.checkNotNull(instance);
  182.   }
  183.  
  184.   /**
  185.    * Creates builder for {@link ImmutableInnerType}.
  186.    * @return new ImmutableInnerType builder
  187.    */
  188.   public static ImmutableInnerType.Builder builder() {
  189.     return new ImmutableInnerType.Builder();
  190.   }
  191.  
  192.   /**
  193.    * Builds instances of {@link ImmutableInnerType}.
  194.    * Initialized attributes and then invoke {@link #build()} method to create
  195.    * immutable instance.
  196.    * <p><em>Builder is not thread safe and generally should not be stored in field or collection,
  197.    * but used immediately to create instances.</em>
  198.    */
  199.   @NotThreadSafe
  200.   public static final class Builder  {
  201.     private static final long INITIALIZED_BITSET_ALL_ = 0x1;
  202.     private static final long INITIALIZED_BIT_VALUE = 0x1L;
  203.     private long initializedBitset;
  204.  
  205.     private int value;
  206.     private Builder() {}
  207.  
  208.     /**
  209.      * Initializes value for {@link InnerType#value() value}.
  210.      * @param value value for value, non-null
  211.      * @return {@code this} builder for chained invocation
  212.      */
  213.     public final Builder value(int value) {
  214.       this.value = value;
  215.       initializedBitset |= INITIALIZED_BIT_VALUE;
  216.       return this;
  217.     }
  218.  
  219.     /**
  220.      * Builds new {@link InnerType}.
  221.      * @return immutable instance of InnerType
  222.      */
  223.     public ImmutableInnerType build() {
  224.       checkRequiredAttributes();
  225.       return ImmutableInnerType.checkPreconditions(
  226.           new ImmutableInnerType(this));
  227.     }
  228.  
  229.     private boolean valueIsSet() {
  230.       return (initializedBitset & INITIALIZED_BIT_VALUE) != 0;
  231.     }
  232.  
  233.     private void checkRequiredAttributes() {
  234.       if (initializedBitset != INITIALIZED_BITSET_ALL_) {
  235.         throw new IllegalStateException(formatRequiredAttributesMessage());
  236.       }
  237.     }
  238.  
  239.     private String formatRequiredAttributesMessage() {
  240.       return MoreObjects.toStringHelper("Cannot build InnerType, some of required attributes are not set ")
  241.           .omitNullValues()
  242.           .addValue(!valueIsSet() ? "value" : null)
  243.           .toString();
  244.     }
  245.  
  246.     /**
  247.      * Prints currently set attributes.
  248.      * @return string representation of builder
  249.      */
  250.     @Override
  251.     public String toString() {
  252.       return MoreObjects.toStringHelper("ImmutableInnerType.Builder")
  253.           .omitNullValues()
  254.           .add("value", valueIsSet() ? value : null)
  255.           .toString();
  256.     }
  257.   }
  258. }
Advertisement
Add Comment
Please, Sign In to add comment