I have a List of objects created from a map like so:
Map incomingRequest = (Map)object;
List accounts = (List)incomingRequest.get("accountList");
In addition, I loop through these objects and pull them out one by one via the index of that list like so and create the account object:
for (int accountRow = 0; accountRow < accounts.size(); accountRow++){
Account account = (Account)accounts.get(accountRow);
There is a method on this Account account object that I can use to get an identifier I can sort on called like so: account.getComp_id().getIcLine(). This gives me a non-unique number that I can use to group with. I now have a need to do some calculations involving only the grouping ov like IcLine properties.
My thought is to create a 2D ArrayList so that I can loop through each sorted array of objects sharing the same IcLine number. However, I currently can't figure out exactly how I would do that after googling around and trying to work through it. I feel like this is a good job for recursion, but I can't figure out how to create the 2D ArrayList I need. Your guidance is appreciated
Related
The problem I'm facing is more like of algorithmic nature.
Let's say that I have a list of pair objects containing integers. Is there a way to sort the list so that the second part of the pair is equal to first part of the next pair?
For instance given this list of pairs:
A = Pair(2,1),Pair(2,3),Pair(1,3).
After sorting the list becomes:
A = Pair(1,3), Pair(3,2),Pair(2,1).
As you can see it is allowed to change the order of values inside the pair like the Pair(2,3) which became Pair(3,2).
I though about using comparator or comparable interfaces but they dont cover complex cases like the above.
To begin with I'm a newbie to Firestore and Android programming.
I have a collection which stores documents, each document contains an array of semesters, inside the semester array there will be an array of maps representing each semester. Inside the individual semester maps, there will be a number field identifying the semester and also another array called Students where it will contain an array of maps where each map will represent each student and store three different fields: ID of the student, DaysPresent, Total.
I'm trying to find a way to read the data for each individual student represented by ID in such a way where the semester number is taken into account.
For example, if the user selects Semester 1, it will go inside the array Semester and then load up the values from the first array which represents the Semester 1, and it will then display all the maps that represent each student where the days present and the total can be modified and read by the user.
One crucial key point is that the total number will always be the same for every individual map which means every individual student.
Edit: Mar 26th, 2020:
Actually it's possible using the solution in the following article:
How to map an array of objects from Cloud Firestore to a List of objects?
If you intend to get a List<Semester> or a List<Student> when querying your Cloud Firestore database, please note that this is currently not possible. Even if those objects are of type Semester and Student, there is no way you can map them into a List of Semester/Student objects. To solve this, you need to write code to iterate those objects so you can convert them from a List<Map> to a List<Semester>and List<Student>. So you need to apply your own logic for that.
Edit:
The type of object that is returned when calling:
document.getData();
Is a Map<String Object>, so you need to iterate through the map according to your logic and get the data as needed.
Hello everybody I have a question regarding adding an entire array to a linked list and what I mean by that is not adding the values with an int array to a linked list but to store the array itself within the linked list. For example
int[] numbers = new int[1,2,3];
LinkedList<something> hi = new LinkedList<something>();
hi.add(array);
This is what I would like to do as I want to store a copy of numbers and than change numbers. I do this so I can compare the past version of numbers with the current one. The reason I want to compare the past and current is so when I change numbers I make sure not to change it to a past version of numbers and always generating a unique state. So I have two questions one how do I store a full array into a linked list or is there better way to keep track variation of numbers I created.
I have some Objects (currently 20 000 +) that have the following Attributes
Object
----------
String name
int rating
I want to create an ELO rating for all these Objects. This implies the following:
To adjust the ELO of 2 Objects matched against each other I need to find those Objects in the list by name.
To Display the List I need to get every Object ordered by its rating.
The whole program will be implemented in Java, but I think its independent from the programming language.
Currently I am unsure which data model to choose for this Project. A friend advised me to use a 2-4 tree to insert the Objects ordered by name so I can change the rating of each object fast.
However the Objects are printed in order of their rating rather than by name and I don't want to sort so many Objects every time I output the list.
As I am pretty new to data structures: What is the usual way to solve this problem?
Creating another tree ordered by rating?
Having a list of ratings and each rating linked to each Object currently having that rating?
Edit: ELO rating is a mapping from the set of objects to the integers. Each object only gets one rating but a rating can have multiple Objects associated with it.
Creating another tree ordered by rating? Having a list of ratings and each rating linked to each Object currently having that rating?
Well , this is one way to do so , but will take huge space also since you have 20K+ entries .
The best way i can think of now is :
Use datastructure like multimap with key=name , and value = ratings.
This way , everytime you insert a new object in multimap , it will take O(logN) time .
To find all ratings with same name use equal_range , which is also an O(logN) operation .
Hope this helps !
A HashMap with name as the key will give you O(1) performance when matching the elements, keep a TreeSet with a rating Comparator and you'll have the items in order. Although you'll need to reinsert an element if the rating changes.
I have an excell sheet with several colums of values and want to put them in a 2D array. Normally, the way I would do it would be:
int[][] example={{colum 1 values},{colum 2 values},{colum 3 values}};
This way works fine, but can be very time consuming when I have lots of colums. Is there a faster way to do this?
Note: This is being used in an exercise I'm doing, so I dont want to stray into using XML or anything like that just yet.
Without seeing code nobody can really give you specific examples, but the algorithm is pretty simple.
First initialize the outer size of your 2d array. Then you just iterate over your columns in a loop and add the values.
Now, that said, why are you not using a more convenient data structure, such as a List of Lists? (ie List<List<String>>). I would suggest that because it takes all the array management out of the equation.
Note that the code below is somewhat pseudo-code-ish given that we don't know what objects you're working with
List<List<String>> table = new ArrayList<List<String>>();
//Note that you have to initialize each list inside the list
for(int i = 0; i < columns.size; i++)
{
table.add(new ArrayList<String>());
}
then you can just add values to each list:
table.get(columnIndex).add(value);
or
table.get(columnIndex).addAll(listOfValues);