Skip to content

Commit

Permalink
small code and javadoc adjustments;
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Nov 17, 2021
1 parent 83be45a commit edc1c90
Show file tree
Hide file tree
Showing 47 changed files with 234 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;

/**
* Interface for accessing configuration of Loggers.
Expand All @@ -44,9 +44,9 @@ public interface LoggerConfig extends Jsonifiable.WithPredicate<JsonObject, Json
Optional<String> getLogger();

/**
* Returns all non hidden marked fields of this object.
* Returns all non-hidden marked fields of this object.
*
* @return a JSON object representation of this object including only non hidden marked fields.
* @return a JSON object representation of this object including only non-hidden marked fields.
*/
@Override
default JsonObject toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;


/**
Expand Down Expand Up @@ -161,7 +161,7 @@ default List<String> getAuthorizationSubjectIds() {
boolean isAuthorized(Collection<AuthorizationSubject> granted, Collection<AuthorizationSubject> revoked);

/**
* Returns all non hidden marked fields of this authorization context.
* Returns all non-hidden marked fields of this authorization context.
*
* @return a JSON object representation of this authorization context including only {@link org.eclipse.ditto.base.model.json.FieldType#REGULAR}
* marked fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class AbstractIdValidator implements BiConsumer<CharSequence, Di
* @param idRegex the regular expression to match IDs to.
*/
protected AbstractIdValidator(final String idRegex) {
this.idRegex = idRegex;
this.idRegex = checkNotNull(idRegex, "idRegex");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.entity.id.EntityId;
import org.eclipse.ditto.base.model.entity.metadata.Metadata;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldSelector;
import org.eclipse.ditto.json.JsonObject;

/**
* Base type for top level entities.
Expand Down Expand Up @@ -79,9 +79,9 @@ public interface Entity<T extends Revision<T>> extends Jsonifiable.WithFieldSele
boolean isDeleted();

/**
* Returns all non hidden marked fields of this object.
* Returns all non-hidden marked fields of this object.
*
* @return a JSON object representation of this object including only non hidden marked fields.
* @return a JSON object representation of this object including only non-hidden marked fields.
*/
@Override
default JsonObject toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
import javax.annotation.concurrent.Immutable;

import org.atteo.classindex.IndexSubclasses;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonObjectBuilder;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.headers.DittoHeadersSettable;
import org.eclipse.ditto.base.model.headers.WithManifest;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonObjectBuilder;

/**
* Parent RuntimeException for all RuntimeExceptions of Ditto.
Expand Down Expand Up @@ -192,9 +192,9 @@ public int hashCode() {
}

/**
* Returns all non hidden marked fields of this exception.
* Returns all non-hidden marked fields of this exception.
*
* @return a JSON object representation of this exception including only non hidden marked fields.
* @return a JSON object representation of this exception including only non-hidden marked fields.
*/
@Override
public JsonObject toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ public ResponseType getResponseType() {
}

/**
* Returns all non hidden marked fields of this Acknowledgement.
* Returns all non-hidden marked fields of this Acknowledgement.
*
* @return a JSON object representation of this Acknowledgement including only non hidden marked fields.
* @return a JSON object representation of this Acknowledgement including only non-hidden marked fields.
*/
@Override
public JsonObject toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,9 @@ public ResponseType getResponseType() {
}

/**
* Returns all non hidden marked fields of this Acknowledgement.
* Returns all non-hidden marked fields of this Acknowledgement.
*
* @return a JSON object representation of this Acknowledgement including only non hidden marked fields.
* @return a JSON object representation of this Acknowledgement including only non-hidden marked fields.
*/
@Override
public JsonObject toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonObjectBuilder;
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;


/**
Expand All @@ -47,7 +47,8 @@ public abstract class AbstractCommand<T extends AbstractCommand<T>> implements C
* @param dittoHeaders the headers of the command.
* @param category used for validation of response required header.
* @throws NullPointerException if any argument is {@code null}.
* @throws CommandHeaderInvalidException if category is {@link org.eclipse.ditto.base.model.signals.commands.Command.Category#QUERY} and response is not required.
* @throws CommandHeaderInvalidException if category is
* {@link org.eclipse.ditto.base.model.signals.commands.Command.Category#QUERY} and response is not required.
*/
protected AbstractCommand(final String type, final DittoHeaders dittoHeaders, final Category category) {
this.type = checkNotNull(type, "type");
Expand All @@ -61,8 +62,8 @@ protected AbstractCommand(final String type, final DittoHeaders dittoHeaders, fi
* @param type the name of this command.
* @param dittoHeaders the headers of the command.
* @throws NullPointerException if any argument is {@code null}.
* @throws CommandHeaderInvalidException if {@link #getCategory()} is {@link org.eclipse.ditto.base.model.signals.commands.Command.Category#QUERY} and response is
* not required.
* @throws CommandHeaderInvalidException if {@link #getCategory()} is
* {@link org.eclipse.ditto.base.model.signals.commands.Command.Category#QUERY} and response is not required.
*/
protected AbstractCommand(final String type, final DittoHeaders dittoHeaders) {
this.type = checkNotNull(type, "type");
Expand All @@ -71,6 +72,7 @@ protected AbstractCommand(final String type, final DittoHeaders dittoHeaders) {
}

private void validateHeaders(final Category category) {
checkNotNull(category, "category");
if (Category.QUERY == category && !dittoHeaders.isResponseRequired()) {
final String headerKey = DittoHeaderDefinition.RESPONSE_REQUIRED.getKey();
throw CommandHeaderInvalidException.newBuilder(headerKey)
Expand Down Expand Up @@ -136,6 +138,7 @@ public boolean equals(@Nullable final Object obj) {
return false;
}
final AbstractCommand<?> other = (AbstractCommand<?>) obj;

return other.canEqual(this) && Objects.equals(dittoHeaders, other.dittoHeaders)
&& Objects.equals(type, other.type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void ensureValidSize(final LongSupplier sizeSupplier, final Supplier<Ditt
* @throws T if size limit is set and exceeded
* @since 1.1.0
*/
public void ensureValidSize(final LongSupplier upperBoundSupplier, final LongSupplier sizeSupplier, final Supplier<DittoHeaders> headersSupplier) {
public void ensureValidSize(final LongSupplier upperBoundSupplier, final LongSupplier sizeSupplier,
final Supplier<DittoHeaders> headersSupplier) {
if (null != maxSize && upperBoundSupplier.getAsLong() >= maxSize) {
ensureValidSize(sizeSupplier, headersSupplier);
}
Expand All @@ -90,4 +91,5 @@ public void ensureValidSize(final LongSupplier upperBoundSupplier, final LongSup
* @return the exception of type T
*/
protected abstract T newInvalidSizeException(long maxSize, long actualSize, DittoHeaders headers);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import javax.annotation.concurrent.Immutable;

import org.atteo.classindex.IndexSubclasses;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;

/**
* Base Interface for all commands which are understood by Ditto.
Expand Down Expand Up @@ -62,9 +62,9 @@ default JsonSchemaVersion getImplementedSchemaVersion() {
}

/**
* Returns all non hidden marked fields of this command.
* Returns all non-hidden marked fields of this command.
*
* @return a JSON object representation of this command including only non hidden marked fields.
* @return a JSON object representation of this command including only non-hidden marked fields.
*/
@Override
default JsonObject toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.base.model.exceptions.DittoJsonException;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonParseException;
import org.eclipse.ditto.base.model.exceptions.DittoJsonException;

/**
* This class helps to deserialize JSON to a sub-class of {@link Command}. Hereby this class extracts the values
Expand Down Expand Up @@ -84,8 +84,8 @@ public CommandJsonDeserializer(final String type, final String jsonString) {
* @throws NullPointerException if {@code commandSupplier} is {@code null}.
* @throws org.eclipse.ditto.json.JsonMissingFieldException if the JSON object did not contain a field for
* {@link org.eclipse.ditto.base.model.signals.commands.Command.JsonFields#TYPE}.
* @throws org.eclipse.ditto.base.model.exceptions.DittoJsonException if the JSON object did not contain the expected value for
* {@link org.eclipse.ditto.base.model.signals.commands.Command.JsonFields#TYPE}.
* @throws org.eclipse.ditto.base.model.exceptions.DittoJsonException if the JSON object did not contain
* the expected value for {@link org.eclipse.ditto.base.model.signals.commands.Command.JsonFields#TYPE}.
*/
public T deserialize(final Supplier<T> commandSupplier) {
checkNotNull(commandSupplier, "supplier for a command object");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeExceptionBuilder;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.JsonParsableException;
import org.eclipse.ditto.json.JsonObject;

/**
* Thrown if a {@link Command} is not supported by the version called.
Expand Down Expand Up @@ -79,7 +79,8 @@ public static CommandNotSupportedException fromMessage(@Nullable final String me
* Constructs a new {@code CommandNotSupportedException} object with the exception message extracted from the
* given JSON object.
*
* @param jsonObject the JSON to read the {@link org.eclipse.ditto.base.model.exceptions.DittoRuntimeException.JsonFields#MESSAGE} field from.
* @param jsonObject the JSON to read the
* {@link org.eclipse.ditto.base.model.exceptions.DittoRuntimeException.JsonFields#MESSAGE} field from.
* @param dittoHeaders the headers of the command which resulted in this exception.
* @return the new CommandNotSupportedException.
* @throws NullPointerException if any argument is {@code null}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
import javax.annotation.concurrent.Immutable;

import org.atteo.classindex.IndexSubclasses;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.base.model.common.ResponseType;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.json.FieldType;
import org.eclipse.ditto.base.model.json.JsonSchemaVersion;
import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonFieldDefinition;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonValue;

/**
* Aggregates all possible responses relating to a given {@link Command}.
Expand Down Expand Up @@ -69,7 +69,7 @@ default ResponseType getResponseType() {
}

/**
* Returns all non hidden marked fields of this command response.
* Returns all non-hidden marked fields of this command response.
*
* @return a JSON object representation of this command response including only regular, non-hidden marked fields.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonParseException;
import org.eclipse.ditto.base.model.common.HttpStatus;
import org.eclipse.ditto.base.model.common.HttpStatusCodeOutOfRangeException;
import org.eclipse.ditto.base.model.exceptions.DittoJsonException;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonParseException;

/**
* This class helps to deserialize JSON to a sub-class of {@link CommandResponse}. Hereby this class extracts the
* values which are common for all command responses. All remaining required values have to be extracted in
* {@link CommandResponseJsonDeserializer.FactoryMethodFunction#create(org.eclipse.ditto.base.model.common.HttpStatus)}. There the actual command response object is created, too.
* {@link CommandResponseJsonDeserializer.FactoryMethodFunction#create(org.eclipse.ditto.base.model.common.HttpStatus)}.
* There the actual command response object is created, too.
*/
@Immutable
public final class CommandResponseJsonDeserializer<T extends CommandResponse> {
Expand Down Expand Up @@ -65,13 +66,14 @@ public CommandResponseJsonDeserializer(final String type, final String jsonStrin

/**
* Partly deserializes the JSON which was given to this object's constructor. The factory method function which is
* given to this method is responsible for creating the actual {@code CommandResponseType}. This method receives the
* partly deserialized values which can be completed by implementors if further values are required.
* given to this method is responsible for creating the actual {@code CommandResponseType}. This method receives
* the partly deserialized values which can be completed by implementors if further values are required.
*
* @param factoryMethodFunction creates the actual {@code CommandResponseType} object.
* @return the command response.
* @throws NullPointerException if {@code factoryMethodFunction} is {@code null}.
* @throws org.eclipse.ditto.json.JsonParseException if the JSON is invalid or if the command response type differs from the expected one.
* @throws org.eclipse.ditto.json.JsonParseException if the JSON is invalid or if the command response type
* differs from the expected one.
*/
public T deserialize(final FactoryMethodFunction<T> factoryMethodFunction) {
checkNotNull(factoryMethodFunction, "method for creating a command response object");
Expand Down

0 comments on commit edc1c90

Please sign in to comment.