2021-05-08 03:09:00 +02:00
|
|
|
package it.cavallium.dbengine.database;
|
|
|
|
|
2021-06-01 17:08:37 +02:00
|
|
|
import java.util.Objects;
|
2021-05-08 03:09:00 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
public class Delta<T> {
|
|
|
|
|
|
|
|
private final @Nullable T previous;
|
|
|
|
private final @Nullable T current;
|
|
|
|
|
|
|
|
public Delta(@Nullable T previous, @Nullable T current) {
|
|
|
|
this.previous = previous;
|
|
|
|
this.current = current;
|
|
|
|
}
|
2021-06-01 17:08:37 +02:00
|
|
|
|
|
|
|
public boolean isModified() {
|
|
|
|
return !Objects.equals(previous, current);
|
|
|
|
}
|
2021-08-29 23:18:03 +02:00
|
|
|
|
|
|
|
public @Nullable T previous() {
|
|
|
|
return previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
public @Nullable T current() {
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (obj == null || obj.getClass() != this.getClass())
|
|
|
|
return false;
|
|
|
|
var that = (Delta) obj;
|
|
|
|
return Objects.equals(this.previous, that.previous) && Objects.equals(this.current, that.current);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
return Objects.hash(previous, current);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "Delta[" + "previous=" + previous + ", " + "current=" + current + ']';
|
|
|
|
}
|
|
|
|
|
2021-06-01 17:08:37 +02:00
|
|
|
}
|