Module com.speedment.common.codegen
Class AutoEquals<T extends HasFields<T> & HasMethods<T> & HasName<T>>
- java.lang.Object
-
- com.speedment.common.codegen.controller.AutoEquals<T>
-
- Type Parameters:
T- The extending type
- All Implemented Interfaces:
Consumer<T>
public final class AutoEquals<T extends HasFields<T> & HasMethods<T> & HasName<T>> extends Object implements Consumer<T>
This control can be applied on a class, enum or similar to auto generate anequalsand ahashCodemethod. The control uses all the fields to determine the salt.The control must be instantiated with the
Fileas a parameter. The reason for this is that the generated methods might require new dependencies to be imported.To use
AutoEquals, follow this example:file.add( Class.of("Vector2f") .add(Field.of("x", FLOAT_PRIMITIVE) .public_() .set(new NumberValue(0))) .add(Field.of("y", FLOAT_PRIMITIVE) .public_() .set(new NumberValue(0))) .call(new AutoEquals<>(file)) );If one of the methods already exists, it will not be overwritten.
- Author:
- Emil Forslund
-
-
Constructor Summary
Constructors Constructor Description AutoEquals(HasImports<?> importer)Instantiates theAutoEqualsusing something that imports can be added to.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(T model)Adds anequals()and ahashCode()method to the specified model.protected voidacceptEquals(T model)Theequals()-part of theacceptmethod.protected voidacceptHashcode(T model)ThehashCode()-part of theacceptmethod.protected Stringcompare(Field f)Generates code for comparing the specified field in this and another object.protected Stringhash(Field f)Generates code for hashing the specified field.protected booleanhasMethod(T model, String method, int params)Returns if a method with the specified signature exists.protected booleanisPrimitive(Type type)Returnstrueif the specified type is a primitive type.
-
-
-
Field Detail
-
importer
protected final HasImports<?> importer
-
EQUALS
protected static final String EQUALS
- See Also:
- Constant Field Values
-
HASHCODE
protected static final String HASHCODE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AutoEquals
public AutoEquals(HasImports<?> importer)
Instantiates theAutoEqualsusing something that imports can be added to. This can for an example be aFile.- Parameters:
importer- the importer
-
-
Method Detail
-
accept
public void accept(T model)
Adds anequals()and ahashCode()method to the specified model.If one of the methods already exists, it will not be overwritten.
-
acceptEquals
protected void acceptEquals(T model)
Theequals()-part of theacceptmethod.- Parameters:
model- the model
-
acceptHashcode
protected void acceptHashcode(T model)
ThehashCode()-part of theacceptmethod.- Parameters:
model- the model
-
compare
protected String compare(Field f)
Generates code for comparing the specified field in this and another object.- Parameters:
f- the field- Returns:
- the comparing code
-
hash
protected String hash(Field f)
Generates code for hashing the specified field.- Parameters:
f- the field- Returns:
- the hashing code
-
isPrimitive
protected boolean isPrimitive(Type type)
Returnstrueif the specified type is a primitive type.- Parameters:
type- the type- Returns:
trueif primitive, elsefalse
-
-