/** * Initializes the optional value {@link ThreadFactoryProvider#priority() priority} to priority. * @param priority The value for priority * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder priority(Optional<Integer> priority) { checkNotIsSet(priorityIsSet(), "priority"); this.priority = priority.orElse(null); optBits |= OPT_BIT_PRIORITY; return this; }
private void checkRequiredAttributes() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } }
private String formatRequiredAttributesMessage() { List<String> attributes = new ArrayList<>(); if (!namePrefixIsSet()) attributes.add("namePrefix"); if (!loggerIsSet()) attributes.add("logger"); return "Cannot build ThreadFactoryProvider, some of required attributes are not set " + attributes; } }
/** * Creates an immutable copy of a {@link ThreadFactoryProvider} 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 ThreadFactoryProvider instance */ public static ImmutableThreadFactoryProvider copyOf(ThreadFactoryProvider instance) { if (instance instanceof ImmutableThreadFactoryProvider) { return (ImmutableThreadFactoryProvider) instance; } return ((ImmutableThreadFactoryProvider.Builder) ImmutableThreadFactoryProvider.builder()) .namePrefix(instance.namePrefix()) .logger(instance.logger()) .priority(instance.priority()) .daemon(instance.daemon()) .build(); }
/** * Builds a new {@link ImmutableThreadFactoryProvider ImmutableThreadFactoryProvider}. * @return An immutable instance of ThreadFactoryProvider * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableThreadFactoryProvider build() { checkRequiredAttributes(); return new ImmutableThreadFactoryProvider(this); }
/** * Creates a builder for {@link ImmutableThreadFactoryProvider ImmutableThreadFactoryProvider}. * @return A new ImmutableThreadFactoryProvider builder */ public static NamePrefixBuildStage builder() { return new ImmutableThreadFactoryProvider.Builder(); }
/** * Initializes the value for the {@link ThreadFactoryProvider#daemon() daemon} attribute. * <p><em>If not set, this attribute will have a default value as returned by the initializer of {@link ThreadFactoryProvider#daemon() daemon}.</em> * @param daemon The value for daemon * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder daemon(boolean daemon) { checkNotIsSet(daemonIsSet(), "daemon"); this.daemon = daemon; optBits |= OPT_BIT_DAEMON; return this; }
/** * Initializes the optional value {@link ThreadFactoryProvider#priority() priority} to priority. * @param priority The value for priority * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder priority(int priority) { checkNotIsSet(priorityIsSet(), "priority"); this.priority = priority; optBits |= OPT_BIT_PRIORITY; return this; }
/** * Initializes the value for the {@link ThreadFactoryProvider#namePrefix() namePrefix} attribute. * @param namePrefix The value for namePrefix * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder namePrefix(String namePrefix) { checkNotIsSet(namePrefixIsSet(), "namePrefix"); this.namePrefix = Objects.requireNonNull(namePrefix, "namePrefix"); initBits &= ~INIT_BIT_NAME_PREFIX; return this; }
/** * Initializes the value for the {@link ThreadFactoryProvider#logger() logger} attribute. * @param logger The value for logger * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder logger(Logger logger) { checkNotIsSet(loggerIsSet(), "logger"); this.logger = Objects.requireNonNull(logger, "logger"); initBits &= ~INIT_BIT_LOGGER; return this; }