/** * Returns a new empty builder for a {@code Policy}. * * @param id the ID of the new Policy. * @return the new builder. * @throws PolicyIdInvalidException if {@code policyId} did not comply to {@link Policy#ID_REGEX}. */ public static ImmutablePolicyBuilder of(final CharSequence id) { return new ImmutablePolicyBuilder().setId(id); }
/** * Returns a new builder for a {@code Policy} which is initialised with the given entries. Be aware: if there are * several entries with the same {@link Label} in the given Iterable, later entries will replace earlier ones. * * @param id the ID of the new Policy. * @param policyEntries the initials entries of the new builder. * @return the new builder. * @throws NullPointerException if {@code policyEntries} is null; * @throws PolicyIdInvalidException if {@code policyId} did not comply to {@link Policy#ID_REGEX}. */ public static PolicyBuilder of(final CharSequence id, final Iterable<PolicyEntry> policyEntries) { checkNotNull(policyEntries, "initial Policy entries"); final ImmutablePolicyBuilder result = new ImmutablePolicyBuilder(); result.setId(id); policyEntries.forEach(result::set); return result; }
/** * Returns a new builder for a {@code Policy} based on the given {@code existingPolicy}. * * @param existingPolicy the existing Policy to instantiate the builder with. * @return the new builder. * @throws NullPointerException if {@code existingPolicy} is {@code null}. * @throws PolicyIdInvalidException if {@code policyId} did not comply to {@link Policy#ID_REGEX}. */ public static PolicyBuilder of(final Policy existingPolicy) { checkNotNull(existingPolicy, "existing Policy"); @SuppressWarnings("ConstantConditions") final ImmutablePolicyBuilder result = new ImmutablePolicyBuilder() .setLifecycle(existingPolicy.getLifecycle().orElse(null)) .setRevision(existingPolicy.getRevision().orElse(null)) .setModified(existingPolicy.getModified().orElse(null)); existingPolicy.getId().ifPresent(result::setId); existingPolicy.forEach(result::set); return result; }