Skip to content

Commit 573b60d

Browse files
Javadocs!!!
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
1 parent bcc1434 commit 573b60d

30 files changed

+330
-127
lines changed

api/src/main/java/io/cloudevents/CloudEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
/**
2222
* Interface representing an in memory read only representation of a CloudEvent,
23-
* as specified by the <a href="/cloudevents/spec/blob/v1.0/spec.md">CloudEvents specification</a>
23+
* as specified by the <a href="/cloudevents/spec/blob/v1.0/spec.md">CloudEvents specification</a>.
2424
*/
2525
public interface CloudEvent extends CloudEventContext {
2626

2727
/**
28-
* The event data
28+
* @return The event data, if any, otherwise {@code null}
2929
*/
3030
@Nullable
3131
CloudEventData getData();

api/src/main/java/io/cloudevents/SpecVersion.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@
2929
*/
3030
@ParametersAreNonnullByDefault
3131
public enum SpecVersion {
32+
/**
33+
* @see <a href="https://github.com/cloudevents/spec/releases/tag/v0.3">CloudEvents release v0.3</a>
34+
*/
3235
V03(
3336
"0.3",
3437
Arrays.asList("specversion", "id", "type", "source"),
3538
Arrays.asList("datacontenttype", "datacontentencoding", "schemaurl", "subject", "time")
3639
),
40+
/**
41+
* @see <a href="https://github.com/cloudevents/spec/releases/tag/v1.0">CloudEvents release v1.0</a>
42+
*/
3743
V1(
3844
"1.0",
3945
Arrays.asList("specversion", "id", "type", "source"),

api/src/main/java/io/cloudevents/lang/Nullable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import static java.lang.annotation.RetentionPolicy.RUNTIME;
2828
import static javax.annotation.meta.When.MAYBE;
2929

30+
/**
31+
* This annotation is used to define a method parameter or return type as nullable.
32+
*/
3033
@Target(value = {METHOD, PARAMETER, FIELD})
3134
@Retention(value = RUNTIME)
3235
@Documented

api/src/main/java/io/cloudevents/rw/CloudEventDataMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
/**
2525
* Interface to convert a {@link CloudEventData} instance to another one.
26+
*
27+
* @param <R> the returned {@link CloudEventData} from this mapper.
2628
*/
2729
@FunctionalInterface
2830
@ParametersAreNonnullByDefault
@@ -38,7 +40,7 @@ public interface CloudEventDataMapper<R extends CloudEventData> {
3840
R map(CloudEventData data) throws CloudEventRWException;
3941

4042
/**
41-
* No-op identity mapper which can be used as default when no mapper is provided.
43+
* @return No-op identity mapper which can be used as default when no mapper is provided.
4244
*/
4345
static CloudEventDataMapper<CloudEventData> identity() {
4446
return d -> d;

api/src/main/java/io/cloudevents/rw/CloudEventRWException.java

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package io.cloudevents.rw;
1919

20+
import io.cloudevents.lang.Nullable;
21+
2022
/**
2123
* This class is the exception Protocol Binding and Event Format implementers can use to signal errors while serializing/deserializing CloudEvent.
2224
*/
@@ -35,9 +37,9 @@ public enum CloudEventRWExceptionKind {
3537
*/
3638
INVALID_ATTRIBUTE_NAME,
3739
/**
38-
* The extension name is not valid,
39-
* because it doesn't follow the <a href="/cloudevents/spec/blob/v1.0/spec.md#attribute-naming-convention">naming convention</a>
40-
* enforced by the CloudEvents spec.
40+
* The extension name is not valid because it doesn't follow the naming convention enforced by the CloudEvents spec.
41+
*
42+
* @see <a href="/cloudevents/spec/blob/v1.0/spec.md#attribute-naming-convention">naming convention</a>
4143
*/
4244
INVALID_EXTENSION_NAME,
4345
/**
@@ -83,46 +85,77 @@ private CloudEventRWException(CloudEventRWExceptionKind kind, String message, Th
8385
this.kind = kind;
8486
}
8587

88+
/**
89+
* @return the {@link CloudEventRWExceptionKind} associated to this exception instance.
90+
*/
8691
public CloudEventRWExceptionKind getKind() {
8792
return kind;
8893
}
8994

95+
/**
96+
* @param specVersion the invalid input spec version
97+
* @return a new {@link CloudEventRWException} instance
98+
*/
9099
public static CloudEventRWException newInvalidSpecVersion(String specVersion) {
91100
return new CloudEventRWException(
92101
CloudEventRWExceptionKind.INVALID_SPEC_VERSION,
93102
"Invalid specversion: " + specVersion
94103
);
95104
}
96105

106+
/**
107+
* @param attributeName the invalid attribute name
108+
* @return a new {@link CloudEventRWException} instance
109+
*/
97110
public static CloudEventRWException newInvalidAttributeName(String attributeName) {
98111
return new CloudEventRWException(
99112
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_NAME,
100113
"Invalid attribute: " + attributeName
101114
);
102115
}
103116

117+
/**
118+
* @param extensionName the invalid extension name
119+
* @return a new {@link CloudEventRWException} instance
120+
*/
104121
public static CloudEventRWException newInvalidExtensionName(String extensionName) {
105122
return new CloudEventRWException(
106123
CloudEventRWExceptionKind.INVALID_EXTENSION_NAME,
107124
"Invalid extensions name: " + extensionName
108125
);
109126
}
110127

128+
/**
129+
* @param attributeName the invalid attribute name
130+
* @param clazz the type of the attribute
131+
* @return a new {@link CloudEventRWException} instance
132+
*/
111133
public static CloudEventRWException newInvalidAttributeType(String attributeName, Class<?> clazz) {
112134
return new CloudEventRWException(
113135
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_TYPE,
114136
"Invalid attribute/extension type for \"" + attributeName + "\": " + clazz.getCanonicalName()
115137
);
116138
}
117139

118-
public static CloudEventRWException newInvalidAttributeValue(String attributeName, Object value, Throwable cause) {
140+
/**
141+
* @param attributeName the invalid attribute name
142+
* @param value the value of the attribute
143+
* @param cause an optional cause identifying the eventual validation error
144+
* @return a new {@link CloudEventRWException} instance
145+
*/
146+
public static CloudEventRWException newInvalidAttributeValue(String attributeName, Object value, @Nullable Throwable cause) {
119147
return new CloudEventRWException(
120148
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_VALUE,
121149
"Invalid attribute/extension value for \"" + attributeName + "\": " + value,
122150
cause
123151
);
124152
}
125153

154+
/**
155+
* @param actual the actual data type
156+
* @param allowed the list of allowed data types
157+
* @return a new {@link CloudEventRWException} instance
158+
*/
126159
public static CloudEventRWException newInvalidDataType(String actual, String... allowed) {
127160
String message;
128161
if (allowed.length == 0) {
@@ -136,6 +169,12 @@ public static CloudEventRWException newInvalidDataType(String actual, String...
136169
);
137170
}
138171

172+
/**
173+
* @param cause the cause of the conversion failure
174+
* @param from the input data type
175+
* @param to the target data type
176+
* @return a new {@link CloudEventRWException} instance
177+
*/
139178
public static CloudEventRWException newDataConversion(Throwable cause, String from, String to) {
140179
return new CloudEventRWException(
141180
CloudEventRWExceptionKind.DATA_CONVERSION,
@@ -144,17 +183,26 @@ public static CloudEventRWException newDataConversion(Throwable cause, String fr
144183
);
145184
}
146185

147-
public static CloudEventRWException newOther(Throwable cause) {
186+
/**
187+
* @return a new {@link CloudEventRWException} instance.
188+
*/
189+
public static CloudEventRWException newUnknownEncodingException() {
148190
return new CloudEventRWException(
149-
CloudEventRWExceptionKind.OTHER,
150-
cause
191+
CloudEventRWExceptionKind.UNKNOWN_ENCODING,
192+
"Could not parse. Unknown encoding. Invalid content type or spec version"
151193
);
152194
}
153195

154-
public static CloudEventRWException newUnknownEncodingException() {
196+
/**
197+
* This wraps a {@link Throwable} in a new generic instance of this exception.
198+
*
199+
* @param cause the cause of the exception
200+
* @return a new {@link CloudEventRWException} instance
201+
*/
202+
public static CloudEventRWException newOther(Throwable cause) {
155203
return new CloudEventRWException(
156-
CloudEventRWExceptionKind.UNKNOWN_ENCODING,
157-
"Could not parse. Unknown encoding. Invalid content type or spec version"
204+
CloudEventRWExceptionKind.OTHER,
205+
cause
158206
);
159207
}
160208
}

api/src/main/java/io/cloudevents/rw/CloudEventReader.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@
3030
public interface CloudEventReader {
3131

3232
/**
33-
* Visit self using the provided visitor factory
33+
* Like {@link #read(CloudEventWriterFactory, CloudEventDataMapper)}, but with the identity {@link CloudEventDataMapper}.
3434
*
35-
* @param writerFactory a factory that generates a visitor starting from the SpecVersion of the event
36-
* @throws CloudEventRWException if something went wrong during the read.
35+
* @see #read(CloudEventWriterFactory, CloudEventDataMapper)
3736
*/
38-
default <V extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<V, R> writerFactory) throws CloudEventRWException {
37+
default <W extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<W, R> writerFactory) throws CloudEventRWException {
3938
return read(writerFactory, CloudEventDataMapper.identity());
4039
}
4140

4241
/**
43-
* Like {@link CloudEventReader#read(CloudEventWriterFactory)}, but providing a mapper for {@link io.cloudevents.CloudEventData} to be invoked when the data field is available.
42+
* Read self using the provided writer factory.
43+
*
44+
* @param <W> the {@link CloudEventWriter} type
45+
* @param <R> the return type of the {@link CloudEventWriter}
46+
* @param writerFactory a factory that generates a visitor starting from the SpecVersion of the event
47+
* @param mapper the mapper to invoke when building the {@link CloudEventData}
48+
* @return the return value returned by {@link CloudEventWriter#end()} or {@link CloudEventWriter#end(CloudEventData)}
49+
* @throws CloudEventRWException if something went wrong during the read.
4450
*/
45-
<V extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<V, R> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException;
51+
<W extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<W, R> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException;
4652

4753
}

api/src/main/java/io/cloudevents/rw/CloudEventWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@
2828
public interface CloudEventWriter<R> extends CloudEventAttributesWriter, CloudEventExtensionsWriter {
2929

3030
/**
31-
* End the visit with a data field
31+
* End the read with a data payload.
3232
*
33+
* @param data the data to write
3334
* @return an eventual return value
3435
* @throws CloudEventRWException if the message writer cannot be ended.
3536
*/
3637
R end(CloudEventData data) throws CloudEventRWException;
3738

3839
/**
39-
* End the visit
40+
* End the read.
4041
*
4142
* @return an eventual return value
4243
* @throws CloudEventRWException if the message writer cannot be ended.

api/src/main/java/io/cloudevents/rw/CloudEventWriterFactory.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@
1919

2020
import io.cloudevents.SpecVersion;
2121

22+
/**
23+
* This factory is used to enforce setting the {@link SpecVersion} as first step in the writing process.
24+
*
25+
* @param <W> The type of the {@link CloudEventWriter} created by this factory
26+
* @param <R> The return value of the {@link CloudEventWriter} created by this factory
27+
*/
2228
@FunctionalInterface
23-
public interface CloudEventWriterFactory<V extends CloudEventWriter<R>, R> {
29+
public interface CloudEventWriterFactory<W extends CloudEventWriter<R>, R> {
2430

2531
/**
2632
* Create a {@link CloudEventWriter} starting from the provided {@link SpecVersion}
@@ -29,5 +35,5 @@ public interface CloudEventWriterFactory<V extends CloudEventWriter<R>, R> {
2935
* @return the new writer
3036
* @throws CloudEventRWException if the spec version is invalid or the writer cannot be instantiated.
3137
*/
32-
V create(SpecVersion version) throws CloudEventRWException;
38+
W create(SpecVersion version) throws CloudEventRWException;
3339
}

core/src/main/java/io/cloudevents/core/CloudEventUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@
3030
import io.cloudevents.rw.CloudEventReader;
3131

3232
/**
33-
* This class contains a set of utility methods to deal with conversions of io.cloudevents related interfaces
33+
* This class contains a set of utility methods to deal with conversions of {@link io.cloudevents} related interfaces
3434
*/
3535
public final class CloudEventUtils {
3636

3737
private CloudEventUtils() {}
3838

3939
/**
4040
* Convert a {@link CloudEvent} to a {@link CloudEventReader}. This method provides a default implementation
41-
* for CloudEvent that doesn't implement {@link CloudEventReader}
42-
* for CloudEvent that doesn't implement CloudEventVisitable.
41+
* for CloudEvent that doesn't implement {@link CloudEventReader}.
4342
* <p>
4443
* It's safe to use the returned {@link CloudEventReader} multiple times.
4544
*
@@ -94,6 +93,11 @@ public static CloudEvent toEvent(CloudEventReader reader, CloudEventDataMapper<?
9493

9594
/**
9695
* Get the data contained in {@code event} and map it using the provided mapper.
96+
*
97+
* @param event the event eventually containing the data
98+
* @param mapper the mapper to use to map the data
99+
* @param <R> the returned {@link CloudEventData} implementation from the provided mapper
100+
* @return the data contained in {@code event} and mapped with {@code mapper}, if any, otherwise null
97101
*/
98102
@Nullable
99103
public static <R extends CloudEventData> R mapData(CloudEvent event, CloudEventDataMapper<R> mapper) {

core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import java.util.Arrays;
66
import java.util.Objects;
77

8+
/**
9+
* An implementation of {@link CloudEventData} that wraps a byte array.
10+
*/
811
public class BytesCloudEventData implements CloudEventData {
912

1013
private final byte[] value;
1114

1215
/**
16+
* @param value the bytes to wrap
1317
* @deprecated use {@link BytesCloudEventData#wrap(byte[])}
1418
*/
1519
public BytesCloudEventData(byte[] value) {

0 commit comments

Comments
 (0)