4

I try to extract relevant information from a bundled object in Java. This object has a structure:

String name;
Array setOfOrders;

Each element in setOfOrders has

int orderID;
String orderName;
List<BuildingBlock> listOfBlocks;

each BuildingBlock has

String shortName;
String fullName;
String blockID;
Array<Element> elements;

I tried looking into the source code, but the branches seem endless. I tried using debugging mode in NetBeans, but every third variable (setOfOrders, listOfBlocks, elements) just keeps expanding. This feels like trying to find which folders take space on your disk. With Explorer it takes forever, while some disk analyzers show a clear map of space usage.

So, what is the best way to analyze a bundled variable? Should I just expand it fully and search recognizable data structure? Is there command (I cannot ask for a tool, but I can ask for an IDE command, right?) to represent the structure of a variable? Should I rely on getters and setters?

sixtytrees
  • 1,156
  • 1
  • 10
  • 25
  • What do you mean with branches?? source code management System branches?? – Carlitos Way Jun 14 '16 at 21:42
  • How do you expect this to be simplified? The data you're looking at is complex; there's no way around the complexity. – Louis Wasserman Jun 14 '16 at 21:42
  • I'm not quite sure what you mean. Just go a few classes deep. The beauty of it (atleast if it is programmed by a reasonable coder) is that every class has a obvious role. I don't think there is a way around digging into the code, even if it isn't as obvious at the beginning. – RecursiveExceptionException Jun 14 '16 at 21:43
  • By branches I mean "a structure a contains a1 (list of a2,a3,...),b1 (list of b2,b3,...),c1(list of c2,c3,...) and a3 is actually a list of (a31,a32,a33). – sixtytrees Jun 14 '16 at 21:45
  • 1
    I can use Notepad. But this is hard. I can use Notepad++. Syntax highlighting is invaluable. But NetBeans is even better 9thatns to refactor/rename, for example). I am curious if there is a way to represent a structure of a variable in a clear format. If the answer is "yes" then how do I do this? If the answer is "no" then how come this tool doesn't exist yet? – sixtytrees Jun 14 '16 at 21:47
  • Seems like I am experiencing this difficulty not because of using wrong tools, but because this is a feature of Java programming (possibly - programming in general). I will keep this question open, however, just in case... – sixtytrees Jun 14 '16 at 22:02
  • 1
    You're looking for a pretty printer, I have used pretty print in Scala but not Java, try adding that to your keywords – Rhys Bradbury Jun 15 '16 at 16:32
  • I was wondering too. Why is there no such tool in existance? Shouldn't it be possible using reflection? similar to this: http://stackoverflow.com/a/39918/3779853 ( `public static String dump(Object o) {}`) – phil294 Jun 17 '16 at 17:28

4 Answers4

2

Not really sure what you are trying to do. If you want to analyze the data at Runtime the only way is to "Should I just expand it fully and search recognizable data structure" in Debugging Mode.

Or just write some Code for example two for Loops which iterate over the elements and Log the data to the system.out. and then you can search inside the strings.

Francesco Iannazzo
  • 596
  • 2
  • 11
  • 31
2

Your best bet (sorted in a descending order) is:
(a) To hope that author made good comments
(b) To read the source code (if some classes are compiled into .class or .java you are in trouble).
(c) To expand it all*

  • You might be able to decrease the size of the structure by setting for(i=0; i<2; i++){ instead of i<100000. However, if this bundle is created from an SQL response you might be out of luck.
1

First, you could try implementing the toString()-method, if it is not already implemented. Maybe you can get some useful information by printing the structure or parts of it.

Second, if you have such a structure, you may also have some methods to query the data structure. You could use them to query for the information needed. Or if no such methods exist, you could write them, as they are probably not only needed for debugging, but also may be useful for your application.

user140547
  • 7,750
  • 3
  • 28
  • 80
1

You have several options, each with own pros and cons.

You can implement toString method, but it defeats your purpose because to write it you need to know the structure of a variable.

You can use reflection, but this is a proprietary feature that might be gone in future releases.

Large projects typically have several huge global variables (like session, that might store everything relevant to this session) and a zillion of local variables. The structure of local variables is simple. Since there is only a small number of global variables you should ask team leader about their structure.