Giter Site home page Giter Site logo

flexbean's Introduction

FlexBean

Flexible Java Bean

Unlike dynamically typed languages like JavaScript, Java is a statically typed language. Although this is beneficial in some ways, somethimes you will need flexible containers to carry information in it. Because sometimes it is hard to write a Java Bean for every single data type. Furthermore it is impossible to write a Java Bean if you don't know data types and structure of the information beforehand.

For example, you are providing an SQL input to user and user is free to write any SQL to send to database. So it's up to users to write the SQL. That means resultset may have any number of columns with any type. This makes impossible to use regular Java beans to carry informatin. This is where FlexBean comes in. FlexBean provides a flexible class which lets you create any property with any type, any time. Not only that, you can also change type and value of properties in runtime.

Examples:

FlexBean personBean = new FlexBean();

// set some properties, property types automatically inferred.
personBean.set("name", "Ahmet Kaya");
personBean.set("birth", LocalDate.of(1957, 10, 28));
personBean.set("death", LocalDate.of(2000, 11, 16));


Period agePeriod = Period.between(
        personBean.valueOf("birth"),
        personBean.valueOf("death")
);

int age = agePeriod.getYears();

personBean.set("age", age);


// read what we put in personBean
for (String propertyName: personBean.getPropertyNames()){
    System.out.println(String.format("Property:%s - type:%s - value:%s",
            propertyName,
            personBean.typeOf(propertyName),
            personBean.valueOf(propertyName)
            ));
}

Outputs:

Property:name - type:class java.lang.String - value:Ahmet Kaya
Property:birth - type:class java.time.LocalDate - value:1957-10-28
Property:death - type:class java.time.LocalDate - value:2000-11-16
Property:age - type:class java.lang.Integer - value:43

flexbean's People

Contributors

ramazanpolat avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.