Coder Social home page Coder Social logo

equals and hashcode? about protostuff HOT 5 CLOSED

protostuff avatar protostuff commented on May 18, 2024
equals and hashcode?

from protostuff.

Comments (5)

kshchepanovskyi avatar kshchepanovskyi commented on May 18, 2024

Hi,

java_bean template does not generate equals/hashCode implementation.
But you can extend it and add your implementation. For example (using Java 7 Objects class):

message_equals_and_hashcode(message, options) ::= <<
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null || this.getClass() != obj.getClass()) {
        return false;
    }
    final <message.name> that = (<message.name>) obj;
    <if(first(message.fields))>
    return
            <message.fields:field_equals(field=it, options=options, message=message); separator=" &&\n">;
    <else>
    return true;
    <endif>
}

@Override
public int hashCode() {
    <if(first(message.fields))>
    return Objects.hash(<message.fields:field_name(field=it, options=options, message=message); separator=", ">);
    <else>
    return 0;
    <endif>
}

>>

field_equals(field, options, message) ::= <<
Objects.equals(this.<var(val=field.name, fmt="CC", options=options)>, that.<var(val=field.name, fmt="CC", options=options)>)
>>

Maybe we can add this functionality to the next release - 1.3.2. I need to check how it affects other templates.

from protostuff.

kshchepanovskyi avatar kshchepanovskyi commented on May 18, 2024

@dyu please check these issues on google code:

I think they can be closed.

from protostuff.

dyu avatar dyu commented on May 18, 2024

Its not implemented for 1.0.x, leaving it open might be the best option.
I think leaving a comment that it is implemented in 1.3.x is enough.

I've updated the googlecode site stating that no new features will be added for 1.0.x

from protostuff.

nwertzberger avatar nwertzberger commented on May 18, 2024

Ladies and gents, you literally can't pay for this type of service. You are all awesome. What can i do to help? I'll start walking the docs while i'm working on this stuff.

from protostuff.

dyu avatar dyu commented on May 18, 2024

Share your experiences. Spread the word!
Hope this project benefits yours.

from protostuff.

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.