/*
 * 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.indexing;

import prm4j.api.Event;
import prm4j.api.ParametricMonitor;
import prm4j.indexing.realtime.LowLevelBinding;

/**
 * Abstract base class for a concrete monitor instance, representing the internal state of a {@link ParametricMonitor}
 * for one single concrete variable binding.
 */
public abstract class BaseMonitor {

    // low level access
    private LowLevelBinding[] bindings;
    // low level access
    private long creationTime;

    /**
     * Creates a low level deep copy of this monitor.
     *
     * @param bindings
     * @return
     */
    public final BaseMonitor copy(LowLevelBinding[] bindings) {
	BaseMonitor copy = copy();
	copy.setBindings(bindings);
	copy.setCreationTime(creationTime);
	return copy;
    }

    public final BaseMonitor copy(LowLevelBinding[] bindings, long timestamp) {
	BaseMonitor copy = copy();
	copy.setBindings(bindings);
	copy.setCreationTime(timestamp);
	return copy;
    }

    private final void setBindings(LowLevelBinding[] bindings) {
	this.bindings = bindings;
    }

    public final LowLevelBinding[] getLowLevelBindings() {
	return bindings;
    }

    protected final prm4j.api.Binding[] getBindings() {
	// upcast
	return bindings;
    }

    public final long getCreationTime() {
	return creationTime;
    }

    final void setCreationTime(long creationTime) {
	this.creationTime = creationTime;
    }

    /**
     * Updates the base monitors internal state by consuming an event. After processing the event, the monitor is either
     * alive or dead. A dead monitor will no longer process events.
     *
     * @return <code>true</code> if a the monitor is still alive
     */
    public abstract boolean processEvent(Event event);

    /**
     * The monitor decides if am accepting state is reachable based on its current internal state. This allows efficient
     * parametric monitors to remove the monitor instance in case it should be impossible to reach any accepting state.
     *
     * @return <code>true</code> if an accepting state is still reachable
     */
    public abstract boolean isAcceptingStateReachable();

    /**
     * Creates a deep copy of this base monitor.
     */
    public abstract BaseMonitor copy();

}

@@ -714,16 +714,101 @@
 itor %7B%0A%0A
+    private final static LowLevelBinding%5B%5D EMPTY_BINDINGS = new LowLevelBinding%5B0%5D;%0A%0A
     // l
@@ -904,29 +904,105 @@
 te long 
-creationTime;
+timestamp;%0A%0A    public BaseMonitor() %7B%0A%09bindings = EMPTY_BINDINGS;%0A%09timestamp = 0L;%0A    %7D
 %0A%0A    /*
@@ -1208,36 +1208,35 @@
 ;%0A%09copy.
-setB
+b
 indings
-(
+ = 
 bindings
 );%0A%09copy
@@ -1223,33 +1223,32 @@
 s = bindings
-)
 ;%0A%09copy.
 setCreationT
@@ -1239,37 +1239,29 @@
 opy.
-setCreationTime(creationTime)
+timestamp = timestamp
 ;%0A%09r
@@ -1397,28 +1397,27 @@
 opy.
-setB
+b
 indings
-(
+ = 
 bindings
 );%0A%09
@@ -1412,25 +1412,24 @@
 bindings
-)
 ;%0A%09copy.
 setCreat
@@ -1420,32 +1420,28 @@
 ;%0A%09copy.
-setCreationTime(
+timestamp = 
 timestam
@@ -1441,17 +1441,16 @@
 imestamp
-)
 ;%0A%09retur
@@ -1468,107 +1468,8 @@
  %7D%0A%0A
-    private final void setBindings(LowLevelBinding%5B%5D bindings) %7B%0A%09this.bindings = bindings;%0A    %7D%0A%0A
     
@@ -1694,114 +1694,17 @@
 urn 
-creationTime;%0A    %7D%0A%0A    final void setCreationTime(long creationTime) %7B%0A%09this.creationTime = creationTime
+timestamp
 ;%0A  

Improve BaseMonitor