Git Product home page Git Product logo

Comments (2)

guiguilechat avatar guiguilechat commented on September 16, 2024

Q : Why not do a list of script with parameters , eg new BeanScript().withClass(myJCMClass).apply(jcm) ?
A : first, for the reason of ordering : the order in which those scripts would be applied would impact the result. Secondly, because calling the script again in another par of the code could lead to issues, therefore the JCM must be used to ensure there is only one instance of each available.

from jcodemodel.

guiguilechat avatar guiguilechat commented on September 16, 2024

Another use case : the generation of a cached value from a generator method.

typically, either the method takes no argument, therefore one item is cached. Or the method takes an argument, and a map stores the cached generated items .

By applying the processor on those two methods :

    private int makeNext(int value) {
        return (value + 1);
    }

    private int make100() {
        return  100;
    }

It results in the following code being added :

    private HashMap<Integer, Integer> next = new HashMap<Integer, Integer>();
    private int hundred = null;


    public int getNext(int value) {
        int ret = next.get(value);
        if (ret == null) {
            ret = makeNext(value);
            next.put(value, ret);
        }
        return ret;
    }

    public int getHundred() {
        if (hundred == null) {
            hundred = make100();
        }
        return hundred;
    }

Still needs to be synchronized if required, to add comments, and to clean the code.

from jcodemodel.

Related Issues (20)

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.