• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you count and classify java objects

 
Lee Zou
Greenhorn
Posts: 4
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have number of java objects. I would like to count, classify and group them based on objects' attributions (let's say). What is best way to approach this problem. Thanks in advance.

Lee
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Pencil and paper. You do not need to do such counting to run an application, so do it on paper.
 
Lee Zou
Greenhorn
Posts: 4
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are large number of objects generated by a program. There is a need to sort out those objects for reporting. Paper and pencil are not environmental friendly way to "count".
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then those objects should be coded in such a way that you can keep track of them. In particular you need code which increments a counter when one of them is created and code which decrements that counter when one of them is garbage-collected.
 
Lee Zou
Greenhorn
Posts: 4
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. Really appreciate your comment. The problem is that I have no control over the objects that got sent to me. I have no way to modify those objects.

Here is an illustration:

The program may receive Java objects such as String, Integer, Double, .., I like to classify, group and count those objects. In the end, I would like to know

x number of String objects
y number of Integer objects
z number of Double objects

further more, for "x number of String objects", I would like to know x1 number of String objects start with "a"; for y number of Integer objects, I like to find how many there are positive vs negative. ...

So, that is the problem I am facing.


 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you have a well defined list of what you can get, or could you literally get ANY kind of object?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lee Zou wrote:Thanks Paul. Really appreciate your comment. The problem is that I have no control over the objects that got sent to me. I have no way to modify those objects.

Here is an illustration:

The program may receive Java objects such as String, Integer, Double, .., I like to classify, group and count those objects. In the end, I would like to know

x number of String objects
y number of Integer objects
z number of Double objects


(sigh...) I knew it was going to be something like that. Where on earth did you get those requirements from?
 
Lee Zou
Greenhorn
Posts: 4
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for responses. Well, it's a bit hard to argue with sales/marketing. I need to develop a reporting system. There are some objects that have common interface. The other are really hard to know in advance. I just assume they are inherited from Object.

 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't imagine why even the most obtuse sales/marketing type would want to know how many String objects you had in your code which started with "a".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic