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

org.glowroot.common.live.ImmutableHeapFile Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.common.live;

import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Longs;
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 LiveJvmService.HeapFile}.
 * 

* Use builder to create immutable instances: * {@code ImmutableHeapFile.builder()}. * Use static factory method to create immutable instances: * {@code ImmutableHeapFile.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "LiveJvmService.HeapFile"}) @Immutable public final class ImmutableHeapFile implements LiveJvmService.HeapFile { private final String filename; private final long size; private ImmutableHeapFile(String filename, long size) { this.filename = Preconditions.checkNotNull(filename); this.size = size; } private ImmutableHeapFile(ImmutableHeapFile original, String filename, long size) { this.filename = filename; this.size = size; } /** * @return value of {@code filename} attribute */ @JsonProperty @Override public String filename() { return filename; } /** * @return value of {@code size} attribute */ @JsonProperty @Override public long size() { return size; } /** * Copy current immutable object by setting value for {@link LiveJvmService.HeapFile#filename() filename}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for filename * @return modified copy of the {@code this} object */ public final ImmutableHeapFile withFilename(String value) { if (this.filename == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableHeapFile(this, newValue, this.size); } /** * Copy current immutable object by setting value for {@link LiveJvmService.HeapFile#size() size}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for size * @return modified copy of the {@code this} object */ public final ImmutableHeapFile withSize(long value) { if (this.size == value) return this; long newValue = value; return new ImmutableHeapFile(this, this.filename, newValue); } /** * This instance is equal to instances of {@code ImmutableHeapFile} with 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 ImmutableHeapFile && equalTo((ImmutableHeapFile) another); } private boolean equalTo(ImmutableHeapFile another) { return filename.equals(another.filename) && size == another.size; } /** * Computes hash code from attributes: {@code filename}, {@code size}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + filename.hashCode(); h = h * 17 + Longs.hashCode(size); return h; } /** * Prints immutable value {@code HeapFile...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("HeapFile") .add("filename", filename) .add("size", size) .toString(); } /** * Simple representation of this value type suitable Jackson binding * @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure */ @Deprecated static final class Json { @JsonProperty @Nullable String filename; @JsonProperty @Nullable Long size; } /** * @param json JSON-bindable data structure * @return immutable value type * @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure */ @Deprecated @JsonCreator static ImmutableHeapFile fromJson(Json json) { ImmutableHeapFile.Builder builder = ImmutableHeapFile.builder(); if (json.filename != null) { builder.filename(json.filename); } if (json.size != null) { builder.size(json.size); } return builder.build(); } /** * Construct new immutable {@code HeapFile} instance. * @param filename value for {@code filename} * @param size value for {@code size} * @return immutable HeapFile instance */ public static ImmutableHeapFile of(String filename, long size) { return new ImmutableHeapFile(filename, size); } /** * Creates immutable copy of {@link LiveJvmService.HeapFile}. * Uses accessors to get values to initialize immutable instance. * If an instance is already immutable, it is returned as is. * @param instance instance to copy * @return copied immutable HeapFile instance */ public static ImmutableHeapFile copyOf(LiveJvmService.HeapFile instance) { if (instance instanceof ImmutableHeapFile) { return (ImmutableHeapFile) instance; } return ImmutableHeapFile.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.common.live.ImmutableHeapFile ImmutableHeapFile}. * @return new ImmutableHeapFile builder */ public static ImmutableHeapFile.Builder builder() { return new ImmutableHeapFile.Builder(); } /** * Builds instances of {@link org.glowroot.common.live.ImmutableHeapFile ImmutableHeapFile}. * Initialize attributes and then invoke {@link #build()} method to create * immutable instance. *

{@code Builder} is not thread safe and generally should not be stored in field or collection, * but used immediately to create instances. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_FILENAME = 0x1L; private static final long INIT_BIT_SIZE = 0x2L; private long initBits = 0x3; private @Nullable String filename; private long size; private Builder() {} /** * Fill builder with attribute values from provided {@link LiveJvmService.HeapFile} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(LiveJvmService.HeapFile instance) { Preconditions.checkNotNull(instance); filename(instance.filename()); size(instance.size()); return this; } /** * Initializes value for {@link LiveJvmService.HeapFile#filename() filename}. * @param filename value for filename * @return {@code this} builder for chained invocation */ public final Builder filename(String filename) { this.filename = Preconditions.checkNotNull(filename); initBits &= ~INIT_BIT_FILENAME; return this; } /** * Initializes value for {@link LiveJvmService.HeapFile#size() size}. * @param size value for size * @return {@code this} builder for chained invocation */ public final Builder size(long size) { this.size = size; initBits &= ~INIT_BIT_SIZE; return this; } /** * Builds new {@link org.glowroot.common.live.ImmutableHeapFile ImmutableHeapFile}. * @return immutable instance of HeapFile * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableHeapFile build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableHeapFile(null, filename, size); } private boolean filenameIsSet() { return (initBits & INIT_BIT_FILENAME) == 0; } private boolean sizeIsSet() { return (initBits & INIT_BIT_SIZE) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!filenameIsSet()) attributes.add("filename"); if (!sizeIsSet()) attributes.add("size"); return "Cannot build HeapFile, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy