1 package com.android.onboarding.nodes 2 3 import java.time.Instant 4 5 /** 6 * Basic [IOnboardingGraph] representation with data available from a set of 7 * [OnboardingGraphLog.OnboardingEventDelegate] only. 8 */ 9 typealias OnboardingGraph = 10 IOnboardingGraph<OnboardingGraphLog.OnboardingEventDelegate, OnboardingGraphNode> 11 12 /** A core representation of the onboarding graph mainly built from [TEvent]s. */ 13 interface IOnboardingGraph< 14 out TEvent : OnboardingGraphLog.OnboardingEventDelegate, 15 out TNode : IOnboardingGraphNode<TEvent>, 16 > { 17 /** 18 * All events related to this graph, sorted by [OnboardingGraphLog.OnboardingEventData.timestamp] 19 */ 20 val events: Iterable<TEvent> 21 22 /** A map of all the nodes in the graph as identified by [OnboardingGraphNode.id] */ 23 val nodes: Map<Long, TNode> 24 25 /** The time when the first node entered the graph. */ 26 val start: Instant 27 get() = events.firstOrNull()?.timestamp ?: Instant.now() 28 29 /** The time when the last node exited the graph. */ 30 val end: Instant 31 get() = events.lastOrNull()?.timestamp ?: start 32 33 companion object { 34 /** 35 * Constructs default implementation of the [OnboardingGraph] 36 * 37 * @param events [IOnboardingGraph.events] 38 */ invokenull39 operator fun invoke( 40 events: Iterable<OnboardingGraphLog.OnboardingEventDelegate> 41 ): OnboardingGraph = OnboardingGraphBuilder.build(events) 42 } 43 } 44