Commit 53a5764f authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

bits variants calc

parent 9e455842
......@@ -9,11 +9,13 @@ import com.biganto.visual.roompark.data.repository.file.FileModule
import com.biganto.visual.roompark.data.repository.mapper.fromRaw
import com.biganto.visual.roompark.data.repository.mapper.fromRawList
import com.biganto.visual.roompark.domain.contract.FlatPlanContract
import com.biganto.visual.roompark.domain.model.FeatureModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.domain.model.fromEntity
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import java.util.*
import javax.inject.Inject
/**
......@@ -144,13 +146,41 @@ class PlanRepository @Inject constructor(
}
private fun BitSet.getOrNull(index:Int) =
if (index<0 || index>=this.size()) null
else get(index)
val PlanPresetModel.featuresVariants : List<PlanFeaturesVariant>
get() {
if (this.features.isNullOrEmpty()) return arrayListOf()
val variants = this.features.size
return arrayListOf()
} //List9 PlanFeaturesVariant()
val maxInd = this.features.size
val variants = BitSet(maxInd).apply { for (i in 0 until size()) set(i,false) }
val f = features.indexOfFirst { it is FeatureModel.Furniture }
val s = features.indexOfFirst { it is FeatureModel.Sizes }
val e = features.indexOfFirst { it is FeatureModel.Electric }
val w = features.indexOfFirst { it is FeatureModel.Walls }
val trueBit = BitSet(1).apply { set(0,true) }
var firstRun = true
val resList = mutableListOf<PlanFeaturesVariant>()
do{
if (firstRun) firstRun = false
else variants.and(trueBit)
val v = PlanFeaturesVariant(
estateId,planId,
furniture = variants.getOrNull(f),
sizes = variants.getOrNull(s),
electric = variants.getOrNull(e),
walls = variants.getOrNull(w)
)
resList.add(v)
}while (variants.cardinality() != variants.size())
return resList
}
data class PlanFeaturesVariant(
val estateId: Int,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment