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

org.javers.core.metamodel.type.ValueObjectType Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
package org.javers.core.metamodel.type;

import org.javers.common.reflection.ReflectionUtil;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

/**
 * ValueObject class in client's domain model.
 * 

* * Has list of mutable properties but no unique identifier. *

* * Two ValueObjects are compared property by property. *

* * Example: *
 *     class Address {
 *         private String city;
 *         private String street;
 *         private String zip;
 *         ...
 *     }
 * 
* * @author bartosz walacik */ public class ValueObjectType extends ManagedType{ private final boolean defaultType; private final Optional> toStringFunction = Optional.empty(); ValueObjectType(ManagedClass valueObject){ super(valueObject); this.defaultType = false; } public ValueObjectType(Class baseJavaClass, List allProperties){ this(new ManagedClass(baseJavaClass, allProperties, Collections.emptyList(), ManagedPropertiesFilter.empty())); } ValueObjectType(ManagedClass valueObject, Optional typeName, boolean isDefault) { super(valueObject, typeName); this.defaultType = isDefault; } @Override ValueObjectType spawn(ManagedClass managedClass, Optional typeName) { return new ValueObjectType(managedClass, typeName, defaultType); } @Override public boolean canBePrototype() { return !defaultType; } public String smartToString(Object value) { if (value == null) { return ""; } return toStringFunction .map(f -> f.apply(value)) .orElse(ReflectionUtil.reflectiveToString(value)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy