|
3 | 3 | import java.io.IOException;
|
4 | 4 | import java.nio.file.Path;
|
5 | 5 |
|
| 6 | +import gov.hhs.aspr.ms.taskit.core.translation.TranslationSpec; |
| 7 | + |
| 8 | +/** |
| 9 | + * Interface for a {@link TaskitEngine} that applies to TaskitEngine and any |
| 10 | + * derivatives thereof |
| 11 | + */ |
6 | 12 | public interface ITaskitEngine {
|
7 | 13 |
|
| 14 | + /** |
| 15 | + * @return the {@link TaskitEngine} associated with the given TaskitEngine. |
| 16 | + * <p> |
| 17 | + * Note that for {@link TaskitEngine} this method returns itself. |
| 18 | + */ |
8 | 19 | public TaskitEngine getTaskitEngine();
|
9 | 20 |
|
| 21 | + /** |
| 22 | + * @return the {@link TaskitEngineId} associated with the TaskitEngine |
| 23 | + */ |
10 | 24 | public TaskitEngineId getTaskitEngineId();
|
11 | 25 |
|
| 26 | + /** |
| 27 | + * Writes the object to the file referenced by the Path |
| 28 | + * |
| 29 | + * @param <O> the type of the object to write |
| 30 | + * @param path the path of the file to write to |
| 31 | + * @param object the object to write |
| 32 | + * @throws IOException if there is an issue writing the file |
| 33 | + */ |
12 | 34 | public <O> void write(Path path, O object) throws IOException;
|
13 | 35 |
|
| 36 | + /** |
| 37 | + * Translates the object and then writes the translated object to the file |
| 38 | + * reference by the Path |
| 39 | + * |
| 40 | + * @param <O> the type of the object to write |
| 41 | + * @param path the path of the file to write to |
| 42 | + * @param object the object to write |
| 43 | + * @throws IOException if there is an issue writing the file |
| 44 | + */ |
14 | 45 | public <O> void translateAndWrite(Path path, O object) throws IOException;
|
15 | 46 |
|
16 |
| - public <OC, O extends OC> void translateAndWrite(Path path, O object, Class<OC> classRef) |
| 47 | + /** |
| 48 | + * Translates the object as the provided class and then writes the translated |
| 49 | + * object to the file referenced by the Path |
| 50 | + * <p> |
| 51 | + * The type params ensure that the object can be written as the provided class |
| 52 | + * |
| 53 | + * @param <C> the type to translate the object as |
| 54 | + * @param <O> the type of the object |
| 55 | + * @param path the path of the file to write to |
| 56 | + * @param object the object to write |
| 57 | + * @param classRef the class to translate the object as |
| 58 | + * @throws IOException if there is an issue writing the file |
| 59 | + */ |
| 60 | + public <C, O extends C> void translateAndWrite(Path path, O object, Class<C> classRef) |
17 | 61 | throws IOException;
|
18 | 62 |
|
| 63 | + /** |
| 64 | + * Reads the given path into the provided class type |
| 65 | + * |
| 66 | + * @param <I> the input type |
| 67 | + * @param path the path of the file to read |
| 68 | + * @param classRef the class to read the file as |
| 69 | + * @return the resulting object from reading the file as the class |
| 70 | + * @throws IOException if there is an issue reading the file |
| 71 | + */ |
19 | 72 | public <I> I read(Path path, Class<I> classRef) throws IOException;
|
20 | 73 |
|
| 74 | + /** |
| 75 | + * Reads the given path into the provided class type and then translates it to |
| 76 | + * the corresponding type associated with the input type |
| 77 | + * |
| 78 | + * @param <T> the translated type |
| 79 | + * @param <I> the input type |
| 80 | + * @param path the path of the file to read |
| 81 | + * @param classRef the class to read the file as |
| 82 | + * @return the resulting translated read in object |
| 83 | + * @throws IOException if there is an issue reading the file |
| 84 | + */ |
21 | 85 | public <T, I> T readAndTranslate(Path path, Class<I> classRef) throws IOException;
|
22 | 86 |
|
| 87 | + /** |
| 88 | + * Given an object, uses the class of the object to obtain the translationSpec |
| 89 | + * and then calls {@link TranslationSpec#translate(Object)} to translate the |
| 90 | + * object |
| 91 | + * <p> |
| 92 | + * this conversion method will be used approx ~90% of the time |
| 93 | + * </p> |
| 94 | + * |
| 95 | + * @param <T> the translated type |
| 96 | + * @param object the object to translate |
| 97 | + * @return the translated object |
| 98 | + */ |
23 | 99 | public <T> T translateObject(Object object);
|
24 | 100 |
|
| 101 | + /** |
| 102 | + * Given an object, uses the given classRef to obtain the |
| 103 | + * translationSpec and then calls {@link TranslationSpec#translate(Object)} |
| 104 | + * <p> |
| 105 | + * This method call is safe in the sense that the type parameters ensure that |
| 106 | + * the passed in object is actually a child of the passed in classRef |
| 107 | + * </p> |
| 108 | + * <p> |
| 109 | + * this conversion method will be used approx ~7% of the time |
| 110 | + * </p> |
| 111 | + * |
| 112 | + * @param <T> the translated type |
| 113 | + * @param <O> the type of the object |
| 114 | + * @param <C> the type to translate the object as |
| 115 | + * @param object the object to translate |
| 116 | + * @param classRef the classRef of the type to translate the object as |
| 117 | + * @return the translated object |
| 118 | + */ |
25 | 119 | public <T, O extends C, C> T translateObjectAsClassSafe(O object, Class<C> classRef);
|
26 | 120 |
|
| 121 | + /** |
| 122 | + * Given an object, uses the given classRef to obtain the |
| 123 | + * translationSpec and then calls {@link TranslationSpec#translate(Object)} |
| 124 | + * <p> |
| 125 | + * There is no type safety with this method unlike the |
| 126 | + * {@link ITaskitEngine#translateObjectAsClassSafe(Object, Class)} method. |
| 127 | + * Therefore it is on the caller of this method to ensure that the given object |
| 128 | + * can be translated using the given classRef. |
| 129 | + * <p> |
| 130 | + * A conventional use case for this would be when you want to wrap an object |
| 131 | + * into another object type where there is no correlation between the wrapping |
| 132 | + * object and the object being wrapped. |
| 133 | + * </p> |
| 134 | + * <p> |
| 135 | + * this conversion method will be used approx ~3% of the time |
| 136 | + * </p> |
| 137 | + * |
| 138 | + * @param <T> the corresponding type |
| 139 | + * @param <O> the type of the object |
| 140 | + * @param <C> the type to translate the object as |
| 141 | + * @param object the object to translate |
| 142 | + * @param classRef the classRef of the type to translate the object as |
| 143 | + * @return the translated object |
| 144 | + */ |
27 | 145 | public <T, O, C> T translateObjectAsClassUnsafe(O object, Class<C> classRef);
|
28 | 146 | }
|
0 commit comments