<commit_before>package uk.ac.st_andrews.cs.host.mk74.locy;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;

//wrapper for LocyNavigator
//acts as LocationManager
public class LocyManager{
	private static final String GPS_PROVIDER = "gps";
	private static final int REQUEST_TIME = 1000;
	
	private LocyNavigator locyNavigator;
	private List<LocationListener> locationListeners;
	private Thread locyNavigatorThread;
	
	public LocyManager(Context context) {
		locationListeners = new CopyOnWriteArrayList<LocationListener>(); //Concurrency issues solved
		locyNavigator = new LocyNavigator(context);
		locyNavigatorThread = new Thread(new Runnable() {
			
			//every second, goes through listeners and broadcast location
			public void run(){
				try {
					System.out.println("LocyNavigatorThread has started");
					while(true){
						if(locyNavigator.getLocation()!=null){
							for(LocationListener listener: locationListeners){
								listener.onLocationChanged(locyNavigator.getLocation());
							}
						}
						Thread.sleep(REQUEST_TIME);
					}
				} catch (InterruptedException e) {
					System.out.println("LocyNavigatorThread has stopped");
				}
	        }
		});
	}
	
	//checks whether provider is enabled
	public boolean isProviderEnabled(String provider){
		if(provider.equals(GPS_PROVIDER))
			return true;
		else
			return false;
	}
	
	//register listener for location updates
	public void requestLocationUpdates(String provider, long minTime, 
										float minDistance, LocationListener listener){
		if(provider == GPS_PROVIDER){
			locationListeners.add(listener);
			if(locationListeners.size() == 1){
				locyNavigator.start();
				locyNavigatorThread.start();
			}
		}
	}
	
	//remove listener for location updates
	public void removeUpdates(LocationListener listener){
		locationListeners.remove(listener);
		if(locationListeners.size() == 0){
			locyNavigatorThread.interrupt();
			locyNavigator.stop();
		}
	}
	
	//returns last known location for given provider
	public Location getLastKnownLocation(String provider){
		if(provider.equals(GPS_PROVIDER)){
			return locyNavigator.getLocation();
		}else
			return null;

	}
	
	//returns all available providers<commit_msg>small bug if many apps is connected<commit_after>package uk.ac.st_andrews.cs.host.mk74.locy;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;

//wrapper for LocyNavigator
//acts as LocationManager
public class LocyManager{
	private static final String GPS_PROVIDER = "gps";
	private static final int REQUEST_TIME = 1000;
	
	private LocyNavigator locyNavigator;
	private List<LocationListener> locationListeners;
	private Thread locyNavigatorThread;
	
	public LocyManager(Context context) {
		locationListeners = new CopyOnWriteArrayList<LocationListener>(); //Concurrency issues solved
		locyNavigator = new LocyNavigator(context);
		locyNavigatorThread = new Thread(new Runnable() {
			
			//every second, goes through listeners and broadcast location
			public void run(){
				try {
					System.out.println("LocyNavigatorThread has started");
					while(true){
						if(locyNavigator.getLocation()!=null){
							for(LocationListener listener: locationListeners){
								listener.onLocationChanged(locyNavigator.getLocation());
							}
						}
						Thread.sleep(REQUEST_TIME);
					}
				} catch (InterruptedException e) {
					System.out.println("LocyNavigatorThread has stopped");
				}
	        }
		});
	}
	
	//checks whether provider is enabled
	public boolean isProviderEnabled(String provider){
		if(provider.equals(GPS_PROVIDER))
			return true;
		else
			return false;
	}
	
	//register listener for location updates
	public void requestLocationUpdates(String provider, long minTime, 
										float minDistance, LocationListener listener){
		if(provider == GPS_PROVIDER){
			locationListeners.add(listener);
			if(locationListeners.size() == 1){
				locyNavigator.start();
				if ( locyNavigatorThread.getState() == Thread.State.NEW )
					locyNavigatorThread.start();
			}
		}
	}
	
	//remove listener for location updates
	public void removeUpdates(LocationListener listener){
		locationListeners.remove(listener);
		if(locationListeners.size() == 0){
			locyNavigatorThread.interrupt();
			locyNavigator.stop();
		}
	}
	
	//returns last known location for given provider
	public Location getLastKnownLocation(String provider){
		if(provider.equals(GPS_PROVIDER)){
			return locyNavigator.getLocation();
		}else
			return null;

	}
	
	//returns all available providers
{'fraction_non_alphanumeric': 0.09378206443669197, 'fraction_numerical': 0.0032833983172583622, 'mean_word_length': 4.326775956284153, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010312', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1366, 'n_words': 332}