Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

java - Datastructure is best for rules like Item can not be Shipped to a particular postalCode

I have a Shipping Restriction table with Rules like:
ProductClass:'Suites' Can not be Shipped to 'Georgia',
ProductClass:'Body Spray' and Hazmat:True can not be shipped to Postal Code:322001
ProductClass:'Baby Toys' can not be shipped to 'US',
and we have a rule like, I Can not ship any item to 'Arizona' state.

ProductClass, Hazmat, and ShippingMethod are one group (zero or more properties can have values).
Same way PostalCode, state, country are another group(only one will be filled with value per rule).
This is configuration/static data and it will be huge(more than 10k rules)

RuleId Product Class Hazmat ShippingMethod Postal Code State Country
1 Suits Georgia
2 Body Spray TRUE 322001
3 Body Spray 322009
4 Baby Toys US
5 Guns Florida
6 Air Hawaii
7 Arizona
question from:https://stackoverflow.com/questions/66050764/datastructure-is-best-for-rules-like-item-can-not-be-shipped-to-a-particular-pos

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Given that the restriction table has 10k items, the first question is how many orders to you expect to need to handle.

If this number is relatively small, then just run each item and find if there are any lines that match what you need.

However, if this number very large, it will make sense to do some preprocessing beforehand and convert the restriction table into some data structure that makes checking the items easier.

The first data structure that comes to (my) mind is a nested object that hold one of the columns as a property. Then those hold more nested object with another column as property.

Essentially this would allow each line to check a number of properties in an object rather than finding a line in an array of 10k items.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...