package com.graphhopper.routing.util;

import com.graphhopper.storage.Graph;
import com.graphhopper.util.EdgeIterator;
import com.graphhopper.util.EdgeIteratorState;

public class EscapePrivateWeighting implements Weighting
{

	private static final double ESCAPE_WEIGHT = 1.1;
	public static final int KEY = 100;
	private Weighting innerWeighting;
	private FlagEncoder encoder;
	private Graph graph;
	private int start;
	private int end;

	public EscapePrivateWeighting( Graph graph, FlagEncoder encoder, Weighting weighting)
    {
	    super();
	    this.graph = graph;
	    this.encoder = encoder;
	    this.innerWeighting = weighting;
    }
	
	public void setFromTo(int from , int to) {
		start = from;
		end = to;
	}

	@Override
	public double getMinWeight( double distance )
	{
		return innerWeighting.getMinWeight(distance);
	}

	@Override
	public double calcWeight( EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId )
	{
		System.err.println(edgeState.getClass() + ":" + edgeState.toString());
		double calcWeight = innerWeighting.calcWeight(edgeState, reverse, prevOrNextEdgeId);
		if(encoder.getLong(edgeState.getFlags(), KEY)>0) {
			EdgeIteratorState edgeProps=null;
			System.err.println("EDGE"+ edgeState.getEdge()+":PREVNEXT"  + prevOrNextEdgeId);
			if(!isStartOrEnd(edgeState) && prevOrNextEdgeId>EdgeIterator.NO_EDGE) {
				edgeProps = graph.getEdgeProps(prevOrNextEdgeId, Integer.MIN_VALUE);
			}
			if(null==edgeProps || encoder.getLong(edgeProps.getFlags(), KEY)>0) {
				calcWeight *= ESCAPE_WEIGHT;
			}
			else {
				calcWeight = Double.POSITIVE_INFINITY;
			}
		}
		System.err.println("WEIGHT:" +calcWeight);
		return calcWeight;
	}

	private boolean isStartOrEnd( EdgeIteratorState edgeState )
    {
	    int baseNode = edgeState.getBaseNode();
		int adjNode = edgeState.getAdjNode();
		boolean startEnd = baseNode == start  || baseNode == end  || adjNode == start || adjNode == end;
		System.err.println("STARTEND:" + startEnd + ":" + edgeState.toString());
		return startEnd;
    }

}

@@ -942,81 +942,8 @@
 %0A%09%7B%0A
-%09%09System.err.println(edgeState.getClass() + %22:%22 + edgeState.toString());%0A
 %09%09do
@@ -1025,16 +1025,16 @@
 dgeId);%0A
+
 %09%09if(enc
@@ -1119,92 +1119,8 @@
 ll;%0A
-%09%09%09System.err.println(%22EDGE%22+ edgeState.getEdge()+%22:PREVNEXT%22  + prevOrNextEdgeId);%0A
 %09%09%09i
@@ -1445,53 +1445,8 @@
 %09%09%7D%0A
-%09%09System.err.println(%22WEIGHT:%22 +calcWeight);%0A
 %09%09re
@@ -1618,16 +1618,16 @@
 Node();%0A
+
 %09%09boolea
@@ -1721,83 +1721,8 @@
 nd;%0A
-%09%09System.err.println(%22STARTEND:%22 + startEnd + %22:%22 + edgeState.toString());%0A
 %09%09re

Remove debug syserrs