{"id":21179032,"url":"https://github.com/spaceavocado/jillogical","last_synced_at":"2025-03-14T18:44:28.194Z","repository":{"id":254496053,"uuid":"845660487","full_name":"spaceavocado/jillogical","owner":"spaceavocado","description":"A micro conditional java engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.","archived":false,"fork":false,"pushed_at":"2025-02-24T05:40:28.000Z","size":79,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-24T06:33:54.853Z","etag":null,"topics":["expression","expression-evaluator","logical"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spaceavocado.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"license.md","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-21T17:18:01.000Z","updated_at":"2025-02-24T05:40:31.000Z","dependencies_parsed_at":"2024-11-20T22:38:30.824Z","dependency_job_id":null,"html_url":"https://github.com/spaceavocado/jillogical","commit_stats":null,"previous_names":["spaceavocado/jillogical"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fjillogical","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fjillogical/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fjillogical/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaceavocado%2Fjillogical/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spaceavocado","download_url":"https://codeload.github.com/spaceavocado/jillogical/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243629556,"owners_count":20322079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expression","expression-evaluator","logical"],"created_at":"2024-11-20T17:28:02.637Z","updated_at":"2025-03-14T18:44:28.185Z","avatar_url":"https://github.com/spaceavocado.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (java)illogical\n\nA micro conditional engine used to parse the logical and comparison expressions, evaluate an expression in data context, and provide access to a text form of the given expression.\n\n\u003e Revision: Aug 26, 2024.\n\nOther implementations:\n- [TS/JS](https://github.com/spaceavocado/illogical)\n- [GO](https://github.com/spaceavocado/goillogical)\n- [Python](https://github.com/spaceavocado/pyillogical)\n- [C#](https://github.com/spaceavocado/cillogical)\n- [Odin](https://github.com/spaceavocado/oillogical)\n\n## About\n\nThis project has been developed to provide C// implementation of [spaceavocado/illogical](https://github.com/spaceavocado/illogical).\n\n\n## Getting Started\nYou can install the **(jave)illogical** from [maven central repository](https://central.sonatype.com/artifact/com.spaceavocado.jillogical/jillogical).\n\n\n**Table of Content**\n\n---\n\n- [(java)illogical](#javaillogical)\n  - [About](#about)\n  - [Getting Started](#getting-started)\n- [Basic Usage](#basic-usage)\n  - [Evaluate](#evaluate)\n  - [Statement](#statement)\n  - [Parse](#parse)\n  - [IEvaluable](#ievaluable)\n    - [Simplify](#simplify)\n    - [Serialize](#serialize)\n- [Working with Expressions](#working-with-expressions)\n  - [Evaluation Data Context](#evaluation-data-context)\n    - [Accessing Array Element:](#accessing-array-element)\n    - [Accessing Array Element via Reference:](#accessing-array-element-via-reference)\n    - [Nested Referencing](#nested-referencing)\n    - [Composite Reference Key](#composite-reference-key)\n    - [Data Type Casting](#data-type-casting)\n  - [Operand Types](#operand-types)\n    - [Value](#value)\n    - [Reference](#reference)\n    - [Collection](#collection)\n  - [Comparison Expressions](#comparison-expressions)\n    - [Equal](#equal)\n    - [Not Equal](#not-equal)\n    - [Greater Than](#greater-than)\n    - [Greater Than or Equal](#greater-than-or-equal)\n    - [Less Than](#less-than)\n    - [Less Than or Equal](#less-than-or-equal)\n    - [In](#in)\n    - [Not In](#not-in)\n    - [Prefix](#prefix)\n    - [Suffix](#suffix)\n    - [Overlap](#overlap)\n    - [None](#none)\n    - [Present](#present)\n  - [Logical Expressions](#logical-expressions)\n    - [And](#and)\n    - [Or](#or)\n    - [Nor](#nor)\n    - [Xor](#xor)\n    - [Not](#not)\n- [Engine Options](#engine-options)\n  - [Reference Serialize Options](#reference-serialize-options)\n    - [From](#from)\n    - [To](#to)\n  - [Collection Serialize Options](#collection-serialize-options)\n    - [Escape Character](#escape-character)\n  - [Simplify Options](#simplify-options)\n    - [Ignored Paths](#ignored-paths)\n    - [Ignored Paths RegEx](#ignored-paths-regex)\n  - [Operator Mapping](#operator-mapping)\n- [Contributing](#contributing)\n- [License](#license)\n\n---\n\n\n# Basic Usage\n\n```java\nimport com.spaceavocado.jillogical.Illogical;\n\n// Create a new instance of the engine\nvar illogical = new Illogical();\n\n// Evaluate an expression\nillogical.evaluate(new Object[] { \"==\", 1, 1 }, null);\n```\n\n\u003e For advanced usage, please [Engine Options](#engine-options).\n\n## Evaluate\n\nEvaluate comparison or logical expression:\n\n`illogical.Evaluate(`[Comparison Expression](#comparison-expressions) or [Logical Expression](#logical-expressions), [Evaluation Data Context](#evaluation-data-context)`)` =\u003e `bool`\n\n**Example**\n\n```java\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"name\", \"peter\");\n\n// Comparison expression\nillogical.evaluate(new Object[]{\"==\", 5, 5}, context);\nillogical.evaluate(new Object[]{\"==\", \"circle\", \"circle\"}, context);\nillogical.evaluate(new Object[]{\"==\", true, true }, context);\nillogical.evaluate(new Object[]{\"==\", \"$name\", \"peter\"}, context);\nillogical.evaluate(new Object[]{\"NULL\", \"$RefA\"}, context);\n\n// Logical expression\nillogical.evaluate(new Object[] {\n    \"AND\",\n    new Object[] { \"==\", 5, 5 },\n    new Object[] { \"==\", 10, 10 }\n}, context);\n\nillogical.evaluate(new Object[] {\n    \"AND\",\n    new Object[] { \"==\", \"circle\", \"circle\" },\n    new Object[] { \"==\", 10, 10 }\n}, context);\n\nillogical.evaluate(new Object[] {\n    \"OR\",\n    new Object[] { \"==\", \"$name\", \"peter\" },\n    new Object[] { \"==\", 5, 10 }\n}, context);\n```\n\n## Statement\n\nGet expression string representation:\n\n`illogical.Statement(`[Comparison Expression](#comparison-expressions) or [Logical Expression](#logical-expressions)`)` =\u003e `str`\n\n**Example**\n\n```java\n// Comparison expression\n\nillogical.statement(new Object[] { \"==\", 5, 5 }); // (5 == 5)\nillogical.statement(new Object[] { \"==\", \"circle\", \"circle\" }); // (\"circle\" == \"circle\")\nillogical.statement(new Object[] { \"==\", true, true }); // (True == True)\nillogical.statement(new Object[] { \"==\", \"$name\", \"peter\" }); // ({name} == \"peter\")\nillogical.statement(new Object[] { \"NONE\", \"$RefA\" }); // ({RefA} \u003cis none\u003e)\n\n// Logical expression\n\nillogical.statement(new Object[] {\n    \"AND\",\n    new Object[] { \"==\", 5, 5 },\n    new Object[] { \"==\", 10, 10 }\n}); // ((5 == 5) AND (10 == 10))\n\nillogical.statement(new Object[] {\n    \"AND\",\n    new Object[] { \"==\", \"circle\", \"circle\" },\n    new Object[] { \"==\", 10, 10 }\n}); // ((\"circle\" == \"circle\") AND (10 == 10))\n\nillogical.statement(new Object[] {\n    \"OR\",\n    new Object[] { \"==\", \"$name\", \"peter\" },\n    new Object[] { \"==\", 5, 10 }\n}); // (({name} == \"peter\") OR (5 == 10))\n```\n\n## Parse\n\nParse the expression into a **IEvaluable** object, i.e. it returns the parsed self-evaluable condition expression.\n\n`illogical.parse(`[Comparison Expression](#comparison-expressions) or [Logical Expression](#logical-expressions)`)` =\u003e `IEvaluable`\n\n## IEvaluable\n\n- `evaluable.Evaluate(context)` please see [Evaluation Data Context](#evaluation-data-context).\n- `evaluable.Simplify(context)` please see [Simplify](#simplify).\n- `evaluable.Serialize()` please see [Serialize](#serialize).\n- `$\"{evaluable}\" | evaluable.ToString()` please see [Statement](#statement).\n\n**Example**\n\n```java\nvar evaluable = illogical.parse(new Object[] { \"==\", \"$name\", \"peter\" });\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"name\", \"peter\");\n\nevaluable.evaluate(context); // true\n\nSystem.out.println(evaluable); // ({name} == \"peter\")\n```\n\n### Simplify\n\nSimplifies an expression with a given context. This is useful when you already have some of\nthe properties of context and wants to try to evaluate the expression.\n\n**Example**\n\n```java\nvar evaluable = illogical.parse(new Object[] {\n  \"AND\",\n  new Object[] { \"==\", \"$a\", 10 },\n  new Object[] { \"==\", \"$b\", 20 }\n});\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"a\", 10);\nevaluable.simplify(context); // ({b} == 20)\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"a\", 20);\nevaluable.simplify(context); // false\n```\n\nValues not found in the context will cause the parent operand not to be evaluated and returned\nas part of the simplified expression.\n\nIn some situations we might want to evaluate the expression even if referred value is not\npresent. You can provide a list of keys that will be strictly evaluated even if they are not\npresent in the context.\n\n**Example**\n\n```java\nimport com.spaceavocado.jillogical.kernel.operand.reference.ISimplifyOptions;\nimport java.util.regex.Pattern;\n\nvar simplifyOptions = new ISimplifyOptions() {\n    @Override\n    public String[] ignoredPaths() {\n        return new String[] {};\n    }\n\n    @Override\n    public Pattern[] ignoredPathsRx() {\n        return new Pattern[] { Pattern.compile(\"^ignored\") };\n    }\n};\n\nvar illogical = new Illogical(simplifyOptions);\n\nvar evaluable = illogical.parse(new Object[] {\n    \"AND\",\n    new Object[] { \"==\", \"$a\", 10 },\n    new Object[] { \"==\", \"$ignored\", 20 }\n});\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"a\", 10);\n\nevaluable.simplify(new Dictionary\u003cstring, object?\u003e { { \"a\", 10 } }); // false\n// $ignored\" will be evaluated to null.\n```\n\nAlternatively we might want to do the opposite and strictly evaluate the expression for all referred\nvalues not present in the context except for a specified list of optional keys.\n\n**Example**\n\n```java\nimport com.spaceavocado.jillogical.kernel.operand.reference.ISimplifyOptions;\nimport java.util.regex.Pattern;\n\nvar simplifyOptions = new ISimplifyOptions() {\n    @Override\n    public String[] ignoredPaths() {\n        return new String[] { \"ignored\" };\n    }\n\n    @Override\n    public Pattern[] ignoredPathsRx() {\n        return new Pattern[] { };\n    }\n};\n\nvar illogical = new Illogical(simplifyOptions);\n\nvar evaluable = illogical.parse(new Object[] {\n    \"OR\",\n    new Object[] { \"==\", \"$a\", 10 },\n    new Object[] { \"==\", \"$b\", 20 },\n    new Object[] { \"==\", \"$c\", 20 }\n});\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"a\", 10);\n\nevaluable.simplify(context); // ({a} == 10)\n// except for \"$b\" everything not in context will be evaluated to null.\n```\n\n### Serialize\n\nSerializes an expression into the raw expression form, reverse the parse operation.\n\n**Example**\n\n```java\nevaluable = illogical.parse(new Object[] {\n  \"AND\",\n  new Object[] { \"==\", \"$a\", 10 },\n  new Object[] { \"==\", 10, 20}\n});\n\nevaluable.serialize()\n// new Object[] { \"AND\", new Object[] { \"==\", \"$a\", 10 }, new Object[] { \"==\", 10, 20 } }\n```\n\n# Working with Expressions\n\n## Evaluation Data Context\n\nThe evaluation data context is used to provide the expression with variable references, i.e. this allows for the dynamic expressions. The data context is object with properties used as the references keys, and its values as reference values.\n\n\u003e Valid reference values: Dictionary, string, char, int, float, decimal, double, array of (bool, string, char, int, float).\n\nTo reference the nested reference, please use \".\" delimiter, e.g.:\n`$address.city`\n\n### Accessing Array Element:\n\n`$options[1]`\n\n### Accessing Array Element via Reference:\n\n`$options[{index}]`\n\n- The **index** reference is resolved within the data context as an array index.\n\n### Nested Referencing\n\n`$address.{segment}`\n\n- The **segment** reference is resolved within the data context as a property key.\n\n### Composite Reference Key\n\n`$shape{shapeType}`\n\n- The **shapeType** reference is resolved within the data context, and inserted into the outer reference key.\n- E.g. **shapeType** is resolved as \"**B**\" and would compose the **$shapeB** outer reference.\n- This resolution could be n-nested.\n\n### Data Type Casting\n\n`$payment.amount.(Type)`\n\nCast the given data context into the desired data type before being used as an operand in the evaluation.\n\n\u003e Note: If the conversion is invalid, then a warning message is being logged.\n\nSupported data type conversions:\n\n- .(String): cast a given reference to String.\n- .(Number): cast a given reference to Number.\n- .(Integer): cast a given reference to Integer.\n- .(Float): cast a given reference to Float.\n- .(Boolean): cast a given reference to Boolean.\n\n**Example**\n\n```java\n// Data context\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"name\", \"peter\");\ncontext.put(\"country\", \"canada\");\ncontext.put(\"age\", 21);\ncontext.put(\"options\", new Object[]{ 1, 2, 3 });\n\nvar address = new HashMap\u003cString, Object\u003e();\naddress.put(\"city\", \"Toronto\");\naddress.put(\"country\", \"Canada\");\ncontext.put(\"address\", address);\n\ncontext.put(\"index\", 2);\ncontext.put(\"segment\", \"city\");\ncontext.put(\"shapeA\", \"box\");\ncontext.put(\"shapeB\", \"circle\");\ncontext.put(\"shapeType\", \"B\");\n\n// Evaluate an expression in the given data context\n\nillogical.evaluate(new Object[] { \"\u003e\", \"$age\", 20 }, context); // true\nillogical.evaluate(new Object[] { \"==\", \"$address.city\", \"Toronto\" }, context); // true\n\n// Accessing Array Element\nillogical.evaluate(new Object[] { \"==\", \"$options[1]\", 2 }, context); // true\n\n// Accessing Array Element via Reference\nillogical.evaluate(new Object[] { \"==\", \"$options[{index}]\", 3 }, context); // true\n\n// Nested Referencing\nillogical.evaluate(new Object[] { \"==\", \"$address.{segment}\", \"Toronto\" }, context); // true\n\n// Composite Reference Key\nillogical.evaluate(new Object[] { \"==\", \"$shape{shapeType}\", \"circle\" }, context); // true\n\n// Data Type Casting\nillogical.evaluate(new Object[] { \"==\", \"$age.(String)\", \"21\" }, context); // true\n```\n\n## Operand Types\n\nThe [Comparison Expression](#comparison-expression) expect operands to be one of the below:\n\n### Value\n\nSimple value types: string, char, int, float, decimal, double, bool, null.\n\n**Example**\n\n```java\nvar val1 = 5;\nvar var2 = \"cirle\";\nvar var3 = true;\n\nillogical.parse(new Object[] {\n    \"AND\",\n    new Object[] { \"==\", val1, var2 },\n    new Object[] { \"==\", var3, var3 }\n});\n```\n\n### Reference\n\nThe reference operand value is resolved from the [Evaluation Data Context](#evaluation-data-context), where the the operands name is used as key in the context.\n\nThe reference operand must be prefixed with `$` symbol, e.g.: `$name`. This might be customized via [Reference Predicate Parser Option](#reference-predicate).\n\n**Example**\n\n| Expression                    | Data Context      |\n| ----------------------------- | ----------------- |\n| `[\"==\", \"$age\", 21]`          | `{age: 21}`       |\n| `[\"==\", \"circle\", \"$shape\"] ` | `{shape: \"circle\"}` |\n| `[\"==\", \"$visible\", true]`    | `{visible: true}` |\n\n### Collection\n\nThe operand could be an array mixed from [Value](#value) and [Reference](#reference).\n\n**Example**\n\n| Expression                               | Data Context                        |\n| ---------------------------------------- | ----------------------------------- |\n| `[\"IN\", [1, 2], 1]`                      | `null`                                |\n| `[\"IN\", \"circle\", [\"$shapeA\", \"$shapeB\"] ` | `{shapeA: \"circle\", shapeB: \"box\"}` |\n| `[\"IN\", [\"$number\", 5], 5]`                | `{number: 3}`                       |\n\n## Comparison Expressions\n\n### Equal\n\nExpression format: `[\"==\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string, char, int, float, decimal, double, bool, null.\n\n```json\n[\"==\", 5, 5]\n```\n\n```java\nillogical.evaluate(new Object[] { \"==\", 5, 5 }, context); // true\n```\n\n### Not Equal\n\nExpression format: `[\"!=\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string, char, int, float, decimal, double, bool, null.\n\n```json\n[\"!=\", \"circle\", \"square\"]\n```\n\n```java\nillogical.evaluate(new Object[] { \"!=\", \"circle\", \"square\" }, context); // true\n```\n\n### Greater Than\n\nExpression format: `[\"\u003e\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: int, float.\n\n```json\n[\"\u003e\", 10, 5]\n```\n\n```java\nillogical.evaluate(new Object[] { \"\u003e\", 10, 5 }, context); // true\n```\n\n### Greater Than or Equal\n\nExpression format: `[\"\u003e=\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: int, float.\n\n```json\n[\"\u003e=\", 5, 5]\n```\n\n```java\nillogical.evaluate(new Object[] { \"\u003e=\", 5, 5 }, context); // true\n```\n\n### Less Than\n\nExpression format: `[\"\u003c\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: int, float.\n\n```json\n[\"\u003c\", 5, 10]\n```\n\n```java\nillogical.evaluate(new Object[] { \"\u003c\", 5, 10 }, context); // true\n```\n\n### Less Than or Equal\n\nExpression format: `[\"\u003c=\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: int, float.\n\n```json\n[\"\u003c=\", 5, 5]\n```\n\n```java\nillogical.evaluate(new Object[] { \"\u003c=\", 5, 5 }, context); // true\n```\n\n### In\n\nExpression format: `[\"IN\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string, char, int, float, decimal, double, bool, null and an array of (string, char, int, float, decimal, double, bool, null).\n\n```json\n[\"IN\", 5, [1, 2, 3, 4, 5]]\n[\"IN\", [\"circle\", \"square\", \"triangle\"], \"square\"]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"IN\", 5, new Object[] { 1, 2, 3, 4, 5 }\n}, context); // true\n\nillogical.evaluate(new Object[] {\n    \"IN\", new Object[] { \"circle\", \"square\", \"triangle\" }, \"square\" },\ncontext); // true\n```\n\n### Not In\n\nExpression format: `[\"NOT IN\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string, char, int, float, decimal, double, bool, null and array of (string, char, int, float, decimal, double, bool, null).\n\n```json\n[\"IN\", 10, [1, 2, 3, 4, 5]]\n[\"IN\", [\"circle\", \"square\", \"triangle\"], \"oval\"]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"NOT IN\", 10, new Object[] { 1, 2, 3, 4, 5 }\n}, context); // true\n\nillogical.evaluate(new Object[] {\n    \"NOT IN\", new Object[] { \"circle\", \"square\", \"triangle\" }, \"oval\" },\ncontext); // true\n```\n\n### Prefix\n\nExpression format: `[\"PREFIX\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string.\n\n- Left operand is the PREFIX term.\n- Right operand is the tested word.\n\n```json\n[\"PREFIX\", \"hemi\", \"hemisphere\"]\n```\n\n```java\nillogical.evaluate(new Object[] { \"PREFIX\", \"hemi\", \"hemisphere\" }, context) // true\nillogical.evaluate(new Object[] { \"PREFIX\", \"hemi\", \"sphere\" }, context) // false\n```\n\n### Suffix\n\nExpression format: `[\"SUFFIX\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: string.\n\n- Left operand is the tested word.\n- Right operand is the SUFFIX term.\n\n```json\n[\"SUFFIX\", \"establishment\", \"ment\"]\n```\n\n```java\nillogical.evaluate(new Object[] { \"SUFFIX\", \"establishment\", \"ment\" }, context) // true\nillogical.evaluate(new Object[] { \"SUFFIX\", \"establish\", \"ment\" }, context) // false\n```\n\n### Overlap\n\nExpression format: `[\"OVERLAP\", `[Left Operand](#operand-types), [Right Operand](#operand-types)`]`.\n\n\u003e Valid operand types: list; set; tuple of (string, char, int, float, decimal, double, bool, null).\n\n```json\n[\"OVERLAP\", [1, 2], [1, 2, 3, 4, 5]]\n[\"OVERLAP\", [\"circle\", \"square\", \"triangle\"], [\"square\"]]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"OVERLAP\", new Object[] { 1, 2, 6 }, new Object[] { 1, 2, 3, 4, 5 }\n}, context); // true\n\nillogical.evaluate(new Object[] {\n    \"OVERLAP\", new Object[] {\"circle\", \"square\", \"triangle\" }, new Object[] {\"square\", \"oval\" }\n}, context); // true\n```\n\n### None\n\nExpression format: `[\"NONE\", `[Reference Operand](#reference)`]`.\n\n```json\n[\"NONE\", \"$RefA\"]\n```\n\n```java\nillogical.evaluate(new Object[] { \"NONE\", \"RefA\" }, null); // true\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"RefA\", 10);\nillogical.evaluate(new Object[] { \"NONE\", \"RefA\" }, context); // false\n```\n\n### Present\n\nEvaluates as FALSE when the operand is UNDEFINED or NULL.\n\nExpression format: `[\"PRESENT\", `[Reference Operand](#reference)`]`.\n\n```json\n[\"PRESENT\", \"$RefA\"]\n```\n\n```java\nillogical.evaluate(new Object[] { \"PRESENT\", \"RefA\" }, null); // false\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"RefA\", 10);\nillogical.evaluate(new Object[] { \"PRESENT\", \"RefA\" }, context); // true\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"RefA\", false);\nillogical.evaluate(new Object[] { \"PRESENT\", \"RefA\" }, context); // true\n\nvar context = new HashMap\u003cString, Object\u003e();\ncontext.put(\"RefA\", \"val\");\nillogical.evaluate(new Object[] { \"PRESENT\", \"RefA\" }, context); // true\n```\n\n## Logical Expressions\n\n### And\n\nThe logical AND operator returns the bool value TRUE if both operands are TRUE and returns FALSE otherwise.\n\nExpression format: `[\"AND\", Left Operand 1, Right Operand 2, ... , Right Operand N]`.\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"AND\", [\"==\", 5, 5], [\"==\", 10, 10]]\n```\n\n```java\nillogical.evaluate(new object[] {\n    \"AND\",\n    new Object[] { \"==\", 5, 5 },\n    new Object[] { \"==\", 10, 10 }\n}, context); // true\n```\n\n### Or\n\nThe logical OR operator returns the bool value TRUE if either or both operands is TRUE and returns FALSE otherwise.\n\nExpression format: `[\"OR\", Left Operand 1, Right Operand 2, ... , Right Operand N]`.\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"OR\", [\"==\", 5, 5], [\"==\", 10, 5]]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"OR\",\n    new Object[] { \"==\", 5, 5 },\n    new Object[] { \"==\", 10, 5 }\n}, context); // true\n```\n\n### Nor\n\nThe logical NOR operator returns the bool value TRUE if both operands are FALSE and returns FALSE otherwise.\n\nExpression format: `[\"NOR\", Left Operand 1, Right Operand 2, ... , Right Operand N]`\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"NOR\", [\"==\", 5, 1], [\"==\", 10, 5]]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"NOR\",\n    new Object[] { \"==\", 5, 1 },\n    new Object[] { \"==\", 10, 5 }\n}, context); // true\n```\n\n### Xor\n\nThe logical NOR operator returns the bool value TRUE if both operands are FALSE and returns FALSE otherwise.\n\nExpression format: `[\"XOR\", Left Operand 1, Right Operand 2, ... , Right Operand N]`\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"XOR\", [\"==\", 5, 5], [\"==\", 10, 5]]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"XOR\",\n    new Object[] { \"==\", 5, 5 },\n    new Object[] { \"==\", 10, 5 }\n}, context); // true\n```\n\n```json\n[\"XOR\", [\"==\", 5, 5], [\"==\", 10, 10]]\n```\n\n```java\nillogical.evaluate(new Object[] {\n    \"XOR\",\n    new Object[] { \"==\", 5, 5 },\n    new Object[] { \"==\", 10, 10 }\n}, context); // false\n```\n\n### Not\n\nThe logical NOT operator returns the bool value TRUE if the operand is FALSE, TRUE otherwise.\n\nExpression format: `[\"NOT\", Operand]`\n\n\u003e Valid operand types: [Comparison Expression](#comparison-expressions) or [Nested Logical Expression](#logical-expressions).\n\n```json\n[\"NOT\", [\"==\", 5, 5]]\n```\n\n```java\nillogical.evaluate(new Object[] { \"NOT\", new Object[] { \"==\", 5, 5 } }, context); // true\n```\n\n# Engine Options\n\n## Reference Serialize Options\n\n**Usage**\n\n```java\nimport com.spaceavocado.jillogical.kernel.operand.reference.ISerializeOptions;\n\nvar serializeOptions = new ISerializeOptions() {\n    @Override\n    public String from(String operand) {\n        return operand.length() \u003e 2 \u0026\u0026 operand.startsWith(\"__\")\n            ? operand.substring(2)\n            : null;\n    }\n\n    @Override\n    public String to(String operand) {\n        return String.format(\"__%s\", operand);\n    }\n};\n\nvar illogical = new Illogical(serializeOptions);\n```\n\n### From\n\nA function used to determine if the operand is a reference type, if so, return a raw value operand value\n\n**Return value:**\n\n- `string` = reference type\n- `null` = value type\n\n**Default reference predicate:**\n\n\u003e The `$` symbol at the begging of the operand is used to predicate the reference type., E.g. `$State`, `$Country`.\n\n### To\n\nA function used to transform the operand into the reference annotation stripped form. I.e. remove any annotation used to detect the reference type. E.g. \"$Reference\" =\u003e \"Reference\".\n\n\u003e **Default reference transform:**\n\u003e It removes the `$` symbol at the begging of the operand name.\n\n## Collection Serialize Options\n\n**Usage**\n\n```java\nvar illogical = new Illogical('*');\n```\n\n### Escape Character\n\nCharter used to escape fist value within a collection, if the value contains operator value.\n\n**Example**\n- `[\"==\", 1, 1]` // interpreted as EQ expression\n- `[\"\\==\", 1, 1]` // interpreted as a collection\n\n\u003e **Default escape character:**\n\u003e `\\`\n\n## Simplify Options\n\nOptions applied while an expression is being simplified.\n\n**Usage**\n\n```java\nimport com.spaceavocado.jillogical.kernel.operand.reference.ISimplifyOptions;\nimport java.util.regex.Pattern;\n\nvar simplifyOptions = new ISimplifyOptions() {\n    @Override\n    public String[] ignoredPaths() {\n        return new String[] { \"ignored\" };\n    }\n\n    @Override\n    public Pattern[] ignoredPathsRx() {\n        return new Pattern[] { Pattern.compile(\"^ignored\") };\n    }\n};\n\nvar illogical = new Illogical(simplifyOptions);\n```\n\n### Ignored Paths\n\nReference paths which should be ignored while simplification is applied. Must be an exact match.\n\n### Ignored Paths RegEx\n\nReference paths which should be ignored while simplification is applied. Matching regular expression patterns.\n\n## Operator Mapping\n\nMapping of the operators. The key is unique operator key, and the value is the key used to represent the given operator in the raw expression.\n\n**Usage**\n\n```java\nimport com.spaceavocado.jillogical.kernel.parser.Parser;\n\nvar operatorMapping = new HashMap\u003cOperator, String\u003e(Parser.DEFAULT_OPERATOR_MAPPING);\noperatorMapping.put(Operator.EQ, \"IS\");\n\nvar illogical = new Illogical(operatorMapping);\n```\n\n**Default operator mapping:**\n\n```java\nvar DEFAULT_OPERATOR_MAPPING = Map.ofEntries(\n    // Logical\n    entry(Operator.AND, \"AND\"),\n    entry(Operator.OR, \"OR\"),\n    entry(Operator.NOR, \"NOR\"),\n    entry(Operator.XOR, \"XOR\"),\n    entry(Operator.NOT, \"NOT\"),\n    // Comparison\n    entry(Operator.EQ, \"==\"),\n    entry(Operator.NE, \"!=\"),\n    entry(Operator.GT, \"\u003e\"),\n    entry(Operator.GE, \"\u003e=\"),\n    entry(Operator.LT, \"\u003c\"),\n    entry(Operator.LE, \"\u003c=\"),\n    entry(Operator.NONE, \"NONE\"),\n    entry(Operator.PRESENT, \"PRESENT\"),\n    entry(Operator.IN, \"IN\"),\n    entry(Operator.NOTIN, \"NOT IN\"),\n    entry(Operator.OVERLAP, \"OVERLAP\"),\n    entry(Operator.PREFIX, \"PREFIX\"),\n    entry(Operator.SUFFIX, \"SUFFIX\")\n);\n```\n\n---\n\n# Contributing\n\nSee [contributing.md](https://github.com/spaceavocado/pyillogical/blob/master/contributing.md).\n\n# License\n\nIllogical is released under the MIT license. See [license.md](https://github.com/spaceavocado/pyillogical/blob/master/license.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaceavocado%2Fjillogical","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspaceavocado%2Fjillogical","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaceavocado%2Fjillogical/lists"}