Skip to content

Commit

Permalink
Define template contract
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Aug 3, 2024
1 parent 258af03 commit 733906f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/ical4j/template/AbstractTemplate.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.ical4j.template;

import java.lang.reflect.InvocationTargetException;
import java.util.function.UnaryOperator;

/**
* Base class for templates with the added ability to construct new object instances.
* Base class for templates with support for a prototype instance. A prototype is an
* instance of the applicable object type used to construct a new instance or modify
* an existing instance prior to applying the template.
*
* @param <T>
* @param <T> the applicable object type
*/
public abstract class AbstractTemplate<T> implements UnaryOperator<T> {
public abstract class AbstractTemplate<T> implements Template<T> {

private final Class<? extends T> typeClass;

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/ical4j/template/Template.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ical4j.template;

import java.lang.reflect.InvocationTargetException;
import java.util.function.UnaryOperator;

/**
* A template encapsulates rules for creating and modifying complex iCalendar and
* vCard objects.
*
* @param <T> the applicable object type
*/
public interface Template<T> extends UnaryOperator<T> {

/**
* Apply the template to a new object instance. The use of this method requires
* that the applicable object type contains a default noargs constructor that
* can be used to create a new object instance.
* @return a new object instance resulting from applying the template
* @throws NoSuchMethodException if a noargs constructor doesn't exist on the applicable object type
* @throws InvocationTargetException an error resulting from invoking the noargs constructor
* @throws InstantiationException an error resulting from invoking the noargs constructor
* @throws IllegalAccessException an error resulting from invoking the noargs constructor
*/
T apply() throws NoSuchMethodException, InvocationTargetException, InstantiationException,
IllegalAccessException;
}

0 comments on commit 733906f

Please sign in to comment.