org.javers.core.diff.changetype.Atomic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.core.diff.changetype;
import org.javers.common.collections.Primitives;
import java.io.Serializable;
import java.util.Objects;
/**
* Immutable wrapper for client's Primitives, Values and Id's
*
*
* TODO refine dehydrate approach
* Value needs to be dehydrated before persisting. Dehydration is simply serialization to JSON.
*
* @author bartosz walacik
*/
public class Atomic implements Serializable {
private final Object value;
public Atomic(Object value) {
this.value = value;
}
public boolean isNull() {
return value == null;
}
/**
* @return true if value is not null and is primitive, box or String
*/
public boolean isJsonBasicType() {
if(isNull()) {
return false;
}
return Primitives.isJsonBasicType(value);
}
/**
* original Value
*/
public Object unwrap() {
return value;
}
@Override
public String toString() {
return "value:"+value;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Atomic)) {
return false;
}
Atomic other = (Atomic)obj;
return Objects.equals(value, other.value);
}
@Override
public int hashCode() {
if (value == null) {
return 0;
}
return value.hashCode();
}
}