All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.immutables.fixture.deep.ImmutableLine Maven / Gradle / Ivy

package org.immutables.fixture.deep;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.List;
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 Canvas.Line}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableLine.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Canvas.Line"}) @Immutable public final class ImmutableLine implements Canvas.Line { private final ImmutableList points; private final ImmutableColor color; private ImmutableLine( ImmutableList points, ImmutableColor color) { this.points = points; this.color = color; } /** * @return The value of the {@code points} attribute */ @Override public ImmutableList points() { return points; } /** * @return The value of the {@code color} attribute */ @Override public ImmutableColor color() { return color; } /** * Copy the current immutable object with elements that replace the content of {@link Canvas.Line#points() points}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableLine withPoints(Canvas.Point... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableLine(newValue, this.color); } /** * Copy the current immutable object with elements that replace the content of {@link Canvas.Line#points() points}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of points elements to set * @return A modified copy of {@code this} object */ public final ImmutableLine withPoints(Iterable elements) { if (this.points == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableLine(newValue, this.color); } /** * Copy the current immutable object by setting a value for the {@link Canvas.Line#color() color} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param color A new value for color * @return A modified copy of the {@code this} object */ public final ImmutableLine withColor(Canvas.Color color) { if (this.color == color) return this; ImmutableColor newValue = ImmutableColor.copyOf(color); return new ImmutableLine(this.points, newValue); } /** * This instance is equal to all instances of {@code ImmutableLine} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableLine && equalTo((ImmutableLine) another); } private boolean equalTo(ImmutableLine another) { return points.equals(another.points) && color.equals(another.color); } /** * Computes a hash code from attributes: {@code points}, {@code color}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + points.hashCode(); h = h * 17 + color.hashCode(); return h; } /** * Prints the immutable value {@code Line} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Line") .omitNullValues() .add("points", points) .add("color", color) .toString(); } /** * Creates an immutable copy of a {@link Canvas.Line} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Line instance */ public static ImmutableLine copyOf(Canvas.Line instance) { if (instance instanceof ImmutableLine) { return (ImmutableLine) instance; } return ImmutableLine.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableLine ImmutableLine}. * @return A new ImmutableLine builder */ public static ImmutableLine.Builder builder() { return new ImmutableLine.Builder(); } /** * Builds instances of type {@link ImmutableLine ImmutableLine}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_COLOR = 0x1L; private long initBits = 0x1L; private ImmutableList.Builder points = ImmutableList.builder(); private @Nullable Canvas.Color color; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Line} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(Canvas.Line instance) { Preconditions.checkNotNull(instance, "instance"); addAllPoints(instance.points()); color(instance.color()); return this; } /** * Adds one element to {@link Canvas.Line#points() points} list. * @param element A points element * @return {@code this} builder for use in a chained invocation */ public final Builder addPoint(Canvas.Point element) { this.points.add(element); return this; } /** * Constructs and adds an element for the {@link Canvas.Line#points() points} list. * @param x The value for {@code points.x} * @param y The value for {@code points.y} * @return {@code this} builder for use in a chained invocation */ public final Builder addPoint(int x, int y) { return addPoint(ImmutablePoint.of(x, y)); } /** * Adds elements to {@link Canvas.Line#points() points} list. * @param elements An array of points elements * @return {@code this} builder for use in a chained invocation */ public final Builder addPoint(Canvas.Point... elements) { this.points.add(elements); return this; } /** * Sets or replaces all elements for {@link Canvas.Line#points() points} list. * @param elements An iterable of points elements * @return {@code this} builder for use in a chained invocation */ public final Builder points(Iterable elements) { this.points = ImmutableList.builder(); return addAllPoints(elements); } /** * Adds elements to {@link Canvas.Line#points() points} list. * @param elements An iterable of points elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllPoints(Iterable elements) { this.points.addAll(elements); return this; } /** * Constructs and initializes the value for the {@link Canvas.Line#color() color} attribute. * @param red The value for {@code color.red} * @param green The value for {@code color.green} * @param blue The value for {@code color.blue} * @return {@code this} builder for use in a chained invocation */ public final Builder color(double red, double green, double blue) { return color(ImmutableColor.of(red, green, blue)); } /** * Initializes the value for the {@link Canvas.Line#color() color} attribute. * @param color The value for color * @return {@code this} builder for use in a chained invocation */ public final Builder color(Canvas.Color color) { this.color = ImmutableColor.copyOf(color); initBits &= ~INIT_BIT_COLOR; return this; } /** * Builds a new {@link ImmutableLine ImmutableLine}. * @return An immutable instance of Line * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableLine build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableLine(points.build(), ImmutableColor.copyOf(color)); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_COLOR) != 0) attributes.add("color"); return "Cannot build Line, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy