Skip to content

Commit

Permalink
Added factory to create template from concept
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jan 5, 2024
1 parent afe9059 commit dbd7aa8
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/org/ical4j/template/TemplateFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.ical4j.template;

import net.fortuna.ical4j.extensions.concept.ActionType;
import net.fortuna.ical4j.extensions.concept.EventType;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.component.VToDo;
import net.fortuna.ical4j.model.property.Concept;
import org.ical4j.template.groupware.Action;
import org.ical4j.template.groupware.Meeting;

import java.util.function.UnaryOperator;

public class TemplateFactory {

@SuppressWarnings("unchecked")
public <T> UnaryOperator<T> newInstance(Concept concept) {
if (EventType.MEETING.equals(concept)) {
return (UnaryOperator<T>) new Meeting();
} else if (ActionType.ACTION.equals(concept)) {
return (UnaryOperator<T>) new Action();
// } else if (ActionType.AGENDA.equals(concept)) {
// return (UnaryOperator<T>) new Agenda();
}
throw new IllegalArgumentException("Unknown concept");
}

@SuppressWarnings("unchecked")
public <T> UnaryOperator<T> newInstance(Concept concept, T prototype) {
if (EventType.MEETING.equals(concept)) {
return (UnaryOperator<T>) new Meeting((VEvent) prototype);
} else if (ActionType.ACTION.equals(concept)) {
return (UnaryOperator<T>) new Action((VToDo) prototype);
// } else if (ActionType.AGENDA.equals(concept)) {
// return (UnaryOperator<T>) new Agenda();
}
throw new IllegalArgumentException("Unknown concept");
}
}

0 comments on commit dbd7aa8

Please sign in to comment.