
io.polyglotted.pgmodel.search.Sleeve Maven / Gradle / Ivy
package io.polyglotted.pgmodel.search;
import com.google.common.base.Function;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import java.util.List;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.transform;
import static io.polyglotted.pgmodel.util.ModelUtil.equalsAll;
@RequiredArgsConstructor
@ToString(includeFieldNames = false, doNotUseGetters = true)
public final class Sleeve {
public final IndexKey key;
public final T source;
public final String ancestor;
public final String status;
public final Long timestamp;
public final Long expiry;
public final String user;
public static Sleeve create(IndexKey key, T source) {
return new Sleeve<>(checkNotNull(key), source, null, null, null, null, null);
}
public static List> createSleeves(List objects, Function> newSleeveFunction) {
return transform(objects, newSleeveFunction);
}
public static Sleeve newSleeve(T object, Function keyFunction) {
return create(keyFunction.apply(object), object);
}
public IndexKey key() {
return key;
}
public String id() {
return key.id();
}
public String index() {
return key.index();
}
public T source() {
return source;
}
public boolean isNew() {
return key.version() <= 0;
}
public boolean isDeleted() {
return key.delete;
}
public Sleeve delete() {
return new Sleeve<>(key.delete(), null, key.uniqueId(), null, null, null, null);
}
public Sleeve update(T update) {
return new Sleeve<>(key, update, key.uniqueId(), null, null, null, null);
}
public Sleeve update(Function updateFunction) {
return update(updateFunction.apply(source));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Sleeve that = (Sleeve) o;
return equalsAll(key, that.key(), source, that.source(), ancestor, that.ancestor);
}
@Override
public int hashCode() {
return Objects.hash(key, source, ancestor);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy