• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Problem with recursive function

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following problem, I have 3 lists and I need to merge them into 1 single list, and for that I created a function with recursion, but I have a field called (ENABLE_INPUT) that has condition "0" or "1" and that can be in any of the levels, when it is "0" in any of the levels even if it is in the first level, every generated line must remain with the condition "0", but I can not solve it, I can not leave the place




Return Result:
--------------------------------------------------------------------
size: 8
{CALMONTH=201901, VERSION=REAL, INDICATOR=IND0001, ENABLE_INPUT=1}
{CALMONTH=201901, VERSION=REAL, INDICATOR=IND0002, ENABLE_INPUT=1}
{CALMONTH=201901, VERSION=PLANNING, INDICATOR=IND0001, ENABLE_INPUT=1}
{CALMONTH=201901, VERSION=PLANNING, INDICATOR=IND0002, ENABLE_INPUT=1}
{CALMONTH=201902, VERSION=REAL, INDICATOR=IND0001, ENABLE_INPUT=1}
{CALMONTH=201902, VERSION=REAL, INDICATOR=IND0002, ENABLE_INPUT=1}
{CALMONTH=201902, VERSION=PLANNING, INDICATOR=IND0001, ENABLE_INPUT=1}
{CALMONTH=201902, VERSION=PLANNING, INDICATOR=IND0002, ENABLE_INPUT=1}

Expected Result:
--------------------------------------------------------------------
size: 8
{CALMONTH=201901, VERSION=REAL, INDICATOR=IND0001, ENABLE_INPUT=0}
{CALMONTH=201901, VERSION=REAL, INDICATOR=IND0002, ENABLE_INPUT=0}

{CALMONTH=201901, VERSION=PLANNING, INDICATOR=IND0001, ENABLE_INPUT=1}
{CALMONTH=201901, VERSION=PLANNING, INDICATOR=IND0002, ENABLE_INPUT=1}
{CALMONTH=201902, VERSION=REAL, INDICATOR=IND0001, ENABLE_INPUT=0}
{CALMONTH=201902, VERSION=REAL, INDICATOR=IND0002, ENABLE_INPUT=0}

{CALMONTH=201902, VERSION=PLANNING, INDICATOR=IND0001, ENABLE_INPUT=1}
{CALMONTH=201902, VERSION=PLANNING, INDICATOR=IND0002, ENABLE_INPUT=1}


Sorry for bad english
 
Saloon Keeper
Posts: 10539
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Honestly, your entire code could use refactoring, it's not object oriented at all.

First describe to us what the program is used for, what do the various lists represent, and why do you need to merge them?
 
Marshal
Posts: 65467
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thank you for using the code button, but your long lines make the code very difficult to understand. They also suggest to me that you are trying to do too much all in one place and your methods are too long. Divide the methods into smaller methods, which is [part of] refactoring. But, as Stephan said, please start by explaining what your program does and what all the Lists and Maps are supposed to contain.
 
Marshal
Posts: 7084
491
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, get rid off the habit populating List, Map... that way, even though it is very tempting.

Use static initializers and the habitual way to add/put elements.

Using the way you do, you are unnecessarily creating anonymous classes which as a result after compilation produces en excessive amount of compiled classes.

If that code snippet were in let's say Test.java source file, after compiling it you'd end up with:
Test.class, Test$1.class, Test$2.class, Test$3.class, Test$4.class

As opposed to:
Test.class
 
Eduardo Savoine
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be a layout generator, I can have several layout settings and I can have "N levels" at each layout, so I had to make it dynamic. Each level can have one or more dimensions.

Unfortunately I can't generate an object class, because each layout can be created with one dimension type.

Lists were created this way just to generate the sample content.


The point is that when I use the recursion function, I can't handle the "ENABLE_INPUT" field satisfactorily or the list is all filled with "0" or filled with "1" (I tried to create some conditions to handle, but couldn't resolve )

 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!