ImmutableValue.Builder builder = ImmutableValue.builder(); if (json.createIndex != null) { builder.createIndex(json.createIndex); builder.modifyIndex(json.modifyIndex); builder.lockIndex(json.lockIndex); builder.key(json.key); builder.flags(json.flags); builder.value(json.value); builder.session(json.session); return builder.build();
/** * Builds a new {@link ImmutableValue ImmutableValue}. * @return An immutable instance of Value * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableValue build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableValue(createIndex, modifyIndex, lockIndex, key, flags, value, session); }
/** * Fill a builder with attribute values from the provided {@code Value} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(Value instance) { Preconditions.checkNotNull(instance, "instance"); createIndex(instance.getCreateIndex()); modifyIndex(instance.getModifyIndex()); lockIndex(instance.getLockIndex()); key(instance.getKey()); flags(instance.getFlags()); Optional<String> valueOptional = instance.getValue(); if (valueOptional.isPresent()) { value(valueOptional); } Optional<String> sessionOptional = instance.getSession(); if (sessionOptional.isPresent()) { session(sessionOptional); } return this; }
/** * Creates an immutable copy of a {@link Value} 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 Value instance */ public static ImmutableValue copyOf(Value instance) { if (instance instanceof ImmutableValue) { return (ImmutableValue) instance; } return ImmutableValue.builder() .from(instance) .build(); }
/** * Creates a builder for {@link ImmutableValue ImmutableValue}. * @return A new ImmutableValue builder */ public static ImmutableValue.Builder builder() { return new ImmutableValue.Builder(); }