Skip to content

Latest commit

 

History

History
84 lines (68 loc) · 2.21 KB

README.md

File metadata and controls

84 lines (68 loc) · 2.21 KB

JavaEntityGenerator

Python script to generate Java class entities

Example

python ./entity_gen.py --equals --toString --hashCode --get --set --class MyClass --builder "Optional<String>:testVariable" "Integer:id"

Result:

import java.util.Objects;
import com.google.common.base.MoreObjects;
public final class MyClass{
    private Optional<String> testVariable;
    private Integer id;

    public final Optional<String> getTestVariable(){
        return testVariable;
    }

    public final Integer getId(){
        return id;
    }

    public final void setTestVariable(Optional<String> pTestVariable){
        testVariable = pTestVariable;
    }

    public final void setId(Integer pId){
        id = pId;
    }

    @Override
    public boolean equals(Object object){
        if(object == this){
            return true;
        }
        if(object instanceof MyClass){
            MyClass myclass = (MyClass) object;
            if(Objects.equals(testVariable, myclass.testVariable) && Objects.equals(id, myclass.id)) {
                return true;
            }
        }
        return false;
    }
    @Override
    public int hashCode(){
        return Objects.hash(testVariable, id);
    }
    @Override
    public String toString(){
        return MoreObjects.toStringHelper(this)
            .add("testVariable", testVariable)
            .add("id", id).toString();
    }
    private MyClass(Builder pBuilder){
        testVariable = pBuilder.testVariable;
      id = pBuilder.id;
  }

  public static Builder builder(){
      return new Builder();
  }

  public static class Builder{

      private Optional<String> testVariable = Optional.empty();
      private Integer id;

      public Builder testVariable(Optional<String> pTestVariable){
          testVariable = pTestVariable;
          return this;
      }

      public Builder id(Integer pId){
          id = pId;
          return this;
      }

      public MyClass build(){
          return new MyClass(this);
      }
  }

}