Skip to content

Instantly share code, notes, and snippets.

@yogacp
Last active August 15, 2019 10:23
Show Gist options
  • Save yogacp/0a2d38e0c1bc798f8d054f5f1da2d807 to your computer and use it in GitHub Desktop.
Save yogacp/0a2d38e0c1bc798f8d054f5f1da2d807 to your computer and use it in GitHub Desktop.
/**
* Can you simplify this code?
* ==================================
* Assesment Point:
* 1. Line of code
* 2. Variable naming
* ==================================
*
* Get Data from this API to test your code:
* http://demo3325159.mockable.io/getBatchConfig
*
* Sample of returned list from below functions:
* HashMap<Int, String> RegionName = {1=Indonesia, 2=Singapore}
* HashMap<String, String> RegionId = {sg=Singapore, id=Indonesia}
* HashMap<Int, String> VerticalType = {1=Apparel, 2=On Demand, 3=Designer Bag}
* HashMap<String, String> VerticalTypeId = {bags=Designer Bag, apparel=Apparel, on_demand=On Demand}
*/
fun BatchConfig.Result.addToRegionNameList(list: HashMap<Int, String>): HashMap<Int, String> {
val sortedList : HashMap<Int, String> = hashMapOf()
val regionName = region.takeIf { !list.values.contains(it?.name) }
regionName.notNull { list[regionOutboundOrder] = it.name }
list.toSortedMap().toMap(sortedList)
return sortedList
}
fun BatchConfig.Result.addToRegionIdList(list: HashMap<String, String>): HashMap<String, String> {
val sortedList : HashMap<String, String> = hashMapOf()
val regionId = region.takeIf { !list.values.contains(it?.name) }
regionId.notNull { list[it.id] = it.name }
list.toSortedMap().toMap(sortedList)
return sortedList
}
fun BatchConfig.Result.addToVerticalTypeList(list: HashMap<Int, String>): HashMap<Int, String> {
val sortedList : HashMap<Int, String> = hashMapOf()
val verticalName = vertical.takeIf { !list.values.contains(it?.name) }
verticalName.notNull { list[verticalTypeOutboundOrder] = it.name }
list.toSortedMap().toMap(sortedList)
return sortedList
}
fun BatchConfig.Result.addToVerticalTypeIdList(list: HashMap<String, String>): HashMap<String, String> {
val sortedList : HashMap<String, String> = hashMapOf()
val verticalId = vertical.takeIf { !list.values.contains(it?.name) }
verticalId.notNull { list[it.id] = it.name }
list.toSortedMap().toMap(sortedList)
return sortedList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment