All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.mutiny.vertx.codegen.lang.HashCodeAndEqualsMethodsCodeWriter Maven / Gradle / Ivy

There is a newer version: 3.15.1
Show newest version
package io.smallrye.mutiny.vertx.codegen.lang;

import java.io.PrintWriter;

import io.vertx.codegen.ClassModel;
import io.vertx.codegen.type.ClassTypeInfo;

/**
 * Add the equals and hashCode methods.
 */
public class HashCodeAndEqualsMethodsCodeWriter implements ConditionalCodeWriter {

    @Override
    public void generate(ClassModel model, PrintWriter writer) {
        ClassTypeInfo type = model.getType();
        writer.println("  @Override");
        writer.println("  public boolean equals(Object o) {");
        writer.println("    if (this == o) return true;");
        writer.println("    if (o == null || getClass() != o.getClass()) return false;");
        writer.print("    ");
        writer.print(type.getSimpleName());
        writer.print(" that = (");
        writer.print(type.getSimpleName());
        writer.println(") o;");
        writer.println("    return delegate.equals(that.delegate);");
        writer.println("  }");
        writer.println("  ");

        writer.println("  @Override");
        writer.println("  public int hashCode() {");
        writer.println("    return delegate.hashCode();");
        writer.println("  }");
        writer.println();
    }

    @Override
    public boolean test(ClassModel model) {
        return model.isConcrete();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy