File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How do you count and classify java objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do you count and classify java objects " Watch "How do you count and classify java objects " New topic
Author

How do you count and classify java objects

Lee Zou
Greenhorn

Joined: Aug 17, 2011
Posts: 4

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

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Aug 17, 2011
Posts: 4

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
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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

Joined: Aug 17, 2011
Posts: 4

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

Joined: Oct 02, 2003
Posts: 11499
    
  16

do you have a well defined list of what you can get, or could you literally get ANY kind of object?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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

Joined: Aug 17, 2011
Posts: 4

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
Bartender

Joined: Oct 14, 2005
Posts: 18989
    
    8

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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you count and classify java objects