- * This object is an instance of a class - * annotated with {@link Collection}, and - * contains fields annotated with {@link Field}. - *
- * - * @param element the element to write - */ - void write(@NonNull Object element); -} \ No newline at end of file diff --git a/src/main/java/me/braydon/feather/annotation/Collection.java b/src/main/java/me/braydon/feather/annotation/Collection.java index c11c634..de59baa 100644 --- a/src/main/java/me/braydon/feather/annotation/Collection.java +++ b/src/main/java/me/braydon/feather/annotation/Collection.java @@ -1,10 +1,13 @@ package me.braydon.feather.annotation; +import me.braydon.feather.data.Document; + import java.lang.annotation.*; /** * Classes tagged with this annotation - * will be treated as a collection. + * will be treated as a collection that + * holds {@link Document}'s. * * @author Braydon */ diff --git a/src/main/java/me/braydon/feather/annotation/Id.java b/src/main/java/me/braydon/feather/annotation/Id.java index 17cbd33..2791c3f 100644 --- a/src/main/java/me/braydon/feather/annotation/Id.java +++ b/src/main/java/me/braydon/feather/annotation/Id.java @@ -3,9 +3,9 @@ package me.braydon.feather.annotation; import java.lang.annotation.*; /** - * Fields tagged with this annotation will be treated - * as the primary identifying key for documents within - * a {@link Collection}. + * {@link Field}'s tagged with this annotation will be + * treated as the primary identifying key for documents + * within a {@link Collection}. * * @author Braydon */ diff --git a/src/main/java/me/braydon/feather/annotation/Serializable.java b/src/main/java/me/braydon/feather/annotation/Serializable.java index c05d552..66134f4 100644 --- a/src/main/java/me/braydon/feather/annotation/Serializable.java +++ b/src/main/java/me/braydon/feather/annotation/Serializable.java @@ -1,8 +1,13 @@ package me.braydon.feather.annotation; +import com.google.gson.Gson; + import java.lang.annotation.*; /** + * {@link Field}'s tagged with this annotation + * will have serialization handled by {@link Gson}. + * * @author Braydon */ @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/me/braydon/feather/common/EntityUtils.java b/src/main/java/me/braydon/feather/common/EntityUtils.java new file mode 100644 index 0000000..2916d6e --- /dev/null +++ b/src/main/java/me/braydon/feather/common/EntityUtils.java @@ -0,0 +1,29 @@ +package me.braydon.feather.common; + +import lombok.NonNull; +import lombok.experimental.UtilityClass; +import me.braydon.feather.annotation.Collection; + +/** + * @author Braydon + */ +@UtilityClass +public final class EntityUtils { + /** + * Ensure that the given entity is valid. + * + * @param entity the entity to validate + * @param allowEmptyCollections should empty collections be allowed? + */ + public static void ensureValid(@NonNull Object entity, boolean allowEmptyCollections) { + Class> clazz = entity.getClass(); // Get the element class + if (!clazz.isAnnotationPresent(Collection.class)) { // Missing annotation + throw new IllegalStateException("Element is missing @Collection annotation"); + } + Collection annotation = clazz.getAnnotation(Collection.class); // Get the @Collection annotation + String collectionName = annotation.name(); // The name of the collection + if (collectionName.isEmpty() && !allowEmptyCollections) { // Missing collection name + throw new IllegalStateException("Missing collection name in @Collection for " + clazz.getSimpleName()); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/braydon/feather/common/Tuple.java b/src/main/java/me/braydon/feather/common/Tuple.java index c6085dd..139c79d 100644 --- a/src/main/java/me/braydon/feather/common/Tuple.java +++ b/src/main/java/me/braydon/feather/common/Tuple.java @@ -10,6 +10,8 @@ import lombok.Setter; * holds a pair of two values. * * @author Braydon + * @param