Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit c310f0e

Browse files
committed
Make the life easier for subclasses
1 parent 704e4dc commit c310f0e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/main/scala/com/ckkloverdos/convert/SourceTargetConverter.scala

+27-2
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,43 @@ object SourceTargetConverter {
112112
}
113113
}
114114

115-
abstract class StrictSourceConverterSkeleton[SS: Type, TT: Type]extends Converter {
115+
abstract class StrictSourceConverterSkeleton[SS: Type, TT: Type] extends Converter {
116116
final def canConvertType[S: Type, T: Type]: Boolean = {
117117
SourceTargetConverter.canConvertWithStrictSource(typeOf[SS], typeOf[TT], typeOf[S], typeOf[T])
118118
}
119119

120120
final def isStrictSource = true
121+
122+
/**
123+
* Convert or throw an exception.
124+
*
125+
* This is a low-level function.
126+
*/
127+
@throws(classOf[ConverterException])
128+
final def convertEx[T: Type](sourceValue: Any) = {
129+
convertEx_(sourceValue.asInstanceOf[SS]).asInstanceOf[T]
130+
}
131+
132+
@throws(classOf[ConverterException])
133+
protected def convertEx_(sourceValue: SS): TT
121134
}
122135

123-
abstract class NonStrictSourceConverterSkeleton[SS: Type, TT: Type]extends Converter {
136+
abstract class NonStrictSourceConverterSkeleton[SS: Type, TT: Type] extends Converter {
124137
final def canConvertType[S: Type, T: Type]: Boolean = {
125138
SourceTargetConverter.canConvertWithNonStrictSource(typeOf[SS], typeOf[TT], typeOf[S], typeOf[T])
126139
}
127140

128141
final def isStrictSource = false
142+
143+
/**
144+
* Convert or throw an exception.
145+
*
146+
* This is a low-level function.
147+
*/
148+
final def convertEx[T: Type](sourceValue: Any) = {
149+
convertEx_(sourceValue.asInstanceOf[SS]).asInstanceOf[T]
150+
}
151+
152+
protected def convertEx_(sourceValue: SS): TT
153+
129154
}

0 commit comments

Comments
 (0)