package net.squanchy.navigation.deeplink;

import net.squanchy.navigation.Navigator;
import net.squanchy.support.lang.Optional;

class DeepLinkNavigator {

    private final Navigator navigator;

    DeepLinkNavigator(Navigator navigator) {
        this.navigator = navigator;
    }

    void toSchedule(String path) {
        String[] pathSegments = path.split("/");

        Optional<String> dayId = Optional.absent();
        if (pathSegments.length > 0) {
            dayId = Optional.of(pathSegments[0]);
        }

        Optional<String> eventId = Optional.absent();
        if (pathSegments.length > 1) {
            eventId = Optional.of(pathSegments[1]);
        }
        navigator.toSchedule(dayId, eventId);
    }

    void toEventDetails(String path) {
        String[] pathSegments = path.split("/");

        if (pathSegments.length > 0) {
            String eventId = pathSegments[0];
            navigator.toEventDetails(eventId);
        } else {
            throw DeepLinkParsingException.eventDetailsMissingEventId(path);
        }
    }

    void toSpeakerUri(String path) {
        String[] pathSegments = path.split("/");

        if (pathSegments.length > 0) {
            String speakerId = pathSegments[0];
            navigator.toSpeakerDetails(speakerId);
        } else {
            throw DeepLinkParsingException.speakerDetailsMissingSpeakerId(path);
        }
    }

    void toFavorites() {
        navigator.toFavorites();
    }

    void toSocial() {
        navigator.toTwitterFeed();
    }

    void toVenue() {
        navigator.toVenueInfo();
    }

    void toDebug() {
        navigator.toDebugSettings();
    }
}

@@ -36,16 +36,68 @@
 plink;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import n
@@ -368,32 +368,36 @@
 ) %7B%0A        
+List%3C
 String
-%5B%5D
+%3E
  pathSegment
@@ -396,38 +396,44 @@
 hSegments = 
-path.split(%22/%22
+extractSegments(path
 );%0A%0A        
@@ -480,32 +480,33 @@
 ();%0A        if (
+!
 pathSegments.len
@@ -498,34 +498,33 @@
 athSegments.
-length %3E 0
+isEmpty()
 ) %7B%0A        
@@ -559,19 +559,23 @@
 Segments
-%5B0%5D
+.get(0)
 );%0A     
@@ -659,22 +659,22 @@
 egments.
-length
+size()
  %3E 1) %7B%0A
@@ -723,11 +723,15 @@
 ents
-%5B1%5D
+.get(1)
 );%0A 
@@ -835,32 +835,36 @@
 ) %7B%0A        
+List%3C
 String
-%5B%5D
+%3E
  pathSegment
@@ -867,34 +867,39 @@
 ments = 
-path.split(%22/%22
+extractSegments(path
 );%0A
-%0A
         
@@ -915,34 +915,125 @@
 egments.
-length %3E 0) %7B%0A    
+isEmpty()) %7B%0A            throw DeepLinkParsingException.eventDetailsMissingEventId(path);%0A        %7D%0A        %0A
         
@@ -1057,33 +1057,33 @@
 pathSegments
-%5B0%5D;%0A    
+.get(0);%0A
         navi
@@ -1113,34 +1113,158 @@
 entId);%0A    
+%7D%0A%0A
     
-%7D else
+void toSpeakerUri(String path) %7B%0A        List%3CString%3E pathSegments = extractSegments(path);%0A        if (pathSegments.isEmpty())
  %7B%0A         
@@ -1289,37 +1289,39 @@
 arsingException.
-event
+speaker
 DetailsMissingEv
@@ -1310,37 +1310,39 @@
 erDetailsMissing
-Event
+Speaker
 Id(path);%0A      
@@ -1349,36 +1349,151 @@
   %7D%0A
+%0A
     
-%7D%0A%0A
     
-void toSpeakerUri
+String speakerId = pathSegments.get(0);%0A        navigator.toSpeakerDetails(speakerId);%0A    %7D%0A%0A    private List%3CString%3E extractSegments
 (Str
@@ -1521,20 +1521,19 @@
 tring%5B%5D 
-path
+all
 Segments
@@ -1552,25 +1552,24 @@
 t(%22/%22);%0A
-%0A
         
 if (path
@@ -1564,38 +1564,63 @@
     
-if (pathSegments.length %3E 0) %7B
+ArrayList%3CString%3E filteredSegments = new ArrayList%3C%3E();
 %0A   
@@ -1620,36 +1620,37 @@
 ();%0A        
-    
+for (
 String s
 peakerId = p
@@ -1637,39 +1637,36 @@
 String s
-peakerId = path
+egment : all
 Segments
 %5B0%5D;%0A   
@@ -1661,12 +1661,11 @@
 ents
-%5B0%5D;
+) %7B
 %0A   
@@ -1677,44 +1677,78 @@
     
-navigator.toSpeakerDetails(speakerId
+if (!segment.isEmpty()) %7B%0A                filteredSegments.add(segment
 );%0A 
@@ -1758,16 +1758,13 @@
     
-%7D else %7B
+    %7D
 %0A   
@@ -1772,90 +1772,42 @@
     
+%7D%0A
     
-throw DeepLinkParsingException.speakerDetailsMissingSpeakerId(path);%0A        %7D
+    return filteredSegments;
 %0A   

Improve deeplink path-parsing code