Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Recurssion programming to retrieve inner values of objects

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Recurssion programming to retrieve inner values of objects

    Hi,
    I am stuck with one of the programmatic logic implementation.Can any one please help me in this regards.The issue is described below.

    I have classes called Event and Method.The structure looks like below.

    Class Event {
    private long eventId;
    private String eventName;
    private Map<String,Method> methods;
    //setters and getters
    }

    class Method {
    private long methodId;
    private String methodName;
    private Event triggeredEvent;
    // setters and getters.
    }

    I have a top level Event and it contains a map of Methods (objects of Method class) and again each method can contain one triggered event which again a class of Event.The triggered event can contain again methods.

    My issue is to traverse from top level Event to down level event and find out the event count and delivery method count at each level

    Attached is tree structure of the issue with a sample example and result expected.

    I have been struggling to implement this logic.Can any one please help me out.Capture.JPG


  2. #2
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Recurssion programming to retrieve inner values of objects

    Seems like a pretty complicated data structure... What problem are you facing? Maybe it's possible to simplify data structure?
    Also, Method class is a part of java core classes, so it's a bad practice to define your own class with same name.

    Anyway, here's a brief sketch of how might you do what you want to, with breadth first search.
    1. Initialize data structures where you want to store yielded information (for example, the counter data of each level of the tree may be grouped into list)
    2. Define a method that would accept a collection of events as an argument. Inside the method:
    2.1. Count all the events
    2.2. Count all the methods of the events
    2.3. Store the data at (1) data structure
    2.4. Create and fill the collection of events of lower level (from the collection of events passed to this method as an argument)
    2.5. Call this method on the (2.4.) collection recursively
    3. Don't forget to specify termination condition!

Similar Threads

  1. Replies: 4
    Last Post: March 21st, 2013, 03:21 PM
  2. Assigning values to objects.
    By LoganC in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 19th, 2012, 11:38 PM
  3. retrieve data from database using Hashmap (multiple values in one key)
    By ashin12 in forum Collections and Generics
    Replies: 2
    Last Post: April 4th, 2012, 06:22 AM
  4. [SOLVED] compare form values with database values
    By VaniRathna in forum Java Servlet
    Replies: 2
    Last Post: October 24th, 2011, 03:48 AM
  5. Character Values Inside of Number Values
    By bgroenks96 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 09:27 PM