Best data structure to store peculiarly structured data [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
So, I'll be looping through a data base and there will be a bunch of campaigns. Each campaign will have some demos and some sites where certain conditions are satisfied. I want to plot some graphs for the data corresponding to all the campaigns, sites and demos. I was thinking of using java, first getting the campaign, site and demo combinations where the conditions are satisfied and then looping through all of them, running individual queries based on their values and plotting the graphs using maybe, GNU plot. My questions are -
Is there a better way to achieve this (with minimal queries).
If I do do it this way, I first have to store the information.
I was thinking of storing the campaign ids in an ArrayList of Integers, the demos for each campaign in
ArrayList<ArrayList<Integer>>
and the sites for each campaign in
ArrayList<ArrayList<Integer>>
Is there a more efficient way of storing this information?

I'd recommend creating a new class to hold your campaign data and storing references to each object within an ArrayList if you need to keep a handle to them in memory (may not be necessary).
From a purist point of view, the class should be backed by a Data Access Object (DAO) and Plain Old Java Object (POJO) to manage database access and storage in memory but if this is a simple prototype then I wouldn't worry too much. I'd also recommend a utility class to convert/write your chart data - all accessible from your Campaign class.
The Campaign class should also be able to work out whether your conditions are satisfied - and if it's worth generating those charts.

Related

What's the purpose of objects in Java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Today I had an interview for test automation in one of the MNC.
They asked me "why do we need to create an object?"
I explained about OOPs concepts with example of individual bank account holders. But he is not convinced. He just need a definition.
What could be a suitable answer for that question?
You require an object to represent state.
At the most simple definition, a class defines behaviour and an instance of a class (an object) represents state.
Of course there are other things like static contexts which can also maintain state, which you can mention also, but above is the clearest answer which I believe they were looking for.
It also always helps to give an example. You could talk about, for example, an Employee class. You would need an object to represent John and another to represent Jane.
I think that this question is kind of generic and does not give much value to an interview. But some generic question should have a generic answer, and here is mine:
We need to create objects in java so we can get instances that have a state inside our application. This allows us to have persistent encapsulated elements that contain any required information, and methods that operate with it.
Just plain basic OOP theory.
There are many reasons why we create a object apart from basic oops
1) To bring up persistent state data to transactional state to perform action (curd and other) and persist back to data storage.(EJB, POJO,etc )
2) Creating handler to serve service and send fluid data across wire like web-service.
3)Stuctural behavior in action.for example you designed a class for a workflow and to make in action state we create a object and serve the behavior example validation , authorization , etc class
All in all to make design time architecture to response based live system

Mapping a java Entity to a GraphQL object [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have difficulty in implementing GraphQL in a java project as a part of updating it. I'm trying to connect an entity (which uses the Hibernate ORM to map to different databases) to a GraphQLObjectType . Any suggestions how can I accomplish this? Can I omit the GraphQL database configurations if so?
There're multiple options here.
It's probably best to not even map an entity directly . Entities are direct representations of the DB and, as such, should probably not be directly exposed, but wrapped into DTOs (maybe allowing pagination, flattening relations, or whatever is appropriate) instead.
If you just need to map the class (entity or not) to a GraphQLObjectType, graphql-java-annotations is the simplest (and most limited) route (check the status of this project first, it was on a hiatus for a while)
If you want to expose the entire entity graph through GraphQL, graphql-jpa might be your best bet (as Sriram suggests), as it's intended to do exactly that, while also adding pagination, aggregation and sorting
If you want to automatically expose not only an entity/DTO class, but also the operations upon it (e.g. an arbitrary service class), look at graphql-spqr (I'm the author of that project)
If you already defined your entities using JPA/Hibernate, try this:
https://github.com/jcrygier/graphql-jpa

Using SQLite or a File [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am new to Android development and I am trying to make a Trivia application.
I need to store the data relating to questions somewhere and I am not entirely sure where to store it.
I plan to have multiple people playing so I need each person to have the same questions.
Basically I planned to have a list of categories and within each category I had question objects.
The question objects contained information regarding the question such as the answers and question itself.
However, if I use a database, I believe none of this would be needed due the questions being stored in tables which would represent categories.
In terms of speed what would be better:
to store it in a database
or to read from a file every time the application is loaded and store the data within a data structure?
You almost certainly want a database. Databases are made for fast search and easy insertion/deletion. There's really no advantage to having a file and doing in memory parsing each time.
Aside from performance benefits, here's a simple list of advantages of using SQLite rather than flat file:
You can query items as you wish -- don't need to load all of them and
select which ones you need.
Record deletion is a much less painful process. No rewriting of whole
files into wherever.
Updating a record is as easy as removing or creating one.
Have you ever tried doing cross-referencing lookups on a flat file?
Just.Not.Worth.It.
To summarize, it's every advantage a Database has over a text file.
Answer by josephus

Creating my own Lists and Maps data structures [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
For practice I want to make my own lists and maps (like ArrayList, HashMap, HashSet etc.).
My goal is to have it as small and flexible as possible while still maintaining good performance. (long road...)
I have some questions:
1)
Unlike the sun, I don't have to take backwards compatibility into account.
So the first thing I wonder, is there any good reason to keep add and put?
Why not just one?
If I would name put > add would this give problems / complexity / unclearness down the road?
2)
Are there any languages known to have really good data structures? (For example, they could be really smart to avoid a concurrency exception).
3)
As last more a request then a question, if you have any tips our vision of how things could be done different then please post them.
There is no duplicated methods, Collection's have add method that returns a boolean, Map's have put method that returns type associated to Map.
There are plenty of examples of data structure, the point is, ¿what you need your data stucture do best? Avoid concurrency? sort? be fast? store securely?
The examples you need are directly in Java source code:
SOURCES
List
ArrayList
HashMap
and so on....

Appengine Entity Design Advice [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a dilemma on how to implement this requierement:
Let's say I have the following Contact classes
Student,
Tutor,
AdminStaff.
I am not sure what is the best way to structure it in DataStore:
shall I have one Contact entity which will contain shared fields and also corresponding extra fields for given type
or shall I have three separate entities
first approach allows me to search through all my contacts, and the second is to avoid extra filtering when I just need contacts of certain kind.
However I have one more requirement which I am not sure how to accommodate with any of these approaches. What if I have contact with multiple personalities e.g. Tutor and AdminStaff. This suggests I have a separate Contact entity and link to its various personalities. So for the above example I would have data about that person kept in three entities Contact,Tutor,AdminStaff.
I would appreciate for any suggestions
Regarding your concern about searching over all your contacts - even if you have 3 different entity types, I think you could still create an index that would allow you to search over all contacts.
I don't know how many attributes there are that are unique to the different contact roles, but I'd be worried about creating a single mega-class/entity that encompassed them all - it could be a very big and messy class.
And, as you have indicated, your final requirement does make things more complicated. It suggests that perhaps you should have a single contact class/entity for all roles, and then create class(es) for the 3 roles that can be #embed'ed into to the contact entity.

Categories