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

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import prm4j.api.Parameter;
import prm4j.indexing.map.MinimalMapEntry;

public class DefaultLowLevelBinding extends WeakReference<Object> implements LowLevelBinding,
	MinimalMapEntry<Object, DefaultLowLevelBinding> {

    private long timestamp;
    private boolean disabled;
    private final int hashCode;
    private final Parameter<?> parameter;
    private DefaultLowLevelBinding next;
    private List<WeakReference<Node>> nodeRefs;

    public DefaultLowLevelBinding(Object boundObject, Parameter<?> parameter, int hashCode, ReferenceQueue<Object> q) {
	super(boundObject, q);
	this.hashCode = hashCode;
	this.parameter = parameter;
	nodeRefs = new ArrayList<WeakReference<Node>>();
    }

    @Override
    public Parameter<?> getParameter() {
	return parameter;
    }

    @Override
    public int getParameterIndex() {
	return parameter.getIndex();
    }

    @Override
    public int getHashCode() {
	return hashCode;
    }

    /**
     * {@inheritDoc}
     *
     * The key used in the {@link BindingStore} is the object.
     */
    @Override
    public Object getKey() {
	return get();
    }

    @Override
    public DefaultLowLevelBinding next() {
	return next;
    }

    @Override
    public void setNext(DefaultLowLevelBinding next) {
	this.next = next;
    }

    @Override
    public void registerNode(WeakReference<Node> nodeReference) {
	nodeRefs.add(nodeReference);
    }

    @Override
    public void release() {
	for (WeakReference<Node> ref : nodeRefs) {
	    final Node node = ref.get();
	    if (node != null) {
		node.remove(this);
	    }
	}
	nodeRefs = null;
    }

    @Override
    public boolean isDisabled() {
	return disabled;
    }

    @Override
    public void setDisabled(boolean disabled) {
	this.disabled = disabled;

    }

    @Override
    public long getTimestamp() {
	return timestamp;
    }

    @Override
    public void setTimestamp(long timestamp) {
	this.timestamp = timestamp;
    }

}

@@ -2469,10 +2469,102 @@
 %0A    %7D%0A%0A
+    @Override%0A    public String toString() %7B%0A        return parameter + %22=%22 + get();%0A    %7D%0A%0A
 %7D%0A

Add toString in DefaultLowLevelBinding