/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.api;

public abstract class MatchHandler {

    /**
     * This {@link MatchHandler} does nothing.
     */
    public final static MatchHandler NO_OP = new MatchHandler0() {
	@Override
	public void handleMatch(Object auxiliaryData) {
	}
    };

    /**
     * This {@link MatchHandler} prints on match to the standard output stream.
     */
    public final static MatchHandler SYS_OUT = new MatchHandler0() {
	@Override
	public void handleMatch(Object auxiliaryData) {
	    System.out.println("Match detected!");
	}
    };

    /**
     * Retrieve bound objects with getBoundObject(...) TODO doc method.
     *
     * @param bindings
     */
    public abstract void handleMatch(Binding[] bindings, Object auxiliaryData);

    /**
     * Retrieves the object which was stored in the monitor bindings. The object may be <code>null</code> if selected
     * object was already garbage collected in the monitored application.
     *
     * @param param
     *            selects the object from the bindings
     * @param bindings
     *            current bindings when the match was completed
     * @return the object which was bound to the given parameter. <code>null</code>, if the object was already garbage
     *         collected.
     */
    @SuppressWarnings("unchecked")
    protected <P> P getBoundObject(Parameter<P> param, Binding[] bindings) {
	return (P) bindings[param.getIndex()];
    }
}

@@ -391,16 +391,67 @@
 j.api;%0A%0A
+import java.util.concurrent.atomic.AtomicInteger;%0A%0A
 public a
@@ -953,32 +953,503 @@
 !%22);%0A%09%7D%0A    %7D;%0A%0A
+    /**%0A     * This %7B@link MatchHandler%7D prints on match to the standard output stream.%0A     */%0A    public final static MatchCounter MATCH_COUNTER = new MatchCounter() %7B%0A%0A    %7D;%0A%0A    public static class MatchCounter extends MatchHandler0 %7B%0A%0A%09public final AtomicInteger counter = new AtomicInteger();%0A%0A%09@Override%0A%09public void handleMatch(Object auxiliaryData) %7B%0A%09    counter.incrementAndGet();%0A%09%7D%0A%0A%09public final AtomicInteger getCounter() %7B%0A%09    return counter;%0A%09%7D%0A    %7D%0A%0A
     /**%0A     * R

Add match-counting MatchHandler