/** * Creates a stack (with a given name) based on a collection of document processors, which are added to the stack * in the iteration order of the collection. * * @param name the name of the stack * @param docprocs the document processors to call */ public CallStack(final String name, Collection<DocumentProcessor> docprocs, Statistics manager, Metric metric) { this(name, manager, metric); for (DocumentProcessor docproc : docprocs) { addLast(docproc); } }
/** * Adds an element just before the first occurence of some other element on * the stack. This can not be called during an iteration. * * @param before * the call to add this before. If this call is not present (the * same object instance), new processor is added as the last * element * @param call the call to add * @return this for convenience */ public CallStack addBefore(final Call before, final Call call) { final int insertPosition = elements.indexOf(before); if (insertPosition < 0) { addLast(call); } else { elements.add(insertPosition, call); } return this; }
/** * Adds multiple elements just after another given element on the stack. * This can not be called during an iteration. * * @param after * the call to add this before. If this call is not present, (the * same object instance), the new processor is added as the last * element * @param callStack * the calls to add * @return this for convenience */ public CallStack addAfter(final Call after, final CallStack callStack) { final int insertPosition = elements.indexOf(after); if (insertPosition < 0) { addLast(callStack); } else { elements.addAll(insertPosition + 1, callStack.elements); } return this; }
/** * Adds multiple elements just before the first occurence of some element on * the stack. This can not be called during an iteration. * * @param before * the call to add this before. If this call is not present (the * same object instance), the new processor is added as the last * element * @param callStack * the calls to add * @return this for convenience */ public CallStack addBefore(final Call before, final CallStack callStack) { final int insertPosition = elements.indexOf(before); if (insertPosition < 0) { addLast(callStack); } else { elements.addAll(insertPosition, callStack.elements); } return this; }
/** * Adds an element just after the first occurence of some other element on * the stack. This can not be called during an iteration. * * @param after * the call to add this before. If this call is not present, (the * same object instance), the new processor is added as the last * element * @param call * the call to add * @return this for convenience */ public CallStack addAfter(final Call after, final Call call) { final int insertPosition = elements.indexOf(after); if (insertPosition < 0) { addLast(call); } else { elements.add(insertPosition + 1, call); } return this; }
/** * Adds an element as the <i>last</i> element on this stack * * @return this for convenience */ public CallStack addLast(final DocumentProcessor processor) { return addLast(new Call(processor, name, statistics, metric)); }
private static CallStack convertToCallStack(Chain<DocumentProcessor> chain, Statistics statistics, Metric metric) { CallStack stack = new CallStack(chain.getId().stringValue(), statistics, metric); for (DocumentProcessor processor : chain.components()) { processor.getFieldMap().putAll(DocprocService.schemaMap.chainMap(chain.getId().stringValue(), processor.getId().stringValue())); stack.addLast(processor); } return stack; }