Giter VIP home page Giter VIP logo

fluent-interface-proxy's People

Contributors

davidmarquis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fluent-interface-proxy's Issues

translateFromPrimitive uses Float for character and byte

I'm not sure if this is intentional or if this is a bug, but this looks to me like a copy-paste error. I know that one could convert 16 and 8 bit integer values to float and vice versa, but shouldn't the java.lang.Character and java.lang.Byte classes be used?

} else if (paramType == char.class) {
return Float.class;
} else if (paramType == byte.class) {
return Float.class;

Could you please help to consider to support the super interface for the builder?

Dear Sir,

Firstly I would like to thank for providing the great and brilliant tools. I'm very appreciated.

In my environment, my bean is not a stand alone and it is derived from another super class. In fact it is a JPA data bean. Here is some example.

public class MySuperBean() {
    private String id;
    private String description;
    private Calendar createdDate();
    private String createdBy();
    //...Other sharing common attributes.

    //Getters/Setters
}

public class MyPerson extends MySuperBean {
    private String firstName;
    private String lastName;
    //...Other specific attributes for Person

    //Getters/Setters
}

public class MyCompany extends MySuperBean {
    private String name;
    private String type;
    //...Other specific attributes for Company

    //Getters/Setters
}

Regarding to the current implementation, I need to create 2 Builder Interface which contains some redundant methods from the super class as the following example

public interface MyPersonBuilder extends Builder<MyPerson> {
    MyPersonBuilder withId(final String id);
    MyPersonBuilder withDescription(final String description);
    // other withXXX from the MySuperBean

    // other withYYY from the specific MyPerson
}

public interface MyCompanyBuilder extends Builder<MyCompany> {
    MyPersonBuilder withId(final String id);
    MyPersonBuilder withDescription(final String description);
    // other withXXX from the MySuperBean

    // other withYYY from the specific MyCompany
}

It would be nice if you may consider to provide the support for the Super Interface Builder as the following example

public inferface MySuperBeanBuilder<T extends MySuperBeanBuilder<T>> {
    T withId(final String id);
    T withDescription(final String description);
     //  other withXXX from the MySuperBean
}

public interface MyPersonBuilder extends MySuperBeanBuilder<MyPersonBuilder>,
                                         Builder<MyPerson> {
    MyPersonBuilder  withFirstName(final String firstName);
    MyPersonBuilder  withLastName(final String lastName);
    // other withYYY from the specific MyPerson
}

public interface MyCompanyBuilder extends MySuperBeanBuilder<MyCompanyBuilder>,
                                         Builder<MyCompany> {
    MyCompanyBuilder withName(final String name);
    MyCompanyBuilder withType(final String type);
    // other withYYY from the specific MyCompany
}

The the actual using may look like the following

    MyPerson person = ReflectionBuilder.implementationFor(MyPersonBuilder.class).
                                        withId("some-id").
                                        withDescription("some-description").
                                        withCreatedBy("my-admin").
                                        ...
                                        withFirstName("Charlee").
                                        withLastName("Ch.").
                                        ....
                                        build();

By overview I also have a chance to dig in your code and found some rough tweak as the following: -

public class BuilderProxy implements InvocationHandler {
      ...
    private boolean isFluentSetter(final Method method) {
        return method.getParameterTypes().length == 1
                && method.getReturnType().isAssignableFrom(this.proxied)
                && !this.isBuildMethod(method);
    }
}

I'm also not sure if it is an acceptable or if it may be any effects to the module or not. Could you please help to consider? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.

Regards,

Charlee Ch.

The proxy can't access protected getters and setters

I propose to use setAccessible of Reflection API to permit encapsulating model properties, and no grant direct access, so, the getters and setters should be protected in anyone cases and only grant access by builder.
The same for the constructors methods.

What do you think?

Ps. Congratulations for your project.

BestMatchingConstructor#typesAreCompatible does type compatibility the opposite way

On line 124 of BestMatchingConstructor.java, you have the following code:
if (!inputParamType.isAssignableFrom(constructorParamType)) { matches = false; break; }

Shouldn't this comparison be the other way? like so:
if (!constructorParamType.isAssignableFrom(inputParamType)) { matches = false; break; }
It's perfectly fine if the constructor param is a super class or an interface of the inputType, but the other way around will be a compile error. So the net effect of this is that only exact types are allowed, for which there is no work-around if the constructor param is an interface.

Is it Fluent Interface or just Method Chaining?

Does this project provide a way to define real fluent interfaces or just method chaining builders?

"I've also noticed a common misconception - many people seem to equate fluent interfaces with Method Chaining. Certainly chaining is a common technique to use with fluent interfaces, but true fluency is much more than that." http://www.martinfowler.com/bliki/FluentInterface.html

What I mean by "method chaining" is something like

 Interface myclass = new MyClass().dothis("mytext").dothat("more text").add(5);

By fluent interface I mean an internal DSL that is able to give the using programmer an interface that limits his/her options to sensible once, thus implementing a grammer: http://blog.jooq.org/2012/01/05/the-java-fluent-api-designer-crash-course/ (possibly with method chaining, but method nesting is an alternative).

It would be nice to have support of Maps

It would be nice to have support of populating maps as well. I am not sure what API should be for this.
For lists "having" is perfect, may be something like

aPerson.havingDetails("age", 25)

where person has property

private Map<String, Integer> details;

Class constructor with argument Map<?,?> and HashMap<?,?>

Issue with pojo constructor where constructor is taking Map<String,Object> as argument
and passing Object is HashMap<String,Object> throws error that constructor not found.

public class Payload {
    private final Map<String, Object> data;
    public Payload(final Map<String,Object> data){
      this.data = data;
    }
}

static PayloadBuilder aMessage() {
		return ReflectionBuilder.implementationFor(PayloadBuilder.class).create();
	}

public static Payload default() {
               Map<String,Object> data = new HashMap<String,Object>();
               data.put("a","b");
		return aMessage() //
				.of(data) //
				.build();
	}

java.lang.IllegalArgumentException: No constructor found on class [Payload] that matches signature (class java.util.HashMap])
at com.fluentinterface.proxy.impl.BestMatchingConstructor.findMatchingConstructor(BestMatchingConstructor.java:56)
at com.fluentinterface.proxy.impl.BestMatchingConstructor.instantiate(BestMatchingConstructor.java:30)
at com.fluentinterface.proxy.BuilderProxy.createInstanceFromProperties(BuilderProxy.java:74)
at com.fluentinterface.proxy.BuilderProxy.invoke(BuilderProxy.java:57)
at com.sun.proxy.$Proxy166.build(Unknown Source)

Support for default methods

When a builder interface has default methods, the proxy tries to implement these methods as builder methods. They should be ignored by the proxy.

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.