Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Can I simplify this code using Recursion or any other methods?
    text
    copied!<p>So I have this method, roosterID is for generating an ID based on the current year and week of year, this is what I've come up with, but I don't think this is the best way to do it, I tried making the method recursive at some point. That didn't work the way I wanted it to. At least, the way I tried it. Basically say there's a year that has 53 weeks, I'm calling the load method of rDAO, with the roosterID for the current week, and the 2 coming weeks. Basically I want the roosterID to be 20141 for the week after 201353, simply using roosterID+1 would make it 201354. I hope my explanation isn't to rubbish.</p> <p>the code below works, I just think it's kind of dirty and unprofessional, and can be done a lot better, if anything changes I have to redo pretty much all the code, so i'd like some advice.</p> <pre><code> public void getWeekTabs(){ gc.setFirstDayOfWeek(Calendar.MONDAY); if(gc.get(Calendar.WEEK_OF_YEAR) &lt;= gc.getWeeksInWeekYear()-2){ roosterID = Integer.parseInt(Integer.toString(gc.get(Calendar.YEAR)) + Integer.toString(gc.get(Calendar.WEEK_OF_YEAR))); rDAO.load(roosterID); rDAO.load(roosterID +1); rDAO.load(roosterID +2); }else if(gc.get(Calendar.WEEK_OF_YEAR) == gc.getWeeksInWeekYear()-1){ roosterIDtemp = Integer.parseInt(Integer.toString(gc.get(Calendar.YEAR) +1 ) + Integer.toString(1)); rDAO.load(roosterID); rDAO.load(roosterID +1); rDAO.load(roosterIDtemp); }else if(gc.get(Calendar.WEEK_OF_YEAR) == gc.getWeeksInWeekYear()){ roosterIDtemp = Integer.parseInt(Integer.toString(gc.get(Calendar.YEAR) +1 ) + Integer.toString(1)); rDAO.load(roosterID); rDAO.load(roosterIDtemp); rDAO.load(roosterIDtemp +1); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload