Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 671593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:23:28+00:00 2026-05-14T00:23:28+00:00

I’m currently trying to construct a list of bean classes in Java from a

  • 0

I’m currently trying to construct a list of bean classes in Java from a flat description file formatted in csv. Concretely :

Here is the structure of the csv file :

MES_ID;GRP_PARENT_ID;GRP_ID;ATTR_ID
M1    ;             ;G1    ;A1
M1    ;             ;G1    ;A2
M1    ;G1           ;G2    ;A3
M1    ;G1           ;G2    ;A4
M1    ;G2           ;G3    ;A5
M1    ;             ;G4    ;A6
M1    ;             ;G4    ;A7
M1    ;             ;G4    ;A8
M2    ;             ;G1    ;A1
M2    ;             ;G1    ;A2
M2    ;             ;G2    ;A3
M2    ;             ;G2    ;A4

It corresponds to the hierarchical data structure :

M1
---G1
------A1
------A2
------G2
---------A3
---------A4
---------G3
------------A5
---G4
------A7
------A8
M2
---G1
------A1
------A2
---G2
------A3
------A4

Remarks :

  • A message M can have an infinite number of groups G and attributes A

  • A group G can have an infinite number of attributes and an infinite number of under-groups each of them having under-groups too

That beeing said, I’m trying to read this flat csv decription to store it in this structure of beans :

Map<String, MBean> messages = new HashMap<String, Mbean>();

==

public class MBean {
   private String mes_id;
   private Map<String, GBean> groups;
}

public class GBean {
   private String grp_id;
   private Map<String, ABean> attributes;
   private Map<String, GBean> underGroups;
}

public class ABean {
   private String attr_id;
}

Reading the csv file sequentially is ok and I’ve been investigating how to use recursion to store the description data, but couldn’t find a way.

Thanks in advance for any of your algorithmic ideas.

I hope it will put you in the mood of thinking about this … I’ve to admit that I’m out of ideas :s

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:23:28+00:00Added an answer on May 14, 2026 at 12:23 am

    Here is a solution, adding comments is left as an exercise…

    public class Test {
    
    public static void main(String[] args) {
        List<Record> records = new ArrayList<Record>() {
            {
                add(new Record("M1", "", "G1", "A1"));
                add(new Record("M1", "", "G1", "A2"));
    
                add(new Record("M1", "G1", "G2", "A3"));
                add(new Record("M1", "G1", "G2", "A4"));
            }
        };
    
        MessageContainer messageContainer = new MessageContainer();
        for (Record record : records) {
            messageContainer.addOrUpdateMessage(record);
        }
    
    }
    
    private static class Record {
    
        final String messageId;
        final String parentGroupId;
        final String groupId;
        final String attributeId;
    
        public Record(String messageId, String parentGroupId, String groupId, String attributeId) {
            super();
            this.messageId = messageId;
            this.parentGroupId = parentGroupId;
            this.groupId = groupId;
            this.attributeId = attributeId;
        }
    
    }
    
    private static class MessageContainer {
    
        Map<String, MBean> messages = new HashMap<String, MBean>();
    
        public void addOrUpdateMessage(Record record) {
            MBean mBean = messages.get(record.messageId);
            if (mBean == null) {
                mBean = new MBean(record.messageId);
                messages.put(record.messageId, mBean);
            }
            mBean.addOrUpdateGroup(record);
        }
    }
    
    private static class MBean {
        private final String mes_id;
        private final Map<String, GBean> groups = new HashMap<String, GBean>();
    
        public MBean(String mesId) {
            super();
            mes_id = mesId;
        }
    
        public void addOrUpdateGroup(Record record) {
            String groupToHandle = (record.parentGroupId != "" ? record.parentGroupId : record.groupId);
            GBean gBean = groups.get(groupToHandle);
            if (gBean == null) {
                gBean = new GBean(groupToHandle);
                groups.put(groupToHandle, gBean);
            }
            gBean.addOrUpdateGroup(record);
        }
    }
    
    private static class GBean {
        private final String groupId;
        private final Map<String, ABean> attributes = new HashMap<String, ABean>();
        private final Map<String, GBean> underGroups = new HashMap<String, GBean>();
    
        public GBean(String groupId) {
            super();
            this.groupId = groupId;
        }
    
        public void addOrUpdateGroup(Record record) {
            if (groupId == record.parentGroupId) {
    
                GBean child = underGroups.get(record.groupId);
                if (child == null) {
                    child = new GBean(record.groupId);
                    underGroups.put(record.groupId, child);
                }
                child.addOrUpdateGroup(record);
    
            } else if (groupId == record.groupId) {
                attributes.put(record.attributeId, new ABean(record.attributeId));
            } else {
                throw new RuntimeException("Unexpected state [recordParentGroupId="+record.parentGroupId+", recordGroupId="+record.groupId+", groupId="+groupId+"]");
    
            }
    
        }
    
        private static class ABean {
            private final String attr_id;
            public ABean(String attrId) {
                super();
                attr_id = attrId;
            }
    
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 351k
  • Answers 351k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Basically in very brief and high-level terms, what you need… May 14, 2026 at 7:21 am
  • Editorial Team
    Editorial Team added an answer SELECT date(time_purchased), order_total FROM purchases WHERE time_purchased BETWEEN '2010-04-15 00:00:00'… May 14, 2026 at 7:21 am
  • Editorial Team
    Editorial Team added an answer You can issue redirects with a given status code via… May 14, 2026 at 7:21 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.