Code Monkey home page Code Monkey logo

pojo-derivation's Introduction

pojo-derivation

maven-central license

Combine multiple POJOs to generate a new POJO.

1 Setup

  • Kotlin Project
apply plugin: 'kotlin-kapt'

dependencies {
    compileOnly('cc.duduhuo.util:pojo-derivation-annotations:1.2.0')
    kapt('cc.duduhuo.util:pojo-derivation-compiler:1.2.0')
}
  • Pure Java Project
dependencies {
    compileOnly('cc.duduhuo.util:pojo-derivation-annotations:1.2.0')
    annotationProcessor('cc.duduhuo.util:pojo-derivation-compiler:1.2.0')
}

2 Use

You can use the Derivation annotation on any class:

@Derivation(
        name = "ABC",
        sourceTypes = {A.class, B.class, C.class},
        constructorTypes = {ConstructorType.NO_ARGS, ConstructorType.ALL_ARGS, ConstructorType.ALL_SOURCE_OBJS}
)
final class ABCCombine {}

Then you will get a new class as shown below:

// This file is automatically generated by pojo-derivation (https://github.com/liying2008/pojo-derivation).
// Do not modify this file -- YOUR CHANGES WILL BE ERASED!
// File generation time: Sat Feb 13 17:45:10 CST 2021
package cc.duduhuo.util.pojo.derivation.samplebase.readme;

import java.lang.String;
import org.jetbrains.annotations.NotNull;

/**
 * Generated according to {@link cc.duduhuo.util.pojo.derivation.samplebase.readme.ABCCombine}.
 */
public class ABC {
    private int a1;

    private String a2;

    private boolean b1;

    private double b2;

    private boolean c1;

    private char c2;

    @NotNull
    private String c3;

    public ABC() {
    }

    public ABC(int a1, String a2, boolean b1, double b2, boolean c1, char c2, String c3) {
        this.a1 = a1;
        this.a2 = a2;
        this.b1 = b1;
        this.b2 = b2;
        this.c1 = c1;
        this.c2 = c2;
        this.c3 = c3;
    }

    public ABC(A a, B b, C c) {
        this.setA1(a.getA1());
        this.setA2(a.getA2());
        this.setB1(b.isB1());
        this.setB2(b.getB2());
        this.setC1(c.getC1());
        this.setC2(c.getC2());
        this.setC3(c.getC3());
    }

    public int getA1() {
        return a1;
    }

    public void setA1(int a1) {
        this.a1 = a1;
    }

    public String getA2() {
        return a2;
    }

    public void setA2(String a2) {
        this.a2 = a2;
    }

    public boolean isB1() {
        return b1;
    }

    public void setB1(boolean b1) {
        this.b1 = b1;
    }

    public double getB2() {
        return b2;
    }

    public void setB2(double b2) {
        this.b2 = b2;
    }

    public boolean isC1() {
        return c1;
    }

    public void setC1(boolean c1) {
        this.c1 = c1;
    }

    public char getC2() {
        return c2;
    }

    public void setC2(char c2) {
        this.c2 = c2;
    }

    public String getC3() {
        return c3;
    }

    public void setC3(String c3) {
        this.c3 = c3;
    }
}

See sample module for more examples.

3 License

MIT

pojo-derivation's People

Contributors

liying2008 avatar

Stargazers

 avatar

Watchers

 avatar  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.