My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How would you model/represent compound expressions with Classes?

Default profile photo
Anonymous
·Feb 4, 2018

I have to store and subsequently evaluate compound expressions in my application. An example of a compound expression would be:

((name == 'John Doe') && (age < 25))

The way that I need to store these expressions, is using a JSON representation. For example, the above expression would end up being something like:

{
 "and": [
    {
        "=": [
            {
                "variable": "name"
            },
            "John Doe"
          ]
    },
    {
        "lt": [
            {
                "variable": "age"
            },
            25
        ]
    }
  ]
}

The general format is <operator>: [<operands>]

I'm finding it a little difficult to map something like this to Classes in my Java application. Would really appreciate some help here! 🙂