Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % cat com/facebook/test/Test.java
- package com.facebook.test;
- import org.immutables.value.Value;
- public class Test {
- @Value.Immutable
- public static interface InnerType {
- int value();
- }
- }
- % 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
- % 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
- Loading source file com/facebook/test/ImmutableInnerType.java...
- Loading source file com/facebook/test/Test.java...
- Loading source file gen/com/facebook/test/ImmutableInnerType.java...
- Loading source files for package com.facebook.test...
- javadoc: warning - No source files for package com.facebook.test
- Constructing Javadoc information...
- Standard Doclet version 1.7.0_71
- Building tree for all the packages and classes...
- Generating doc/com/facebook/test/ImmutableInnerType.html...
- com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
- com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
- Generating doc/com/facebook/test/ImmutableInnerType.Builder.html...
- com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
- com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
- com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
- com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
- Generating doc/com/facebook/test/Test.html...
- Generating doc/com/facebook/test/Test.InnerType.html...
- Generating doc/com/facebook/test/package-frame.html...
- Generating doc/com/facebook/test/package-summary.html...
- Generating doc/com/facebook/test/package-tree.html...
- Generating doc/constant-values.html...
- Generating doc/serialized-form.html...
- Building index for all the packages and classes...
- Generating doc/overview-tree.html...
- Generating doc/index-all.html...
- com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
- com/facebook/test/ImmutableInnerType.java:167: warning - Tag @link: reference not found: InnerType
- com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
- com/facebook/test/ImmutableInnerType.java:157: warning - Tag @link: reference not found: InnerType#value() value
- com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
- com/facebook/test/ImmutableInnerType.java:41: warning - Tag @link: reference not found: InnerType#value() value
- Generating doc/deprecated-list.html...
- Building index for all classes...
- Generating doc/allclasses-frame.html...
- Generating doc/allclasses-noframe.html...
- Generating doc/index.html...
- Generating doc/help-doc.html...
- 13 warnings
- % cat gen/com/facebook/test/ImmutableInnerType.java
- package com.facebook.test;
- import com.facebook.test.ImmutableInnerType;
- import com.google.common.base.MoreObjects;
- import com.google.common.base.Preconditions;
- import javax.annotation.Generated;
- import javax.annotation.Nullable;
- import javax.annotation.ParametersAreNonnullByDefault;
- import javax.annotation.concurrent.Immutable;
- import javax.annotation.concurrent.NotThreadSafe;
- /**
- * Immutable implementation of {@link Test.InnerType}.
- * <p>
- * Use builder to create immutable instances:
- * {@code ImmutableInnerType.builder()}.
- */
- @SuppressWarnings("all")
- @ParametersAreNonnullByDefault
- @Generated({"Immutables.generator", "Test.InnerType"})
- @Immutable
- public final class ImmutableInnerType
- implements com.facebook.test.Test.InnerType {
- private final int value;
- private ImmutableInnerType(ImmutableInnerType.Builder builder) {
- this.value = builder.value;
- }
- private ImmutableInnerType(
- ImmutableInnerType original,
- int value) {
- this.value = value;
- }
- /**
- * Copy current immutable object by setting value for {@link InnerType#value() value}.
- * Value equality check is used to prevent copying of the same value by returning {@code this}.
- * @param value new value for value, non-null
- * @return modified copy of the {@code this} object
- */
- public final ImmutableInnerType withValue(int value) {
- if (this.value == value) {
- return this;
- }
- int newValue = value;
- return checkPreconditions(new ImmutableInnerType(
- this,
- newValue));
- }
- /**
- * {@inheritDoc}
- * @return value of {@code value} attribute
- */
- @Override
- public int value() {
- return value;
- }
- /**
- * This instance is equal to instances of {@code ImmutableInnerType} with equal attribute values.
- * @return {@code true} if {@code this} is equal to {@code another} instance
- */
- @Override
- public boolean equals(@Nullable Object another) {
- return this == another
- || (another instanceof ImmutableInnerType && equalTo((ImmutableInnerType) another));
- }
- private boolean equalTo(ImmutableInnerType another) {
- return value == another.value;
- }
- private int computeHashCode() {
- int h = 31;
- h = h * 17 + value;
- return h;
- }
- /**
- * Computes hash code from attributes: {@code value}.
- * @return hashCode value
- */
- @Override
- public int hashCode() {
- return computeHashCode();
- }
- /**
- * Prints immutable value {@code InnerType{...}} with attribute values,
- * excluding any non-generated and auxiliary attributes.
- * @return string representation of value
- */
- @Override
- public String toString() {
- return MoreObjects.toStringHelper("InnerType")
- .omitNullValues()
- .add("value", value)
- .toString();
- }
- private static ImmutableInnerType checkPreconditions(ImmutableInnerType instance) {
- return instance;
- }
- /**
- * Creates immutable copy of {@link Test.InnerType}.
- * Uses accessors to get values to initialize new immutable instance.
- * If instance is already immutable, it returns it unchanged.
- */
- public static ImmutableInnerType copyOf(com.facebook.test.Test.InnerType instance) {
- if (instance instanceof ImmutableInnerType) {
- return (ImmutableInnerType) instance;
- }
- Preconditions.checkNotNull(instance);
- return builder()
- .value(instance.value())
- .build();
- }
- /**
- * @deprecated Already an immutable object, no need to create immutable copy
- */
- @Deprecated
- public static ImmutableInnerType copyOf(ImmutableInnerType instance) {
- return Preconditions.checkNotNull(instance);
- }
- /**
- * Creates builder for {@link ImmutableInnerType}.
- * @return new ImmutableInnerType builder
- */
- public static ImmutableInnerType.Builder builder() {
- return new ImmutableInnerType.Builder();
- }
- /**
- * Builds instances of {@link ImmutableInnerType}.
- * Initialized attributes and then invoke {@link #build()} method to create
- * immutable instance.
- * <p><em>Builder is not thread safe and generally should not be stored in field or collection,
- * but used immediately to create instances.</em>
- */
- @NotThreadSafe
- public static final class Builder {
- private static final long INITIALIZED_BITSET_ALL_ = 0x1;
- private static final long INITIALIZED_BIT_VALUE = 0x1L;
- private long initializedBitset;
- private int value;
- private Builder() {}
- /**
- * Initializes value for {@link InnerType#value() value}.
- * @param value value for value, non-null
- * @return {@code this} builder for chained invocation
- */
- public final Builder value(int value) {
- this.value = value;
- initializedBitset |= INITIALIZED_BIT_VALUE;
- return this;
- }
- /**
- * Builds new {@link InnerType}.
- * @return immutable instance of InnerType
- */
- public ImmutableInnerType build() {
- checkRequiredAttributes();
- return ImmutableInnerType.checkPreconditions(
- new ImmutableInnerType(this));
- }
- private boolean valueIsSet() {
- return (initializedBitset & INITIALIZED_BIT_VALUE) != 0;
- }
- private void checkRequiredAttributes() {
- if (initializedBitset != INITIALIZED_BITSET_ALL_) {
- throw new IllegalStateException(formatRequiredAttributesMessage());
- }
- }
- private String formatRequiredAttributesMessage() {
- return MoreObjects.toStringHelper("Cannot build InnerType, some of required attributes are not set ")
- .omitNullValues()
- .addValue(!valueIsSet() ? "value" : null)
- .toString();
- }
- /**
- * Prints currently set attributes.
- * @return string representation of builder
- */
- @Override
- public String toString() {
- return MoreObjects.toStringHelper("ImmutableInnerType.Builder")
- .omitNullValues()
- .add("value", valueIsSet() ? value : null)
- .toString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment