0

i want to get the count value of one of the children of arrayString . so i have Arraylist <resistance?>(), which contains {name, room_block, registration number} let's say the values

  1. {Faisal, A-1, 628345}
  2. {Agun, A-1, 932983}
  3. {Jefri, B-1, 7820179}

then I want to get the count value from Room_Block so that it will return the value.

Number of Rooms = 2, namely A-1 and B-1

this is my temporary code which is false

this is my Arraylist value form

val dao = DAOTahanan()
    dao.get().addValueEventListener(object : ValueEventListener {
        @SuppressLint("NotifyDataSetChanged")
        override fun onDataChange(snapshot: DataSnapshot) {
            emps.clear()
            for (data in snapshot.children) {
                val emp = data.getValue(tahanan::class.java)
                emp!!.setkey(data.key)
                emps.add(emp)

            }
            temporay.sortWith { lhs, rhs ->
                rhs!!.name?.let {
                    lhs!!.name!!.compareTo(
                        it
                    )
                }!!
            }
                //filter jika nilai ada yang ganda
                temp.clear()
                for(item in tempora){

                    if (!temp.stream().anyMatch { t-> t?.blok_kamar == item?.blok_kamar }){

                        temp.add(item)
                    }else{
                        Log.e("Check duplikat value", "__${tempora.stream().count().toInt()}")
                    }
                }
                temp.sortWith { lhs, rhs ->
                    rhs!!.blok_kamar?.let {
                        lhs!!.blok_kamar!!.compareTo(
                            it
                        )
                    }!!
                }
                    //adapter & viewmodel cardslide
                adap = adaptercardslide_levelsdua(context!!, tempora)
                rec!!.layoutManager = LinearLayoutManager(context!!, LinearLayoutManager.HORIZONTAL, false)
                rec!!.adapter = adap
                adap?.setItems(temp)

this is the code where i get the data Arraylist<Prisoner?>() and this my code in adapter recycleview :

    package com.example.testing.model

import android.content.Context
import android.content.Intent
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.testing.Dashboard.detail.Ac_detail_tahanan
import com.example.testing.Database.tahanan
import com.example.testing.R
import com.example.testing.adapter.RVAdapter
import java.util.stream.Collectors
import kotlin.collections.ArrayList
import androidx.localbroadcastmanager.content.LocalBroadcastManager




class adaptercardslide(private val context: Context, tempora: ArrayList<tahanan?>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    private val valueint = tempora
    var typeface_medium : Typeface? = null
    var typeface_bold: Typeface? = null
    var typefacesemi: Typeface? = null
    var typefacedefauld: Typeface?= null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view: View = LayoutInflater.from(context).inflate(R.layout.card_item, parent, false)
        typeface_medium = ResourcesCompat.getFont(context, R.font.poppins_medium)
        typeface_bold = ResourcesCompat.getFont(context, R.font.poppins_bold)
        typefacesemi = ResourcesCompat.getFont(context, R.font.poppins_semibold)
        typefacedefauld = ResourcesCompat.getFont(context, R.font.poppins)
        return modelcardslide(view)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val vh: modelcardslide = holder as modelcardslide
        val emp: tahanan = list[position]!!
        val count = valueint.count {
            emp.blok_kamar?.let { it1 -> it?.blok_kamar?.contains(it1) }!!
        }

        vh.nameblok.text = emp.blok_kamar
        vh.nameblok.typeface = typeface_bold

        vh.jumlahorang.text = "$count, Tahanan"
        vh.jumlahorang.typeface = typefacesemi

        vh.titlejumlah.typeface = typeface_bold

        vh.btnclik.setOnClickListener {
            val ItemName: String = vh.nameblok.text.toString()
            val intent = Intent("blok-selected")
            //            intent.putExtra("quantity",Integer.parseInt(quantity.getText().toString()));
            //            intent.putExtra("quantity",Integer.parseInt(quantity.getText().toString()));
            intent.putExtra("item", ItemName)
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    var list: ArrayList<tahanan?> = ArrayList<tahanan?>()
    fun setItems(emp: ArrayList<tahanan?>) {
        list.addAll(emp)
    }
}

Load dynamic objects from application.properties in Spring Boot

I currently have a microservice in Spring Boot, where I have some properties stored in application.properties. Right now, it is configured for one store only. But I want to change the logic so that stores can be added dynamically without needing to change any code.

I have created a model java class for a store, and it looks like this:

public class Store {
    private String username;
    private String password;
    private String hostname;
    private int port;
}

My application.properties looks like this today:

system.connection.username=TestUser
system.connection.password=123456
system.connection.hostname=12.34.56.78
system.connection.port=1234

But I want to be able to specify which store it is, and be able to add more stores by just adding them into the application.properties, like this:

system.connection.Store1.username=TestUser1
system.connection.Store1.password=123456
system.connection.Store1.hostname=12.34.56.78
system.connection.Store1.port=1234

system.connection.Store2.username=TestUser2
system.connection.Store2.password=859382
system.connection.Store2.hostname=34.34.34.34
system.connection.Store2.port=4444

Then add this into some hashmap, and be able to check for and retrieve the variables for a specific store from any of my other classes.

For this, I have tried the following:

@Configuration
@ConfigurationProperties(prefix = "system.connection")
class StoresConfiguration(
    val stores: HashMap<String, Store> = HashMap()
) {

    fun getStore(storeName: String): Store? {
        return stores.get(storeName)
    }


}

But getStore only returns null, and even if I check stores.size it is 0. So where am I doing wrong, and how can I do this effectively? I have thought about just skipping the crap and just making a folder called "stores" and put json files in it, and read from there. So that each Store is just a json file, so at startup the app scans the folder and for every json file makes a Store object. But I don't know if that is a good solution. This is my first time working with Spring Boot. Thanks for any help!

4

1 回答 1

0

我找到了答案,只需使用 startswith() 进行过滤,这是我使用的代码:

var temporay = ArrayList<tahanan?>()
repeat(temp.size) {
                    temporay = (temp.stream()
                        .filter {
                            it?.blok_kamar!!.startsWith(emp.blok_kamar!![0])
                        }
                        .collect(Collectors.toList()) as ArrayList<tahanan?>)
                }
于 2022-02-12T18:23:25.543 回答