• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do you count and classify java objects

 
Greenhorn
Posts: 4
MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic