/** * Copy the current immutable object with elements that replace the content of {@link ListResult#getItems() items}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of items elements to set * @return A modified copy of {@code this} object */ public final ImmutableListResult<T> withItems(Iterable<? extends T> elements) { if (this.items == elements) return this; List<T> newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return validate(new ImmutableListResult<T>(this, this.totalCount, newValue)); }
/** * Construct a new immutable {@code ListResult} instance. * @param totalCount The value for the {@code totalCount} attribute * @param items The value for the {@code items} attribute * @return An immutable ListResult instance */ public static <T> ListResult<T> of(int totalCount, List<T> items) { return of(totalCount, (Iterable<? extends T>) items); }
private ImmutableListResult(int totalCount, Iterable<? extends T> items) { this.totalCount = totalCount; this.items = createUnmodifiableList(false, createSafeList(items, true, false)); }
/** * Copy the current immutable object by setting a value for the {@link ListResult#getTotalCount() totalCount} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for totalCount * @return A modified copy of the {@code this} object */ public final ImmutableListResult<T> withTotalCount(int value) { if (this.totalCount == value) return this; return validate(new ImmutableListResult<T>(this, value, this.items)); }
/** * Builds a new {@link ListResult ListResult}. * @return An immutable instance of ListResult * @throws java.lang.IllegalStateException if any required attributes are missing */ public ListResult<T> build() { return ImmutableListResult.validate(new ImmutableListResult<T>(this)); }
/** * This instance is equal to all instances of {@code ImmutableListResult} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @SuppressWarnings("unchecked") @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableListResult<?> && equalTo((ImmutableListResult<T>) another); }
private ImmutableListResult(ImmutableListResult.Builder<T> builder) { this.totalCount = builder.totalCount; this.items = builder.itemsIsSet() ? createUnmodifiableList(true, builder.items) : createUnmodifiableList(false, createSafeList(ListResult.super.getItems(), true, false)); }
/** * Construct a new immutable {@code ListResult} instance. * @param totalCount The value for the {@code totalCount} attribute * @param items The value for the {@code items} attribute * @return An immutable ListResult instance */ public static <T> ListResult<T> of(int totalCount, Iterable<? extends T> items) { return validate(new ImmutableListResult<T>(totalCount, items)); }
/** * Copy the current immutable object with elements that replace the content of {@link ListResult#getItems() items}. * @param elements The elements to set * @return A modified copy of {@code this} object */ @SafeVarargs public final ImmutableListResult<T> withItems(T... elements) { List<T> newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return validate(new ImmutableListResult<T>(this, this.totalCount, newValue)); }