added visitor to TimerInfo
This commit is contained in:
		
							parent
							
								
									f2d45b410e
								
							
						
					
					
						commit
						93a282026e
					
				
					 5 changed files with 28 additions and 8 deletions
				
			
		|  | @ -6,11 +6,10 @@ import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
| class CustomTimerInfo( | class CustomTimerInfo( | ||||||
|     name: String, |     name: String, | ||||||
|     description: String, |     description: String, | ||||||
|     private val studyTime: Int, |     val studyTime: Int, | ||||||
|     id: String = "" |     id: String = "" | ||||||
| ):  TimerInfo(id, name, description) { | ):  TimerInfo(id, name, description) { | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     override fun getFunctionalTimer(): FunctionalTimer { |     override fun getFunctionalTimer(): FunctionalTimer { | ||||||
|         return FunctionalCustomTimer(studyTime) |         return FunctionalCustomTimer(studyTime) | ||||||
|     } |     } | ||||||
|  | @ -24,4 +23,8 @@ class CustomTimerInfo( | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     override fun <T> accept(visitor: TimerInfoVisitor<T>): T { | ||||||
|  |         return visitor.visitCustomTimerInfo(this) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | @ -22,4 +22,8 @@ class EndlessTimerInfo( | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     override fun <T> accept(visitor: TimerInfoVisitor<T>): T { | ||||||
|  |         return visitor.visitEndlessTimerInfo(this) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | @ -2,13 +2,14 @@ package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
| 
 | 
 | ||||||
| import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer | ||||||
| import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimerVisitor | ||||||
| 
 | 
 | ||||||
| class PomodoroTimerInfo( | class PomodoroTimerInfo( | ||||||
|     name: String, |     name: String, | ||||||
|     description: String, |     description: String, | ||||||
|     private val studyTime: Int, |     val studyTime: Int, | ||||||
|     private val breakTime: Int, |     val breakTime: Int, | ||||||
|     private val repeats: Int, |     val repeats: Int, | ||||||
|     id: String = "" |     id: String = "" | ||||||
| ):  TimerInfo(id, name, description) { | ):  TimerInfo(id, name, description) { | ||||||
| 
 | 
 | ||||||
|  | @ -28,4 +29,8 @@ class PomodoroTimerInfo( | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     override fun <T> accept(visitor: TimerInfoVisitor<T>): T { | ||||||
|  |         return visitor.visitBreakTimerInfo(this) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | @ -7,8 +7,8 @@ import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  */ |  */ | ||||||
| abstract class TimerInfo( | abstract class TimerInfo( | ||||||
|     val id: String, |     val id: String, | ||||||
|     val name: String, |     var name: String, | ||||||
|     val description: String |     var description: String | ||||||
| ) { | ) { | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -21,6 +21,7 @@ abstract class TimerInfo( | ||||||
|      * TODO implementaties hebben nog hardgecodeerde strings. |      * TODO implementaties hebben nog hardgecodeerde strings. | ||||||
|      */ |      */ | ||||||
|     abstract fun asJson(): Map<String, Any> |     abstract fun asJson(): Map<String, Any> | ||||||
|  |     abstract fun <T> accept(visitor: TimerInfoVisitor<T>): T | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,11 @@ | ||||||
| package be.ugent.sel.studeez.data.local.models.timer_info | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
| 
 | 
 | ||||||
| interface TimerInfoVisitor { | interface TimerInfoVisitor<T> { | ||||||
|  | 
 | ||||||
|  |     fun visitCustomTimerInfo(customTimerInfo: CustomTimerInfo): T | ||||||
|  | 
 | ||||||
|  |     fun visitEndlessTimerInfo(endlessTimerInfo: EndlessTimerInfo): T | ||||||
|  | 
 | ||||||
|  |     fun visitBreakTimerInfo(pomodoroTimerInfo: PomodoroTimerInfo): T | ||||||
|  | 
 | ||||||
| } | } | ||||||
		Reference in a new issue
	
	 lbarraga
						lbarraga