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 9 years ago.
Improve this question
The question is not too dificult: How do I best implement a table in Java.
I wish to have something like a table in a database. Named columns and numbered rows. My values are Integer.
My inital idea: LinkedHashMap<String, ArrayList<Integer>>
But is there a better way of doing it?
What do you mean by "better"? It depends on what do you need to do with that.
You may build
a 2-dimensional array and a map of column names (C++ way)
a list of objects, where each object is a row (the most Java way)
a Guava Table
Related
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 1 year ago.
Improve this question
I'm writing a method that given a product, returns for each country the number of sales. I named it getNumOfSalesByCountry().
To me, the word "get" relates to a getter of a bean and not to a function that makes a query to a DB.
Can you suggest better names? (Or you think the name is valid)
Thanks
You can name it something like retrieveNumOfSalesByCountry(), but I think getNumOfSalesByCountry() is good too.
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 6 years ago.
Improve this question
I have some pre initialized objects of some class. These objects are heavy weight objects and each correspond to some configuration options specified by user. There will be exactly one instance corresponding to one configuration and same will be used every time.
My question is, which design pattern suits best to handle this kind of situation?
Most likely a Flyweight is what you are looking for. https://en.wikipedia.org/wiki/Flyweight_pattern
This can be used for pre-initialise heavy weight objects and reuse them.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a table with primary key but how much maximum secondary key's i use in that table?
You can define up to 5 local secondary indexes and 5 global secondary indexes per table. Limits in DynamoDb
.
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 9 years ago.
Improve this question
I want to store a list of (Object, int) in a data structure such that the int field can be easily sorted (ascending or descending).
I'm looking at Hashtables and TreeMaps but i'm unsure which, if either, of these are good for this purpose.
The priority is the sort speed. Any suggestions?
Given what you've told us, it's hard to say what'd be best.
If you're concerned with sorting performance alone, a HashTable or TreeMap (actually a red-black binary tree) have great sorting performance, but they're slower than some other data structures when adding (and in TreeMap's case, deleting) items.
You should probably provide more details regarding what you're doing with the data.
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 4 years ago.
Improve this question
Take twissandra as an example, when a new tweet is received, not only the column family for the tweet need to be updated, but a few other (super) column families need to be updated. Definitely we can do this in sequential, on receiving the new tweet, to update each family one by one. But what if there are a dozen column families out there need to be updated? This doesn't seem to be an efficient approach to me. Is any other way, either relying on the programming framework (Java eg), or relying on other "utilities" like Message Queue, or a better programming model/design pattern to make this more scalable and maintainable?
Yes, you can use batch mutations to group together a set of updates. For example, in Hector, you can do something like:
mutator.addInsertion("jsmith", "Standard1",
HFactory.createStringColumn("first", "John"))
.addInsertion("jsmith", "Standard1", HFactory.createStringColumn("last", "Smith"))
.addInsertion("jsmith", "Standard1", HFactory.createStringColumn("middle", "Q"));
mutator.execute();
See https://github.com/rantav/hector/wiki/User-Guide under "Inserting Multiple Columns with Mutator".