A library with common Java types that are mostly immutable value objects.
- 0.9.x (or later) = Java 17
- 0.8.0 = Java 11 with new jakarta namespace
- 0.7.x = Java 11 before namespace change from 'javax' to 'jakarta'
- 0.6.9 (or previous) = Java 8
Base classes like utilities and general annotations.
Annotations that can be placed on plain objects but may be used by a user interface to render that object in some way.
- Label annotation
- Prompt annotation
- ShortLabel annotation
- TableColumn annotation
- TextField annotation
- Tooltip annotation
Provides Value Objects and utility classes for those immutable objects.
Base classes like utilities and general annotations.
Verifies that the file exists (Bean validation JSR 303).
@FileExists
private File myFile;
Verifies that it's a directory and not a file (Bean validation JSR 303).
@IsDirectory
private File myDir;
Marker interface for classes that provide a special representation for trace output.
public class MyClass implements TraceStringCapable {
@Override
public String toTraceString() {
return "A long and very detailed instance description for trace output";
}
}
The annotations may be used by UI elements to display an appropriate text for a type or a field. You can also configure a bundle and key for internationalization.
Use this annotation to assign a label to a class or an attribute.
@Label(value = "Birthday", bundle = "my/MyBundle", key = "birthday.label")
private Date birthday;
Use this annotation to assign a prompt (example value) to a class or an attribute.
@Prompt(value = "12-31-1993", bundle = "my/MyBundle", key = "birthday.prompt")
private Date birthday;
Use this annotation to assign an abbreviation to a class or an attribute.
@ShortLabel(value = "BD", bundle = "my/MyBundle", key = "birthday.short")
private Date birthday;
Use this annotation to assign preferred table column values to a field.
@TableColumn(pos = 3, width = 20, unit= FontSizeUnit.EM, getter = "isInternal")
private boolean permanentEmployee;
Use this annotation to express the annotated attribute should be rendered as a text field. User agents are expected to use this information as hint for the rendering process.
@TextField(width = 50)
private String lastName;
Use this annotation to assign a tooltip to a class or a field.
@Tooltip(value = "The person's birthday", bundle = "my/MyBundle", key = "birthday.tooltip")
private Date birthday;
You can use AnnotationAnalyzer to read the internationalized text from above annotations.
Read a single @Label
text:
AnnotationAnalyzer analyzer = new AnnotationAnalyzer();
Field field = MyClass.class.getDeclaredField("birthday");
FieldTextInfo labelInfoGermany = analyzer.createFieldInfo(field, Locale.GERMANY, Label.class);
System.out.println(labelInfoGermany.getText());
// Prints "Geburtstag"
FieldTextInfo labelInfoUs = analyzer.createFieldInfo(field, Locale.US, Label.class);
System.out.println(labelInfoUs.getText());
// Prints "Birthday"
Read all @Label
texts from a class:
AnnotationAnalyzer analyzer = new AnnotationAnalyzer();
List<FieldTextInfo> infos = analyzer.createFieldInfos(MyClass.class, Locale.US, Label.class);
for (final FieldTextInfo info : infos) {
// Text of the label or the name of the field if the text is null
System.out.println(info.getTextOrField());
}
Create a list of TableColumnInfo that combines @Label, @ShortLabel and @TableColumn annotations.
List<TableColumnInfo> columns = TableColumnInfo.create(MyClass.class, Locale.US);
for (TableColumnInfo column : columns) {
System.out.println(column.getText());
}
This allows easy creation of a table model for example for JavaFX:
TableView<MyClass> tableView = new TableView<>();
List<TableColumnInfo> tableCols = TableColumnInfo.create(MyClass.class, Locale.getDefault());
Collections.sort(tableCols);
for (TableColumnInfo column : tableCols) {
TableColumn<MyClass, String> tc = new TableColumn<>();
tc.setStyle("-fx-alignment: CENTER;");
Label label = new Label(column.getShortText());
label.setTooltip(new Tooltip(column.getTooltip()));
tc.setGraphic(label);
tc.setCellValueFactory(new PropertyValueFactory<MyClass, String>(column.getField().getName()));
tc.setPrefWidth(column.getWidth().getSize());
tableView.getColumns().add(tc);
}
Use this annotation to assign some example values to a class or an attribute.
@Examples({"John", "Jane"})
private String firstName;
Use this annotation to assign key/value mappings to a class or an attribute.
@Mappings({"1=One", "2=Two", "3=Three"})
private String code;
Provides Value Objects (immutable objects) that represents an object whose equality isn't based on identity. That means instances of this type are equal when they have the same value, not necessarily being the same object. Additionally some helper classes (like validators) are placed in this package.
Interfaces
- ValueObject - Tag interface for value objects.
- ValueObjectConverter - Converts a value object into it's base type and back.
- ValueObjectWithBaseType - Value object that may be expressed in a more general type with relaxed restrictions. Often basic Java types like String or numeric values (Long, Integer, ...) are used for this.
- ValueOfCapable - Classes that can convert a string into a type (They have a
valueOf(String)
method). - AsStringCapable - Classes that provides a string representation (They have a
asString()
method).
Base classes that allow an easy implementation of concrete classes.
- AbstractIntegerValueObject - A value object that is based on an integer.
- AbstractLongValueObject - A value object that is based on a long.
- AbstractStringValueObject - A value object that is based on a string.
- AbstractUuidValueObject - A value object that is based on a UUID.
- AbstractValueObjectConverter - Converts value objects. It combines a JAXB XmlAdapter, JPA AttributeConverter and ValueObjectConverter.
Predefined Value Objects
- CurrencyAmount - Combines a currency (like "USD" or "EUR") with a big decimal value (like "512 EUR"). There is also a CurrencyAmountConverter (JAX-B, JSON-B and JPA) and a CurrencyAmountValidator (
@CurrencyAmountStr
) available. - EmailAddress - Email address. There is also a EmailAddressConverter (JAX-B, JSON-B and JPA) and a EmailAddressValidator (
@EmailAddressStr
) available. - Password - A password with a length between 8 and 20 characters. There is also a PasswordConverter (JAX-B, JSON-B and JPA) and a PasswordValidator (
@PasswordStr
) available. - PasswordSha512 - A SHA-512 hashed password that is HEX encoded. There is also a PasswordSha512Converter (JAX-B, JSON-B and JPA) and a PasswordSha512Validator (
@PasswordSha512Str
) available. - UserName - User name with restricted character set and length. There is also a UserNameConverter (JAX-B, JSON-B and JPA) and a UserNameValidator (
@UserNameStr
) available. - Hour - Hour of a day like '23:59' (24 hours, sometimes called Military Time). There is also an HourConverter (JAX-B, JSON-B and JPA) and an HourStrValidator (
@HourStr
) available. - HourRange - Range of hours of a day like '00:00-24:00' (24 hours, sometimes called Military Time). There is also an HourRangeConverter (JAX-B, JSON-B and JPA) and an HourRangeStrValidator (
@HourRangeStr
) available. - HourRanges - Multiple range of hours of a day like '09:00-12:00+13:00-17:00'. There is also an HourRangesConverter (JAX-B, JSON-B and JPA) and an HourRangesStrValidator (
@HourRangesStr
) available. - DayOfTheWeek - The days of the week 'Mon'-'Sun'(from Monday to Sunday) plus 'PH' (Public Holiday). There is also an DayOfTheWeekConverter (JAX-B, JSON-B and JPA) and an DayOfTheWeekStrValidator (
@DayOfTheWeekStr
) available. - MultiDayOfTheWeek - Multiple days of the week like 'Mon/Tue/Wed-Fri/PH' (Monday AND Tuesday AND Wednesday TO Friday AND Public Holidays). There is also an MultiDayOfTheWeekConverter (JAX-B, JSON-B and JPA) and an MultiDayOfTheWeekStrValidator (
@MultiDayOfTheWeekStr
) available. - DayOpeningHours - Multiple range of hours of single a day like 'Mon 09:00-12:00+13:00-17:00'. There is also an DayOpeningHoursConverter (JAX-B, JSON-B and JPA) and an DayOpeningHoursStrValidator (
@DayOpeningHoursStr
) available. - WeeklyOpeningHours - weekly opening hours separated by a comma like 'Mon-Fri 09:00-12:00+13:00-17:00,Sat/Sun 09:-12:00'. There is also an WeeklyOpeningHoursConverter (JAX-B, JSON-B and JPA) and an WeeklyOpeningHoursStrValidator (
@WeeklyOpeningHoursStr
) available.
Validators
- DateValidator - Validates that a string is a date using the current locale (@DateStr).
- LocaleValidator - Validates that a string is a valid locale (@LocaleStr). There is also a LocaleConverter available.
- PropertiesContainValidator - Validates that a string is one out of a list of constants (@PropertiesContain("one", "two", "three")).
- TrimmedNotEmptyValidator - Validates that a string is not empty after it was trimmed @TrimmedNotEmpty
- UUIDValidator - Validates that a string is a valid UUID (@UUIDStr). There is also a UUIDConverter available.
Other
- KeyValue - Container for a key (String) and a value (Object).
This version has several incompatible changes because of moving it to Java 11.
- Removed JaxbMarshallable classes because of illegal reflective access
Snapshots can be found on the OSS Sonatype Snapshots Repository.
Add the following to your .m2/settings.xml to enable snapshots in your Maven build:
<repository>
<id>sonatype.oss.snapshots</id>
<name>Sonatype OSS Snapshot Repository</name>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>