Simplix-Softworks / SimplixStorage

Library to store data in a better way
Apache License 2.0
138 stars 25 forks source link

getLongList returns integerlist? #37

Closed TheSilentPro closed 3 years ago

TheSilentPro commented 3 years ago

Describe the bug getLongList seems to return an integer list? List<Long> legacy = userdata.getLongList(profile.getPk() + ".followers"); When trying to loop through it i get Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long Here is an example of the list: https://paste.md-5.net/mitokajuni.json Yes the list is getting returned as is, not empty.

To Reproduce Steps to reproduce the behavior: Create a List using #getLongList() Loop through it using for (long entry : list), throws this error

Expected behavior it should loop but i think it's casting Integer while creating the loop or something?

Screenshots N/A

Desktop (please complete the following information):

Additional context N/A

KotlinFactory commented 3 years ago

Hey TheSilentPro,

this seems to happen since the values in your List are not represented as a Long internally. Since Lists in Java can only store primitives and the Wrappers of primitive types can't be casted to each other this exception is thrown.

We have implemented behavior to handle this in our primitive getters but not yet in Lists. If you have any suggestion on how to improve SimplixStorage in this regard I would be more than happy to implement it.

Maybe some sort of a getList: List with a mapper function that maps a raw value to T would be helpful (But could also be implemented manually)

If you feel like it is helpful to chat with us in realtime to get this improved feel free to join our discord: discord.simplixsoft.com.

Regards, Leonhard

KotlinFactory commented 3 years ago

Any further questions?

TheSilentPro commented 3 years ago

Nope, that would be all, just want to be notified when this is fixed :)

KotlinFactory commented 3 years ago

I am sorry for the late response - I am currently in my final exams in school. I still don't exactly understand where this is an issue of SimplixStorage. What exactly do you want to change? The exception you are currently getting is caused by the way the data is read by the background library SimplixStorage is using - It seems to be recognized as an Integer, not as a Long. As stated above we would need to convert every value in the List manually which would require some computation time.

Regards, Leonhard

TheSilentPro commented 3 years ago

No problem i am also doing finals soon and i dont actually fully remember what the issue is. I think i was trying to use the longs you get from longList and loop through them but since they are read by integers it looks like its throwing that error.

And wouldn't this be a problem if it is an actual long but it recognizes it as an Integer. Because longs can be higher than integers so wouldn't that be somewhat an issue

Basically i am trying to get a list of longs but it looks like its returning a list of Integers instead. Trying to loop through them causes those errors.

KotlinFactory commented 3 years ago

Well it looks like its just of a different data type. getIntergerList should do the job.

TheSilentPro commented 3 years ago

Well it looks like its just of a different data type. getIntergerList should do the job.

not all longs can be an interger though? So storing a long that isn't an int when trying to retrieve it will result in an error..