org.javers.shadow.Shadow Maven / Gradle / Ivy
package org.javers.shadow;
import org.javers.common.validation.Validate;
import org.javers.core.commit.CommitId;
import org.javers.core.commit.CommitMetadata;
import org.javers.repository.api.JaversRepository;
/**
* Shadow is a historical version of a domain object restored
* from a snapshot loaded from {@link JaversRepository}.
*
*
* Shadows use the same types as domain objects.
* For example, a Shadow of a Person object is an instance of Person.class.
*
*
* Shadows class is a thin wrapper for a Shadow object and {@link CommitMetadata}
*
* @param type of a domain object
* @author bartosz.walacik
*/
public class Shadow {
private final CommitMetadata commitMetadata;
private final T it;
Shadow(CommitMetadata commitMetadata, T shadow) {
Validate.argumentsAreNotNull(commitMetadata, shadow);
this.commitMetadata = commitMetadata;
this.it = shadow;
}
public CommitMetadata getCommitMetadata() {
return commitMetadata;
}
public CommitId getCommitId() {
return commitMetadata.getId();
}
/**
* Shadow object per se
*/
public T get() {
return it;
}
@Override
public String toString() {
return "Shadow{" +
"it=" + it +
", commitMetadata=" + commitMetadata +
'}';
}
}