/** * Sets the given revision number to this builder. * * @param revisionNumber the revision number to be set. * @return this builder to allow method chaining. */ default PolicyBuilder setRevision(final long revisionNumber) { return setRevision(PolicyRevision.newInstance(revisionNumber)); }
@Override public int compareTo(final PolicyRevision o) { checkNotNull(o, "other revision to compare this revision with"); return Long.compare(value, o.toLong()); }
/** * Returns a new immutable Policy which is initialised with the specified entries. * * @param id the ID of the new Policy. * @param entries the entries of the Policy. * @return the new initialised Policy. * @throws NullPointerException if any argument is {@code null}. */ public static Policy newPolicy(final CharSequence id, final Iterable<PolicyEntry> entries) { return ImmutablePolicy.of(id, PolicyLifecycle.ACTIVE, PolicyRevision.newInstance(1), null, entries); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { checkNotNull(schemaVersion, "schema version"); checkNotNull(thePredicate, "predicate"); final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.SCHEMA_VERSION, schemaVersion.toInt(), predicate); if (null != lifecycle) { jsonObjectBuilder.set(JsonFields.LIFECYCLE, lifecycle.name(), predicate); } if (null != revision) { jsonObjectBuilder.set(JsonFields.REVISION, revision.toLong(), predicate); } if (null != modified) { jsonObjectBuilder.set(JsonFields.MODIFIED, modified.toString(), predicate); } if (null != policyId) { jsonObjectBuilder.set(JsonFields.NAMESPACE, namespace, predicate); jsonObjectBuilder.set(JsonFields.ID, policyId, predicate); } jsonObjectBuilder.set(JsonFields.ENTRIES, stream() .map(policyEntry -> JsonFactory.newObjectBuilder() .set(policyEntry.getLabel().getJsonFieldDefinition(), policyEntry.toJson(schemaVersion, thePredicate.and(FieldType.notHidden())), predicate) // notice: only "not HIDDEN" sub-fields of PolicyEntry are included .build()) .collect(JsonCollectors.objectsToObject()), predicate); return jsonObjectBuilder.build(); }
/** * Returns a new immutable Policy which is initialised with the specified entries. * * @param id the ID of the new Policy. * @param entry the mandatory entry of the Policy. * @param furtherEntries additional entries of the Policy. * @return the new initialised Policy. * @throws NullPointerException if any argument is {@code null}. */ public static Policy newPolicy(final CharSequence id, final PolicyEntry entry, final PolicyEntry... furtherEntries) { checkNotNull(entry, "mandatory entry"); checkNotNull(furtherEntries, "additional policy entries"); final Collection<PolicyEntry> allEntries = new HashSet<>(1 + furtherEntries.length); allEntries.add(entry); Collections.addAll(allEntries, furtherEntries); return ImmutablePolicy.of(id, PolicyLifecycle.ACTIVE, PolicyRevision.newInstance(1), null, allEntries); }