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

io.permazen.change.ListFieldClear Maven / Gradle / Ivy

The newest version!

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.change;

import com.google.common.base.Preconditions;

import io.permazen.PermazenObject;
import io.permazen.PermazenTransaction;
import io.permazen.annotation.OnChange;

/**
 * Notification object that gets passed to {@link OnChange @OnChange}-annotated methods when a list field is cleared.
 *
 * @param  the type of the object containing the changed field
 */
public class ListFieldClear extends ListFieldChange {

    /**
     * Constructor.
     *
     * @param jobj Java object containing the list field that was cleared
     * @param fieldName the name of the field that changed
     * @throws IllegalArgumentException if {@code jobj} or {@code fieldName} is null
     */
    public ListFieldClear(T jobj, String fieldName) {
        super(jobj, fieldName);
    }

    @Override
    public  R visit(ChangeSwitch target) {
        return target.caseListFieldClear(this);
    }

    @Override
    public void apply(PermazenTransaction jtx, PermazenObject jobj) {
        Preconditions.checkArgument(jtx != null, "null jtx");
        Preconditions.checkArgument(jobj != null, "null jobj");
        jtx.readListField(jobj.getObjId(), this.getFieldName(), false).clear();
    }

// Object

    @Override
    public String toString() {
        return "ListFieldClear[object=" + this.getObject() + ",field=\"" + this.getFieldName() + "\"]";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy