MCPcopy Create free account
hub / github.com/PCGen/pcgen / ContextProcessor

Class ContextProcessor

code/src/java/pcgen/cdom/processor/ContextProcessor.java:38–155  ·  view source on GitHub ↗

A ContextProcessor is a Processor that has the ability to wrap another Processor in order to conditionally apply the underlying Processor only in a given context. @param The class of object this ContextProcessor acts upon. @param The class of objects which provide the

Source from the content-addressed store, hash-verified

36 * ContextProcessor acts
37 */
38public class ContextProcessor<T, R extends PrereqObject> implements Processor<T>
39{
40 /**
41 * The underlying Processor that this ContextModifer will apply when the
42 * given context is matched.
43 */
44 private final Processor<T> processor;
45
46 /**
47 * A Reference which contains the objects in the context in which the
48 * underlying Processor should be applied.
49 */
50 private final CDOMReference<R> contextItems;
51
52 /**
53 * Constructs a new ContextProcessor that will conditionally apply the given
54 * Processor only when objects in the given CDOMReference are provided as the
55 * context of the modification.
56 *
57 * @param mod
58 * The underlying Processor that this ContextModifer will apply
59 * when the given context is matched.
60 * @param contextRef
61 * The CDOMReference which contains the objects for which the
62 * underlying Processor should be applied.
63 * @throws IllegalArgumentException
64 * if the given Processor or the given CDOMReference is null
65 */
66 public ContextProcessor(Processor<T> mod, CDOMReference<R> contextRef)
67 {
68 Objects.requireNonNull(mod, "Processor in ContextProcessor cannot be null");
69 Objects.requireNonNull(contextRef, "Context in ContextProcessor cannot be null");
70 processor = mod;
71 contextItems = contextRef;
72 }
73
74 /**
75 * Conditionally applies the underlying Processor to the given input. Will
76 * only be applied if the object given as the context object is contained
77 * within the CDOMReference provided during construction of this
78 * ContextProcessor.
79 *
80 * Note this method may return the object passed in as the input object. The
81 * behavior of ContextProcessor will depend on the behavior of the underlying
82 * Processor. Therefore, if the input object is mutable, the caller of the
83 * applyProcessor method should be aware of that behavior, and should treat
84 * the returned object appropriately.
85 *
86 * @param obj
87 * The input object this ContextProcessor will act upon
88 * @param context
89 * The context of this ContextProcessor, to establish whether this
90 * Processor should act upon the input object
91 * @return The modified object, of the same class as the input object.
92 */
93 @Override
94 public T applyProcessor(T obj, Object context)
95 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected