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

com.kenshoo.pl.entity.audit.FieldAuditRecord Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
package com.kenshoo.pl.entity.audit;

import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class FieldAuditRecord> {
    private final EntityField field;
    private final Object oldValue;
    private final Object newValue;

    private FieldAuditRecord(final EntityField field,
                             final Object oldValue,
                             final Object newValue) {
        this.field = field;
        this.oldValue = oldValue;
        this.newValue = newValue;
    }

    public EntityField getField() {
        return field;
    }

    public Optional getOldValue() {
        return Optional.ofNullable(oldValue);
    }

    public Optional getNewValue() {
        return Optional.ofNullable(newValue);
    }

    public static > Builder builder(final EntityField field) {
        return new Builder<>(field);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        @SuppressWarnings("unchecked")
        final FieldAuditRecord that = (FieldAuditRecord) o;

        return new EqualsBuilder()
            .append(field, that.field)
            .append(oldValue, that.oldValue)
            .append(newValue, that.newValue)
            .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
            .append(field)
            .append(oldValue)
            .append(newValue)
            .toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
            .append("field", field.getEntityType().getName() + "." + field)
            .append("oldValue", oldValue)
            .append("newValue", newValue)
            .toString();
    }

    public static class Builder> {
        private final EntityField field;
        private Object oldValue;
        private Object newValue;

        private Builder(final EntityField field) {
            this.field = requireNonNull(field, "A field is required");
        }

        public Builder oldValue(Object oldValue) {
            this.oldValue = oldValue;
            return this;
        }

        public Builder newValue(Object newValue) {
            this.newValue = newValue;
            return this;
        }

        public FieldAuditRecord build() {
            return new FieldAuditRecord<>(field, oldValue, newValue);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy