/** * Constructs an {@link Application} instance. Use this factory method only if the parameters * are known to be valid; it will throw an {@link IllegalArgumentException} otherwise. * @param displayName the human-readable name of the application (may not contain HTML) * @param id the application's identifying URI */ public static Application application(String displayName, URI id) { checkNotNull(displayName, "displayName"); checkNotNull(id, "id"); Either<ValidationErrors, Application> ret = application(some(displayName), some(id.toASCIIString())); if (ret.isLeft()) { throw new IllegalArgumentException(ret.left().get().toString()); } return ret.right().get(); }
/** * Same as {@link #target}, but accepts an {@link Either} which may contain either an * {@link ActivityObject} or {@link ValidationErrors}. In the latter case, the errors are * added to the error list for this Builder. This overload is for convenience, so you can * write expressions like this without having to check intermediate results: * <pre> * Activity.Builder activityBuilder = Activity.builder().someActivityProperties(...) * .target(ActivityObject.builder().someObjectProperties(...).build())) * .build(); * </pre> * @param targetOrErrors an {@link Either} containing either an {@link ActivityObject} or * {@link ValidationErrors} * @return the same Builder instance */ public Builder target(Either<ValidationErrors, ActivityObject> targetOrErrors) { checkNotNull(targetOrErrors, "targetOrErrors"); if (targetOrErrors.isRight()) { this.target = targetOrErrors.right().toOption(); } else { errors.addAll(targetOrErrors.left().get(), "target"); } return this; }
/** * Same as {@link #icon}, but accepts an {@link Either} which may contain either an * {@link Image} or {@link ValidationErrors}. In the latter case, the errors are * added to the error list for this Builder. This overload is for convenience, so you can * write expressions like this without having to check intermediate results: * <pre> * Activity.Builder activityBuilder = Activity.builder().someActivityProperties(...) * .icon(Image.builder(...).someImageProperties(...).build())) * .build(); * </pre> * @param imageOrErrors an {@link Either} containing either an {@link Image} or * {@link ValidationErrors} * @return the same Builder instance */ public Builder icon(Either<ValidationErrors, Image> imageOrErrors) { checkNotNull(imageOrErrors, "imageOrErrors"); if (imageOrErrors.isRight()) { this.icon = imageOrErrors.right().toOption(); } else { errors.addAll(imageOrErrors.left().get(), "icon"); } return this; }
/** * Same as {@link #object}, but accepts an {@link Either} which may contain either an * {@link ActivityObject} or {@link ValidationErrors}. In the latter case, the errors are * added to the error list for this Builder. This overload is for convenience, so you can * write expressions like this without having to check intermediate results: * <pre> * Activity.Builder activityBuilder = Activity.builder().someActivityProperties(...) * .object(ActivityObject.builder().someObjectProperties(...).build())) * .build(); * </pre> * @param objectOrErrors an {@link Either} containing either an {@link ActivityObject} or * {@link ValidationErrors} * @return the same Builder instance */ public Builder object(Either<ValidationErrors, ActivityObject> objectOrErrors) { checkNotNull(objectOrErrors, "targetOrErrors"); if (objectOrErrors.isRight()) { this.object = objectOrErrors.right().toOption(); } else { errors.addAll(objectOrErrors.left().get(), "object"); } return this; }
/** * Constructs an {@link Image} with only an image URI, and no dimensions specified. Use this * constructor only if the URL is known to be valid; it will throw an {@link IllegalArgumentException} * otherwise. * @param url a {@link URI}; cannot be null * @return an {@link Image} */ public static Image withUrl(URI url) { Either<ValidationErrors, Image> ret = builder(url).build(); if (ret.isLeft()) { throw new IllegalArgumentException(ret.left().get().toString()); } return ret.right().get(); }