public void mergeOrOverwriteTurnInfo ( int fromEdge , int viaNode , int toEdge , long turnFlags , boolean merge ) { int newEntryIndex = turnCostsCount ; ensureTurnCostIndex ( newEntryIndex ) ; boolean oldEntryFound = false ; long newFlags = turnFlags ; int next = NO_TURN_ENTRY ; // determine if we already have a cost entry for this node int previousEntryIndex = nodeAccess . getAdditionalNodeField ( viaNode ) ; if ( previousEntryIndex == NO_TURN_ENTRY ) { // set cost-pointer to this new cost entry nodeAccess . setAdditionalNodeField ( viaNode , newEntryIndex ) ; } else { int i = 0 ; next = turnCosts . getInt ( ( long ) previousEntryIndex * turnCostsEntryBytes + TC_NEXT ) ; long existingFlags = 0 ; while ( true ) { long costsIdx = ( long ) previousEntryIndex * turnCostsEntryBytes ; if ( fromEdge == turnCosts . getInt ( costsIdx + TC_FROM ) && toEdge == turnCosts . getInt ( costsIdx + TC_TO ) ) { // there is already an entry for this turn oldEntryFound = true ; existingFlags = turnCosts . getInt ( costsIdx + TC_FLAGS ) ; break ; } else if ( next == NO_TURN_ENTRY ) { break ; } previousEntryIndex = next ; // search for the last added cost entry if ( i ++ > 1000 ) { throw new IllegalStateException ( "Something unexpected happened. A node probably will not have 1000+ relations." ) ; } // get index of next turn cost entry next = turnCosts . getInt ( ( long ) next * turnCostsEntryBytes + TC_NEXT ) ; } if ( ! oldEntryFound ) { // set next-pointer to this new cost entry turnCosts . setInt ( ( long ) previousEntryIndex * turnCostsEntryBytes + TC_NEXT , newEntryIndex ) ; } else if ( merge ) { newFlags = existingFlags | newFlags ; } else { // overwrite! } } long costsBase ; // where to (over)write if ( ! oldEntryFound ) { costsBase = ( long ) newEntryIndex * turnCostsEntryBytes ; turnCostsCount ++ ; } else { costsBase = ( long ) previousEntryIndex * turnCostsEntryBytes ; } turnCosts . setInt ( costsBase + TC_FROM , fromEdge ) ; turnCosts . setInt ( costsBase + TC_TO , toEdge ) ; turnCosts . setInt ( costsBase + TC_FLAGS , ( int ) newFlags ) ; turnCosts . setInt ( costsBase + TC_NEXT , next ) ; }
Add a new turn cost entry or clear an existing . See tests for usage examples .