-2

I am trying to pass an object say Order where it checks against its previous value and updates a field.

Order(orderId, item_id, quantity, price, discount_type, discount_amount)

So the first time I get Order Data with a value Order("o1", "i1", 1, 100, null, null).

Second record I would be getting for the same order with details Order("o1", "i1", 2, 200, null, null).

When I process the 2nd order, I want to update the Order object with values Order("o1", "i1", 2, 150, "discountType1", 50(calculate the value prev_price - curr_price)).

I am trying to create a drools application, where I want to send a single Order object with both, current and previous, values and apply rules in drools xsl file using java.

Can someone help me how do I set the current and previous instance values of order in one object.

csalmhof
  • 1,820
  • 2
  • 15
  • 24
chintu
  • 29
  • 3
  • 1
    Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – Yoshikage Kira Jun 09 '21 at 17:37
  • Please show what you've attempted so far in solving your problem. At minimum, for Drools, you should share what the data you're passing into working memory looks like, your attempt at a decision table (screenshot of the XLSX is fine), and what is going wrong with your attempt. Also the unit tests you're using to test/verify your implementation are generally helpful. – Roddy of the Frozen Peas Jun 09 '21 at 21:48

1 Answers1

0

If you google for 'java pair implementation' you'll get many working approaches.
Java Pair<T,N> is also a discussion on SO, which haters closed (we have many here).
If you have few rules to deal only with pairs comparison, then generalized class would be sufficient, if you have more rules which potentially will be getting more complicated, I'd extend from common 'pair' to give business meaning to your pair to keep supportability in mind. You should check and compare each field in your rules if you want some logic to be applied per field basis.

Mike
  • 20,010
  • 25
  • 97
  • 140