/merdiven

A generic statement builder tool for all-purpose

Primary LanguageJavaApache License 2.0Apache-2.0

TOC

0 Introduction

merdiven-logo

Maven Central

Merdiven is a simple generic statement builder for generic purposes. During different development projects, there was the need to have a generic statement builder that produces immutable statements thus I've created this open-source project.

Go back to TOC

1 Setup

You can simply add merdiven to your project as a maven dependency;

<dependency>
    <groupId>io.github.bzdgn</groupId>
    <artifactId>merdiven</artifactId>
    <version>0.0.2</version>
</dependency>

Go back to TOC

2 Example

Merdiven is easy to use. A simple example to produce a statement is as follows to produce a json object;

Statement statement = builder
		.openBracket()
			.openCurlyBracket()
				.add("name", "Levent", ":", "\"")
				.and(",")
				.add("id", "717", ":", "\"")
				.and(",")
				.add("isOccupied", "true", ":", "\"")
				.and(",")
				.addParam("info", "\"")
				.eq(":")
				.openCurlyBracket()
					.addParam("languages", "\"")
					.eq(":")
					.openBracket()
						.addParam("english", "\"")
						.and(",")
						.addParam("turkish", "\"")
						.and(",")
						.addParam("dutch", "\"")
					.closeBracket()
				.closeCurlyBracket()
			.closeCurlyBracket()
		.closeBracket()
		.build();
		
System.out.println(statement.toString());

And the output will be as follows;

[ { "name":"Levent" , "id":"717" , "isOccupied":"true" , "info" : { "languages" : [ "english" , "turkish" , "dutch" ] } } ]

Pretty printed output will be;

[
    {
        "name": "Levent",
        "id": "717",
        "isOccupied": "true",
        "info": {
            "languages": [
                "english",
                "turkish",
                "dutch"
            ]
        }
    }
]

Or to make an undefined query by your own as follows;

Statement statement = builder
        .add("firstName", "Levent")
        .and()
        .add("lastName", "Divilioglu")
        .add("number", "717")
        .add("github", "bzdgn")
        .openBracket()
            .add("type", "Engineer")
            .or()
            .add("type", "Guitarist")
        .closeBracket()
        .build();
        
System.out.println(statement.toString());

And the string output is as follows;

firstName="Levent" and lastName="Divilioglu" number="717" github="bzdgn" [ type="Engineer" or type="Guitarist" ]

Go back to TOC

3 TODO List

  • Field to list structure to be added.
  • Configuration object to be implemented for generic templates
  • Pretty Print functionality to be added

Go back to TOC

4 Future Plan

As a Camel user, I want to dig into the Camel components and want to create a camel component for merdiven. Also json/xml conversions may be added to the project.

Go back to TOC