<commit_before>/*
 * Copyright (c) 2012 <NAME>, <NAME>
 * 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:
 * <NAME> - initial API and implementation
 */
package prm4j.indexing;

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

/**
 * 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 {

    private final static LowLevelBinding[] EMPTY_BINDINGS = new LowLevelBinding[0];

    private MetaNode metaNode;
    // low level access
    private LowLevelBinding[] bindings;
    // low level access
    private long timestamp;

    public BaseMonitor() {
	bindings = EMPTY_BINDINGS;
	timestamp = 0L;
    }

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

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

    /**
     * Returns a compressed representation of low level bindings
     *
     * @return
     */
    public final LowLevelBinding[] getLowLevelBindings() {
	return bindings;
    }

    /**
     * Returns a uncompressed representation of high-level bindings.
     *
     * @return
     */
    protected final prm4j.api.Binding[] getBindings() {
	if (metaNode == null) {
	    // upcast
	    return bindings;
	}
	// upcast
	return metaNode.uncompressBindings(bindings);
    }

    /**
     * Ends the life-span of this monitor. A terminated monitor can be removed from all data structures it is referenced
     * by.
     */
    public final void terminate() {
	bindings = null;
    }

    /**
     * Returns <code>true</code>, if the life of this monitor is over.
     *
     * @return <code>true</code> if terminated
     */
    public final boolean isTerminated() {
	return bindings == null;
    }

    public final long getCreationTime() {
	return timestamp;
    }

    /**
     * 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();

    public MetaNode getMetaNode() {
	return metaNode;
    }

    public void setMetaNode(MetaNode metaNode) {
	this.metaNode = metaNode;
    }

}<commit_msg>Add methods to retrieve count of created and updated base monitors<commit_after>/*
 * Copyright (c) 2012 <NAME>, <NAME>
 * 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:
 * <NAME> - initial API and implementation
 */
package prm4j.indexing;

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

/**
 * 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 {

    private final static LowLevelBinding[] EMPTY_BINDINGS = new LowLevelBinding[0];

    private static long createdMonitorsCount = 0L;
    private static long updatedMonitorsCount = 0L;

    private MetaNode metaNode;
    // low level access
    private LowLevelBinding[] bindings;
    // low level access
    private long timestamp;

    public BaseMonitor() {
	bindings = EMPTY_BINDINGS;
	timestamp = 0L;
    }

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

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

    /**
     * Returns a compressed representation of low level bindings
     *
     * @return
     */
    public final LowLevelBinding[] getLowLevelBindings() {
	return bindings;
    }

    /**
     * Returns a uncompressed representation of high-level bindings.
     *
     * @return
     */
    protected final prm4j.api.Binding[] getBindings() {
	if (metaNode == null) {
	    // upcast
	    return bindings;
	}
	// upcast
	return metaNode.uncompressBindings(bindings);
    }

    /**
     * Ends the life-span of this monitor. A terminated monitor can be removed from all data structures it is referenced
     * by.
     */
    public final void terminate() {
	bindings = null;
    }

    /**
     * Returns <code>true</code>, if the life of this monitor is over.
     *
     * @return <code>true</code> if terminated
     */
    public final boolean isTerminated() {
	return bindings == null;
    }

    public final long getCreationTime() {
	return timestamp;
    }

    /**
     * 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();

    public MetaNode getMetaNode() {
	return metaNode;
    }

    public void setMetaNode(MetaNode metaNode) {
	this.metaNode = metaNode;
    }

    /**
     * DIAGNOSTIC
     *
     * @return the number of created monitors
     */
    public static long getCreatedMonitorsCount() {
	return createdMonitorsCount;
    }

    /**
     * DIAGNOSTIC
     *
     * @return the number of updated monitors
     */
    public static long getUpdateddMonitorsCount() {
	return updatedMonitorsCount;
    }

    /**
     * Resets internal created monitors and updated monitors counter.
     */
    public static void reset() {
	createdMonitorsCount = 0L;
	updatedMonitorsCount = 0L;
    }

}
{'fraction_non_alphanumeric': 0.0844062947067239, 'fraction_numerical': 0.0046820132657042525, 'mean_word_length': 2.8936708860759492, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323803', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2086, 'n_words': 766}