/** * Adds a map context to the chain. This means that the transformation associated to the passed * context will be applied after all the currently queued transformations. An exception will be * thrown if the chain already contains an object of the same class as <code>mapCtx</code>. This * is because we don't want to compose the same transformation twice. This method adds a copy of * <code>mapCtx</code> to the chain. This is because we want to exclude the possibility that the * context's state can be modified after the lookup table is built. This method triggers a * re-build of the lookup table. * * @param mapCtx The context to add. Mustn't be <code>null</code>. * @throws IllegalArgumentException If the context is already defined. */ public void add(CodomainMapContext mapCtx) { if (mapCtx == null) { throw new NullPointerException("No context."); } if (chain.contains(mapCtx)) { throw new IllegalArgumentException("Context already defined."); } mapCtx = mapCtx.copy(); // Get memento and discard original object. mapCtx.setCodomain(intervalStart, intervalEnd); mapCtx.buildContext(); chain.add(mapCtx); buildLUT(); }
/** * Sets the codomain interval. This triggers an update of all map contexts in the chain and a * re-build of the lookup table. The interval defined by <code>start</code> and <code>end</code> * must be a sub-interval of <code>[{@link QuantumStrategy#MIN}, {@link QuantumStrategy#MAX}] * </code>. * * @param start The lower bound of the codomain interval. * @param end The upper bound of the codomain interval. */ public void setInterval(int start, int end) { verifyInterval(start, end); intervalStart = start; intervalEnd = end; CodomainMapContext ctx; Iterator i = chain.iterator(); while (i.hasNext()) { ctx = (CodomainMapContext) i.next(); ctx.setCodomain(start, end); ctx.buildContext(); } buildLUT(); }
/** * Updates a map context in the chain. An exception will be thrown if the chain doesn't contain an * object of the same class as <code>mapCtx</code>. This method replaces the old context with a * copy of <code>mapCtx</code>. This is because we want to exclude the possibility that the * context's state can be modified after the lookup table is built. This method triggers a * re-build of the lookup table. * * @param mapCtx The context to add. Mustn't be <code>null</code> and already contained in the * chain. * @throws IllegalArgumentException If the specifed context doesn't exist. */ public void update(CodomainMapContext mapCtx) { if (mapCtx == null) { throw new NullPointerException("No context."); } int i = chain.indexOf(mapCtx); // Recall equals() is overridden. if (i == -1) { throw new IllegalArgumentException("No such a context."); } mapCtx = mapCtx.copy(); // Get memento and discard original object. mapCtx.setCodomain(intervalStart, intervalEnd); mapCtx.buildContext(); chain.set(i, mapCtx); buildLUT(); }