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