Coverage Report - org.mule.example.gpswalker.CityStroller
 
Classes in this File Line Coverage Branch Coverage Complexity
CityStroller
0%
0/18
0%
0/2
1.333
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.example.gpswalker;
 8  
 
 9  
 import org.mule.api.annotations.Schedule;
 10  
 
 11  
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
 12  
 
 13  
 /**
 14  
  * Generates a random walk around a city
 15  
  */
 16  0
 public class CityStroller
 17  
 {
 18  
 
 19  0
     public static final GpsCoord SAN_FRANCISCO = new GpsCoord(37.789167f, -122.419281f);
 20  0
     public static final GpsCoord LONDON = new GpsCoord(37.788423f, -122.39823f);
 21  0
     public static final GpsCoord VALLETTA = new GpsCoord(35.898504f, 14.514313f);
 22  
 
 23  
 
 24  0
     private volatile GpsCoord currentCoord = SAN_FRANCISCO;
 25  0
     private AtomicBoolean firstTime = new AtomicBoolean(true);
 26  
 
 27  
     //could use a better algorithm here or real test data for better results
 28  
     public GpsCoord generateNextCoord()
 29  
     {
 30  0
         if (firstTime.get())
 31  
         {
 32  0
             firstTime.set(false);
 33  
         }
 34  
         else
 35  
         {
 36  0
             double dist = Math.random() * 0.002;
 37  0
             double angle = Math.random() * Math.PI;
 38  
 
 39  
 
 40  0
             float lat = currentCoord.getLatitude() + (float) (dist * Math.sin(angle));
 41  0
             float lng = currentCoord.getLongitude() + (float) (dist * Math.cos(angle));
 42  
 
 43  0
             currentCoord = new GpsCoord(lat, lng);
 44  
         }
 45  0
         return currentCoord;
 46  
     }
 47  
 
 48  
     public GpsCoord getCurrentCoord()
 49  
     {
 50  0
         return currentCoord;
 51  
     }
 52  
 
 53  
     public void setCurrentCoord(GpsCoord currentCoord)
 54  
     {
 55  0
         this.currentCoord = currentCoord;
 56  0
         firstTime.set(false);
 57  0
     }
 58  
 }