<commit_before>package com.palsulich.nyubustracker.models;

import android.util.Log;

import com.google.android.gms.maps.model.PolylineOptions;
import com.palsulich.nyubustracker.helpers.BusManager;
import com.palsulich.nyubustracker.helpers.FileGrabber;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class Route {
    String longName = "";
    String routeID = "";
    ArrayList<Stop> stops = null;
    BusManager sharedManager;
    ArrayList<String> segmentIDs;
    ArrayList<PolylineOptions> segments;

    public Route(String mLongName, String mRouteID){
        segmentIDs = new ArrayList<String>();
        segments = new ArrayList<PolylineOptions>();
        longName = mLongName;
        routeID = mRouteID;
        sharedManager = BusManager.getBusManager();
        stops = sharedManager.getStopsByRouteID(routeID);
        for (Stop s : stops){
            s.addRoute(this);
        }
        Log.v("Debugging", longName + "'s number of stops:" + stops.size());
    }

    public String toString(){
        return longName;
    }

    public Route setName(String name){
        longName = name;
        return this;
    }

    public ArrayList<String> getSegmentIDs() {
        return segmentIDs;
    }

    public String getLongName(){
        return longName;
    }

    public String getID(){
        return routeID;
    }

    public boolean hasStop(String stop){
        for (Stop s : stops){
            if (s.name.equals(stop)) return true;
        }

        return false;
    }

    public boolean hasStopByID(String stopID){
        for (Stop s : stops){
            if (s.getID().equals(stopID)) return true;
        }
        return false;
    }

    public ArrayList<Stop> getStops(){
        return stops;
    }

    public void addStop(Stop stop){
        if(!stops.contains(stop)) stops.add(stop);
    }

    public void addStop(int index, Stop stop){
        if(stops.contains(stop)) stops.remove(stop);
        stops.add(index, stop);
    }

    public boolean isActive(){
        ArrayList<Time> times = sharedManager.getStopByName("715 Broadway @ Washington Square").getTimesOfRoute(longName);
        Time currentTime = Time.getCurrentTime();
        for (Time t : times){
            if (!t.isStrictlyBefore(currentTime) && currentTime.getTimeOfWeek() == t.getTimeOfWeek()){
                return true;
            }
        }
        return false;
    }

    public static void parseJSON(JSONObject routesJson) throws JSONException{
        JSONArray jRoutes = new JSONArray();
        BusManager sharedManager = BusManager.getBusManager();
        if (routesJson != null) jRoutes = routesJson.getJSONObject(FileGrabber.TAG_DATA).getJSONArray("72");<commit_msg>Fixing out of bounds force close.<commit_after>package com.palsulich.nyubustracker.models;

import android.util.Log;

import com.google.android.gms.maps.model.PolylineOptions;
import com.palsulich.nyubustracker.helpers.BusManager;
import com.palsulich.nyubustracker.helpers.FileGrabber;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class Route {
    String longName = "";
    String routeID = "";
    ArrayList<Stop> stops = null;
    BusManager sharedManager;
    ArrayList<String> segmentIDs;
    ArrayList<PolylineOptions> segments;

    public Route(String mLongName, String mRouteID){
        segmentIDs = new ArrayList<String>();
        segments = new ArrayList<PolylineOptions>();
        longName = mLongName;
        routeID = mRouteID;
        sharedManager = BusManager.getBusManager();
        stops = sharedManager.getStopsByRouteID(routeID);
        for (Stop s : stops){
            s.addRoute(this);
        }
        Log.v("Debugging", longName + "'s number of stops:" + stops.size());
    }

    public String toString(){
        return longName;
    }

    public Route setName(String name){
        longName = name;
        return this;
    }

    public ArrayList<String> getSegmentIDs() {
        return segmentIDs;
    }

    public String getLongName(){
        return longName;
    }

    public String getID(){
        return routeID;
    }

    public boolean hasStop(String stop){
        for (Stop s : stops){
            if (s.name.equals(stop)) return true;
        }

        return false;
    }

    public boolean hasStopByID(String stopID){
        for (Stop s : stops){
            if (s.getID().equals(stopID)) return true;
        }
        return false;
    }

    public ArrayList<Stop> getStops(){
        return stops;
    }

    public void addStop(Stop stop){
        if(!stops.contains(stop)) stops.add(stop);
    }

    public void addStop(int index, Stop stop){
        if(stops.contains(stop)) stops.remove(stop);
        if (stops.size() == index) stops.add(stop);
        else stops.add(index, stop);
    }

    public boolean isActive(){
        ArrayList<Time> times = sharedManager.getStopByName("715 Broadway @ Washington Square").getTimesOfRoute(longName);
        Time currentTime = Time.getCurrentTime();
        for (Time t : times){
            if (!t.isStrictlyBefore(currentTime) && currentTime.getTimeOfWeek() == t.getTimeOfWeek()){
                return true;
            }
        }
        return false;
    }

    public static void parseJSON(JSONObject routesJson) throws JSONException{
        JSONArray jRoutes = new JSONArray();
        BusManager sharedManager = BusManager.getBusManager();
        if (routesJson != null) jRoutes = routesJson.getJSONObject(FileGrabber.TAG_DATA).getJSONArray("72");
{'fraction_non_alphanumeric': 0.10666666666666667, 'fraction_numerical': 0.0017777777777777779, 'mean_word_length': 2.627337201805287, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4941926', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1606, 'n_words': 379}