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

com.kenshoo.pl.entity.internal.audit.AuditedField 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.internal.audit;

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

import static com.kenshoo.pl.entity.audit.AuditTrigger.ON_CREATE_OR_UPDATE;
import static java.util.Objects.requireNonNull;

public class AuditedField, T> {

    private final EntityField field;
    private final String name;
    private final AuditTrigger trigger;

    private AuditedField(final EntityField field,
                         final String name,
                         final AuditTrigger trigger) {
        this.field = requireNonNull(field, "An underlying field must be provided");
        this.name = requireNonNull(name, "A name must be provided");
        this.trigger = requireNonNull(trigger, "A trigger must be provided");
    }

    public EntityField getField() {
        return field;
    }

    public String getName() {
        return name;
    }

    public AuditTrigger getTrigger() {
        return trigger;
    }

    public ValueConverter getStringValueConverter() {
        return field.getStringValueConverter();
    }


    public boolean valuesEqual(final T v1, final T v2) {
        return field.valuesEqual(v1, v2);
    }

    public static , T> 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;

        final AuditedField that = (AuditedField) o;

        return new EqualsBuilder()
            .append(field, that.field)
            .append(name, that.name)
            .append(trigger, that.trigger)
            .isEquals();
    }

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

    @Override
    public String toString() {
        return new ToStringBuilder(this)
            .append("field", field)
            .append("name", name)
            .append("trigger", trigger)
            .toString();
    }

    public static class Builder, T> {
        private final EntityField field;
        private String name;
        private AuditTrigger trigger;

        public Builder(final EntityField field) {
            this.field = requireNonNull(field, "An underlying field must be provided");
            this.name = field.toString();
            this.trigger = ON_CREATE_OR_UPDATE;
        }

        public Builder withName(final String name) {
            this.name = name;
            return this;
        }

        public Builder withTrigger(final AuditTrigger trigger) {
            this.trigger = trigger;
            return this;
        }

        public AuditedField build() {
            return new AuditedField<>(field, name, trigger);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy