// Path: src/it/reyboz/bustorino/util/LinesNameSorter.java
// public class LinesNameSorter implements Comparator<String> {
//     @Override
//     public int compare(String name1, String name2) {
// 
//         if(name1.length()>name2.length()) return 1;
//         if(name1.length()==name2.length()) {
//             try{
//                 int num1 = Integer.parseInt(name1.trim());
//                 int num2 = Integer.parseInt(name2.trim());
//                 return num1-num2;
//             } catch (NumberFormatException  ex){
//                 //Log.d("BUSTO Compare lines","Cannot compare lines "+name1+" and "+name2);
//                 return name1.compareTo(name2);
//             }
//         }
//         return -1;
// 
//     }
// }


import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import it.reyboz.bustorino.util.LinesNameSorter;
    /**
     * Adds a route to the timetable.
     *
     * @param routeID name
     * @param type bus, underground, railway, ...
     * @param destinazione end of line\terminus (underground stations have the same ID for both directions)
     * @return array index for this route
     */
    public int addRoute(String routeID, String destinazione, Route.Type type) {
        return addRoute(new Route(routeID, destinazione, type, new ArrayList<>(6)));
    }
    public int addRoute(Route r){
        this.routes.add(r);
        routesModified = true;
        buildRoutesString();
        return this.routes.size()-1; // last inserted element and pray that direct access to ArrayList elements really is direct
    }

    public void setRoutes(List<Route> routeList){
        routes = new ArrayList<>(routeList);
    }

    @Nullable
    @Override
    protected String buildRoutesString() {
        // no routes => no string
        if(routes == null || routes.size() == 0) {
            return "";
        }
        final StringBuilder sb = new StringBuilder();
// Path: src/it/reyboz/bustorino/util/LinesNameSorter.java
// public class LinesNameSorter implements Comparator<String> {
//     @Override
//     public int compare(String name1, String name2) {
// 
//         if(name1.length()>name2.length()) return 1;
//         if(name1.length()==name2.length()) {
//             try{
//                 int num1 = Integer.parseInt(name1.trim());
//                 int num2 = Integer.parseInt(name2.trim());
//                 return num1-num2;
//             } catch (NumberFormatException  ex){
//                 //Log.d("BUSTO Compare lines","Cannot compare lines "+name1+" and "+name2);
//                 return name1.compareTo(name2);
//             }
//         }
//         return -1;
// 
//     }
// }


// Path: src/it/reyboz/bustorino/backend/Palina.java
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import it.reyboz.bustorino.util.LinesNameSorter;

    /**
     * Adds a route to the timetable.
     *
     * @param routeID name
     * @param type bus, underground, railway, ...
     * @param destinazione end of line\terminus (underground stations have the same ID for both directions)
     * @return array index for this route
     */
    public int addRoute(String routeID, String destinazione, Route.Type type) {
        return addRoute(new Route(routeID, destinazione, type, new ArrayList<>(6)));
    }
    public int addRoute(Route r){
        this.routes.add(r);
        routesModified = true;
        buildRoutesString();
        return this.routes.size()-1; // last inserted element and pray that direct access to ArrayList elements really is direct
    }

    public void setRoutes(List<Route> routeList){
        routes = new ArrayList<>(routeList);
    }

    @Nullable
    @Override
    protected String buildRoutesString() {
        // no routes => no string
        if(routes == null || routes.size() == 0) {
            return "";
        }
        final StringBuilder sb = new StringBuilder();
        final LinesNameSorter nameSorter = new LinesNameSorter();