Sign in
Log inSign up

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! 🙂

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct