Skip to content

Commit

Permalink
supporting super-type handling in getWrappedGene
Browse files Browse the repository at this point in the history
  • Loading branch information
arcuri82 committed Dec 23, 2024
1 parent 1fd5f43 commit e5439c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
11 changes: 9 additions & 2 deletions core/src/main/kotlin/org/evomaster/core/search/gene/Gene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,22 @@ abstract class Gene(
* Wrapper genes, and only those, will override this method to check their children
*/
@Suppress("BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER")
open fun <T,K> getWrappedGene(klass: Class<K>) : T? where T : Gene, T : K{
open fun <T,K> getWrappedGene(klass: Class<K>, strict: Boolean = false) : T? where T : Gene, T : K{

if(this.javaClass == klass){
if(matchingClass(klass,strict)){
return this as T
}

return null
}

protected fun matchingClass(klass: Class<*>, strict: Boolean) : Boolean{
if(strict){
return this.javaClass == klass
}
return klass.isAssignableFrom(this.javaClass)
}

/**
* there might be a need to repair gene based on some constraints, e.g., DateGene and TimeGene
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class ChoiceGene<T>(
}

@Suppress("BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER")
override fun <T,K> getWrappedGene(klass: Class<K>) : T? where T : Gene, T: K{
if(this.javaClass == klass){
override fun <T,K> getWrappedGene(klass: Class<K>, strict: Boolean) : T? where T : Gene, T: K{
if(matchingClass(klass,strict)){
return this as T
}
return activeGene().getWrappedGene(klass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class CustomMutationRateGene<out T>(
}

@Suppress("BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER")
override fun <T,K> getWrappedGene(klass: Class<K>) : T? where T : Gene, T: K{
if(this.javaClass == klass){
override fun <T,K> getWrappedGene(klass: Class<K>, strict: Boolean) : T? where T : Gene, T: K{
if(matchingClass(klass,strict)){
return this as T
}
return gene.getWrappedGene(klass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class FlexibleGene(name: String,
}

@Suppress("BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER")
override fun <T,K> getWrappedGene(klass: Class<K>) : T? where T : Gene, T: K{
if(this.javaClass == klass){
override fun <T,K> getWrappedGene(klass: Class<K>, strict: Boolean) : T? where T : Gene, T: K{
if(matchingClass(klass,strict)){
return this as T
}
return gene.getWrappedGene(klass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ abstract class SelectableWrapperGene(name: String,
}

@Suppress("BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER")
override fun <T,K> getWrappedGene(klass: Class<K>) : T? where T : Gene, T: K{
if(this.javaClass == klass){
override fun <T,K> getWrappedGene(klass: Class<K>, strict: Boolean) : T? where T : Gene, T: K{
if(matchingClass(klass,strict)){
return this as T
}
return gene.getWrappedGene(klass)
Expand Down

0 comments on commit e5439c1

Please sign in to comment.