package com.conveyal.r5.api.util;

import com.conveyal.r5.profile.StreetMode;

import java.util.Set;

/**
 * Modes of transport on access or egress legs
 */
public enum  LegMode {
    WALK, BICYCLE, CAR,
    //Renting a bicycle
    BICYCLE_RENT,
    //Park & Ride
    CAR_PARK;

    /** Return the heaviest/fastest StreetMode for use in stop finding */
    public static StreetMode getDominantStreetMode(Set<LegMode> modes) {
        if (modes.contains(LegMode.CAR)) return StreetMode.CAR;
        else if (modes.contains(LegMode.BICYCLE)) return StreetMode.BICYCLE;
        else return StreetMode.WALK;
    }

    /** Convert between these two enum types */
    public static StreetMode toStreetMode (LegMode legMode) {
        if (legMode == LegMode.WALK) {
            return StreetMode.WALK;
        }
        if (legMode == LegMode.BICYCLE) {
            return StreetMode.BICYCLE;
        }
        if (legMode == LegMode.CAR) {
            return StreetMode.CAR;
        }
        throw new RuntimeException("Unrecognized mode.");
    }

}

@@ -71,16 +71,76 @@
 etMode;%0A
+import org.hsqldb.lib.Collection;%0A%0Aimport java.util.EnumSet;
 %0Aimport 
@@ -1098,10 +1098,406 @@
 %0A    %7D%0A%0A
+    public static EnumSet%3CStreetMode%3E toStreetModeSet (EnumSet%3CLegMode%3E... legModeSets) %7B%0A        EnumSet%3CStreetMode%3E streetModes = EnumSet.noneOf(StreetMode.class);%0A        for (EnumSet%3CLegMode%3E legModeSet : legModeSets) %7B%0A            for (LegMode legMode : legModeSet) %7B%0A                streetModes.add(LegMode.toStreetMode(legMode));%0A            %7D%0A        %7D%0A        return streetModes;%0A    %7D%0A%0A
 %7D%0A

add method to bulk convert LegModes to StreetModes