简体   繁体   中英

Design suggestion for decision tree like business logic

I am trying to design the data structure to support data that looks like the following for example, according to the first line if X<=15 and Y<=78.00 and X>625500 i need to populate Z as some value.

Whats the best way to design this so that the data storage and retrieval is efficient and elegant? Will tree work?

PS I dont want to store this data set in the database but prefer to store it in java data structures

Thanks a bunch

X Y Z
<= 15 <= 78.00 > 625,500
<= 15 <= 78.00 <= 625,500
<= 15 78.01 - 90.00 > 625,500
<= 15 78.01 - 90.00 <= 625,500
<= 15 > 90.00 > 625,500
<= 15 > 90.00 <= 625,500

Since your data is not a custom structure, I think its better if you treat one row as one object & then create it's collection.

For ex:

Class Row{
<variables for X, Y, Z>
<getter setter for X, Y, Z>
}

List<Row> myTable .....

myTable.add(row1);
myTable.add(row2);

Now with this, you an directly access any row that you want, just do myTable.get(3) to get 3rd row. Now in that object access XY to calculate Z & set in that object. You can create RowUtil.java to put methods for Z calculations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM