Skip to content
Snippets Groups Projects
Commit 00fe7413 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add documentation for simple pojo classes

parent dc7ea56d
No related branches found
No related tags found
No related merge requests found
Showing
with 78 additions and 4 deletions
......@@ -3,6 +3,12 @@ package de.unikoblenz.fgbks.base.builder;
import java.io.Serializable;
import java.lang.reflect.Field;
/**
* A abstract builder for creating java pojo classes.
*
* @param <E> the type of the object being constructed
* @param <B> the instance type of the builder
*/
public abstract class AbstractBuilder<E, B extends AbstractBuilder<E, B>> implements Serializable {
private static final String VALUE_FIELD_NAME = "value";
......@@ -46,8 +52,18 @@ public abstract class AbstractBuilder<E, B extends AbstractBuilder<E, B>> implem
protected abstract E newInstance();
/**
* Check if the fields in the value object are valid.
*/
protected abstract void validate();
/**
* Start the building process and return the finished object. While building the new object the
* function {@link DefaultBuilder#validate()} is called and should be passed without an exception.
* Every time this function is called a new instance of the type is returned.
*
* @return the new created object
*/
public E build() {
validate();
E result = value;
......
......@@ -31,6 +31,9 @@ public class DefaultBuilder<E> extends AbstractBuilder<E, DefaultBuilder<E>> {
return this;
}
/**
* {@inheritDoc}
*/
@Override
protected void validate() {
// nothing to validate
......
......@@ -2,12 +2,17 @@ package de.unikoblenz.fgbks.base.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
/**
* A value object representing a description.
*/
public class Description extends AbstractStringValueObject {
/** Create a new copy of the given description object. */
public Description(Description initialValue) {
this(initialValue.getValue());
}
/** Create a description object with the given {@code initialValue}. */
public Description(String initialValue) {
super(initialValue);
}
......
......@@ -2,12 +2,17 @@ package de.unikoblenz.fgbks.base.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
/**
* A value object representing a label.
*/
public class Label extends AbstractStringValueObject {
/** Create a new copy of the given label object. */
public Label(Label initialValue) {
this(initialValue.getValue());
}
/** Create a label object with the given {@code initialValue}. */
public Label(String initialValue) {
super(initialValue);
}
......
......@@ -2,12 +2,17 @@ package de.unikoblenz.fgbks.base.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
/**
* A value object representing a message.
*/
public class Message extends AbstractStringValueObject {
/** Create a new copy of the given message object. */
public Message(Message initialValue) {
this(initialValue.getValue());
}
/** Create a message object with the given {@code initialValue}. */
public Message(String initialValue) {
super(initialValue);
}
......
......@@ -2,12 +2,17 @@ package de.unikoblenz.fgbks.base.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
/**
* A value object representing a name.
*/
public class Name extends AbstractStringValueObject {
/** Create a new copy of the given name object. */
public Name(Name initialValue) {
this(initialValue.getValue());
}
/** Create a name object with the given {@code initialValue}. */
public Name(String initialValue) {
super(initialValue);
}
......
......@@ -2,12 +2,17 @@ package de.unikoblenz.fgbks.base.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
/**
* A value object representing a string value.
*/
public class StringValue extends AbstractStringValueObject {
/** Create a new copy of the given string value object. */
public StringValue(StringValue initialValue) {
this(initialValue.getValue());
}
/** Create a string value object with the given {@code initialValue}. */
public StringValue(String initialValue) {
super(initialValue);
}
......
......@@ -2,12 +2,17 @@ package de.unikoblenz.fgbks.base.domain;
import de.unikoblenz.fgbks.base.value.AbstractStringValueObject;
/**
* A value object representing a text.
*/
public class Text extends AbstractStringValueObject {
/** Create a new copy of the given text object. */
public Text(Text initialValue) {
this(initialValue.getValue());
}
/** Create a text object with the given {@code initialValue}. */
public Text(String initialValue) {
super(initialValue);
}
......
......@@ -6,6 +6,9 @@ import javax.json.bind.JsonbConfig;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
/**
* A provider for the configuration of jsonb handling. See {@link ContextResolver}
*/
@Provider
public class JsonConfiguration implements ContextResolver<Jsonb> {
......
......@@ -5,6 +5,9 @@ import javax.json.bind.serializer.JsonbSerializer;
import javax.json.bind.serializer.SerializationContext;
import javax.json.stream.JsonGenerator;
/**
* A json serializer for simple value objects ({@link SimpleValueObject})
*/
public class JsonSimpleValueObjectSerializer implements JsonbSerializer<SimpleValueObject> {
@Override
......
......@@ -7,6 +7,10 @@ import javax.json.bind.annotation.JsonbProperty;
import javax.json.bind.annotation.JsonbTransient;
import javax.json.bind.config.PropertyVisibilityStrategy;
/**
* The private visibility strategy is used in {@link JsonConfiguration} for the visibility for json
* serialization.
*/
public class PrivateVisibilityStrategy implements PropertyVisibilityStrategy {
@Override
......@@ -17,7 +21,7 @@ public class PrivateVisibilityStrategy implements PropertyVisibilityStrategy {
@Override
public boolean isVisible(Method method) {
return Modifier.isPublic(method.getModifiers())
&& !method.isAnnotationPresent(JsonbTransient.class)
&& !method.isAnnotationPresent(JsonbTransient.class)
|| method.isAnnotationPresent(JsonbProperty.class);
}
}
package de.unikoblenz.fgbks.base.utils;
/**
* Generate a thread safe synchronized unique application scoped long id by calling the method
* {@link UniqueIdGenerator#getNextId()}
*/
public class UniqueIdGenerator {
private static volatile long id = 0;
private UniqueIdGenerator() {}
/**
* Return the next id. This method is synchronized.
*/
public static synchronized long getNextId() {
return id++;
}
......
......@@ -6,6 +6,9 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* A abstract value object contains a array of objects.
*/
public abstract class AbstractValueObject implements Serializable, ValueObject {
private transient Object[] values;
......@@ -45,8 +48,8 @@ public abstract class AbstractValueObject implements Serializable, ValueObject {
public String toString() {
return "["
+ Arrays.stream(getValues())
.map(o -> nonNull(o) ? o.toString() : "null")
.collect(Collectors.joining(", "))
.map(o -> nonNull(o) ? o.toString() : "null")
.collect(Collectors.joining(", "))
+ "]";
}
......
package de.unikoblenz.fgbks.base.value;
/**
* A simple value object, which contains a value of a given type V.
*/
public interface SimpleValueObject<V> extends ValueObject {
V getValue();
......
......@@ -2,7 +2,9 @@ package de.unikoblenz.fgbks.base.value;
import java.io.Serializable;
@SuppressWarnings("checkstyle:all")
/**
* A interface for a value object.
*/
public interface ValueObject extends Serializable {
String VALUE = "value";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment