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

org.glowroot.agent.config.ImmutablePluginCache Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.agent.config;

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.ImmutableList;
import java.io.File;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.glowroot.common.config.PluginDescriptor;

/**
 * Immutable implementation of {@link PluginCache}.
 * 

* Use builder to create immutable instances: * {@code ImmutablePluginCache.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "PluginCache"}) @Immutable public final class ImmutablePluginCache extends PluginCache { private final ImmutableList pluginJars; private final ImmutableList pluginDescriptors; private ImmutablePluginCache( ImmutableList pluginJars, ImmutableList pluginDescriptors) { this.pluginJars = pluginJars; this.pluginDescriptors = pluginDescriptors; } /** * @return value of {@code pluginJars} attribute */ @JsonProperty @Override public ImmutableList pluginJars() { return pluginJars; } /** * @return value of {@code pluginDescriptors} attribute */ @JsonProperty @Override public ImmutableList pluginDescriptors() { return pluginDescriptors; } /** * Copy current immutable object with elements that replace content of {@link PluginCache#pluginJars() pluginJars}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutablePluginCache withPluginJars(File... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePluginCache(newValue, this.pluginDescriptors); } /** * Copy current immutable object with elements that replace content of {@link PluginCache#pluginJars() pluginJars}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of pluginJars elements to set * @return modified copy of {@code this} object */ public final ImmutablePluginCache withPluginJars(Iterable elements) { if (this.pluginJars == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePluginCache(newValue, this.pluginDescriptors); } /** * Copy current immutable object with elements that replace content of {@link PluginCache#pluginDescriptors() pluginDescriptors}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutablePluginCache withPluginDescriptors(PluginDescriptor... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePluginCache(this.pluginJars, newValue); } /** * Copy current immutable object with elements that replace content of {@link PluginCache#pluginDescriptors() pluginDescriptors}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of pluginDescriptors elements to set * @return modified copy of {@code this} object */ public final ImmutablePluginCache withPluginDescriptors(Iterable elements) { if (this.pluginDescriptors == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePluginCache(this.pluginJars, newValue); } /** * This instance is equal to instances of {@code ImmutablePluginCache} 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 ImmutablePluginCache && equalTo((ImmutablePluginCache) another); } private boolean equalTo(ImmutablePluginCache another) { return pluginJars.equals(another.pluginJars) && pluginDescriptors.equals(another.pluginDescriptors); } /** * Computes hash code from attributes: {@code pluginJars}, {@code pluginDescriptors}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + pluginJars.hashCode(); h = h * 17 + pluginDescriptors.hashCode(); return h; } /** * Prints immutable value {@code PluginCache...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("PluginCache") .add("pluginJars", pluginJars) .add("pluginDescriptors", pluginDescriptors) .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 ImmutableList pluginJars; @JsonProperty @Nullable ImmutableList pluginDescriptors; } /** * @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 ImmutablePluginCache fromJson(Json json) { ImmutablePluginCache.Builder builder = ImmutablePluginCache.builder(); if (json.pluginJars != null) { builder.addAllPluginJars(json.pluginJars); } if (json.pluginDescriptors != null) { builder.addAllPluginDescriptors(json.pluginDescriptors); } return builder.build(); } /** * Creates immutable copy of {@link PluginCache}. * 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 PluginCache instance */ public static ImmutablePluginCache copyOf(PluginCache instance) { if (instance instanceof ImmutablePluginCache) { return (ImmutablePluginCache) instance; } return ImmutablePluginCache.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.agent.config.ImmutablePluginCache ImmutablePluginCache}. * @return new ImmutablePluginCache builder */ public static ImmutablePluginCache.Builder builder() { return new ImmutablePluginCache.Builder(); } /** * Builds instances of {@link org.glowroot.agent.config.ImmutablePluginCache ImmutablePluginCache}. * 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 ImmutableList.Builder pluginJarsBuilder = ImmutableList.builder(); private ImmutableList.Builder pluginDescriptorsBuilder = ImmutableList.builder(); private Builder() {} /** * Fill builder with attribute values from provided {@link PluginCache} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(PluginCache instance) { Preconditions.checkNotNull(instance); addAllPluginJars(instance.pluginJars()); addAllPluginDescriptors(instance.pluginDescriptors()); return this; } /** * Adds one element to {@link PluginCache#pluginJars() pluginJars} list. * @param element pluginJars element * @return {@code this} builder for chained invocation */ public final Builder addPluginJars(File element) { pluginJarsBuilder.add(element); return this; } /** * Adds elements to {@link PluginCache#pluginJars() pluginJars} list. * @param elements array of pluginJars elements * @return {@code this} builder for chained invocation */ public final Builder addPluginJars(File... elements) { pluginJarsBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link PluginCache#pluginJars() pluginJars} list. * @param elements iterable of pluginJars elements * @return {@code this} builder for chained invocation */ public final Builder pluginJars(Iterable elements) { pluginJarsBuilder = ImmutableList.builder(); return addAllPluginJars(elements); } /** * Adds elements to {@link PluginCache#pluginJars() pluginJars} list. * @param elements iterable of pluginJars elements * @return {@code this} builder for chained invocation */ public final Builder addAllPluginJars(Iterable elements) { pluginJarsBuilder.addAll(elements); return this; } /** * Adds one element to {@link PluginCache#pluginDescriptors() pluginDescriptors} list. * @param element pluginDescriptors element * @return {@code this} builder for chained invocation */ public final Builder addPluginDescriptors(PluginDescriptor element) { pluginDescriptorsBuilder.add(element); return this; } /** * Adds elements to {@link PluginCache#pluginDescriptors() pluginDescriptors} list. * @param elements array of pluginDescriptors elements * @return {@code this} builder for chained invocation */ public final Builder addPluginDescriptors(PluginDescriptor... elements) { pluginDescriptorsBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link PluginCache#pluginDescriptors() pluginDescriptors} list. * @param elements iterable of pluginDescriptors elements * @return {@code this} builder for chained invocation */ public final Builder pluginDescriptors(Iterable elements) { pluginDescriptorsBuilder = ImmutableList.builder(); return addAllPluginDescriptors(elements); } /** * Adds elements to {@link PluginCache#pluginDescriptors() pluginDescriptors} list. * @param elements iterable of pluginDescriptors elements * @return {@code this} builder for chained invocation */ public final Builder addAllPluginDescriptors(Iterable elements) { pluginDescriptorsBuilder.addAll(elements); return this; } /** * Builds new {@link org.glowroot.agent.config.ImmutablePluginCache ImmutablePluginCache}. * @return immutable instance of PluginCache * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutablePluginCache build() throws IllegalStateException { return new ImmutablePluginCache(pluginJarsBuilder.build(), pluginDescriptorsBuilder.build()); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy