Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have this huge code which is used to generate chart several categories with Primefaces. How I can optimize this source. Now I get this error when I run the code:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

This is the complete code of the managed bean:

The code is too huge I will paste it here.

share|improve this question
It's not obvious what you're asking here. It seems that you have a problem with your code causing an exception but also that you want to "optimize" it. In which way, do you want it to run faster? Make it more legible? Consume less memory. And the code you pasted is over 3000 lines long for one class. You're going to have to distill the problem down if you want help. – Mike Brown Mar 6 at 20:02
That's pretty bold to post a ~3.5k LOC File and expect us to tell you "how to optimize" :D – Vain Fellowman Mar 7 at 7:48

closed as not a real question by gnat, MichaelT, Mike Brown, Mason Wheeler, Robert Harvey Mar 6 at 20:07

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

I had a quick look. You may benefit from using maps to retrieve properties instead of having tens of setters/getters, e.g. instead of

public int getDatacenterProduction() { return datacenterProduction; }
public void setDatacenterProduction(int datacenterProduction) {
    this.datacenterProduction = datacenterProduction;
}
public int getZonesProduction() { return zonesProduction; }
public void setZonesProduction(int zonesProduction) {
    this.zonesProduction = zonesProduction;
}

try something like

Map<String, Integer> map = new HashMap<String, Integer>();
int x = map.get("datacenterproduction");
map.set("zonesproduction", Integer.valueOf(z));

essentially the map would replace the DCDataObj class.

The initDBDataProduction uses a lot of constants and so your life maybe made easier by using a for loop and a table of the needed values.

Once your code is cleaned up further improvements should become more apparent.

share|improve this answer
Minor nit - please don't ever suggest new Integer(z) - this creates a new object every time. The factory method Integer.valueOf(z) can make use of the internal cache to the Integer class to avoid creating new objects for commonly used values. – MichaelT Mar 6 at 19:27
@MichaelT Fair enough, it's been a while since I've done Java – James Mar 6 at 19:28
Thank you... I've seen code that does new Boolean(true) which just makes me go wtf. It becomes even more 'fun' when there is a test if (new Boolean(foo) == new Boolean(bar)) which, aside from creating and throwing away of two objects is always false. Its just something that gets my hackles up and I endevor to stamp it out quickly before someone else gets it into their head. The "awhile" is a fair excuse - this is something that changed with 1.5 (I'm working on code with lots of 1.4ism's in it still) – MichaelT Mar 6 at 19:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.