Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to make nested data structure from a table in Java

Tags:

java

In my database I have a table which is show in below. Now I want to make a nested data structure to draw on a view by an algorithm to transfer data from table to this

Tables -> Seats -> Rounds -> Dish_names

Note that -> stands for 'contain'

Could anyone have a clean way to do this in Java. Thanks!

enter image description here

like image 386
Kevin Duong Avatar asked Apr 28 '26 03:04

Kevin Duong


1 Answers

Not sure what you want exactly, but if you want a nested Java Object (entity) to correspond to the table, read on:

Since Tables contain Seats contain Rounds contain Dish_names, you start from the innermost entity (Dish):

Public class Dish{
  private int id; // an id  
  private String dish_name;
  // getters and setters
}

Your Rounds contain the Dishes

 Public class Round{
      private int id; // an id  
      private List<Dish> dishes;
      // getters and setters
    }

Your Seats contain the Rounds

Public class Seat{
      private int id; // an id  
      private List<Round> rounds;
      // getters and setters
    }

And finally you Tables contain the Seats

 Public class Table{
      private int id; //  
      private List<Seat> seats;
      // getters and setters
    }
like image 148
jmcg Avatar answered Apr 30 '26 16:04

jmcg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!