io.permazen.change.SetFieldRemove Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-main Show documentation
Show all versions of permazen-main Show documentation
Permazen classes that map Java model classes onto the core API.
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;
import java.util.Objects;
/**
* Notification object that gets passed to {@link OnChange @OnChange}-annotated methods
* when an element is removed from a set field.
*
* @param the type of the object containing the changed field
* @param the type of the changed set's elements
*/
public class SetFieldRemove extends SetFieldChange {
private final E element;
/**
* Constructor.
*
* @param jobj Java object containing the set field that changed
* @param fieldName the name of the field that changed
* @param element the element that was removed
* @throws IllegalArgumentException if {@code jobj} or {@code fieldName} is null
*/
public SetFieldRemove(T jobj, String fieldName, E element) {
super(jobj, fieldName);
this.element = element;
}
@Override
public R visit(ChangeSwitch target) {
return target.caseSetFieldRemove(this);
}
@Override
public void apply(PermazenTransaction jtx, PermazenObject jobj) {
Preconditions.checkArgument(jtx != null, "null jtx");
Preconditions.checkArgument(jobj != null, "null jobj");
jtx.readSetField(jobj.getObjId(), this.getFieldName(), false).remove(this.element);
}
/**
* Get the element that was removed from the set.
*
* @return the value removed from the set
*/
public E getElement() {
return this.element;
}
// Object
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (!super.equals(obj))
return false;
final SetFieldRemove, ?> that = (SetFieldRemove, ?>)obj;
return Objects.equals(this.element, that.element);
}
@Override
public int hashCode() {
return super.hashCode() ^ Objects.hashCode(this.element);
}
@Override
public String toString() {
return "SetFieldRemove[object=" + this.getObject() + ",field=\"" + this.getFieldName() + "\",element=" + this.element + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy