com.g2forge.alexandria.data.relationship.ARelationship Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-collection Show documentation
Show all versions of ax-collection Show documentation
Extended collection API, which will evolve to encompass all ADTs.
package com.g2forge.alexandria.data.relationship;
import java.util.function.BiConsumer;
import java.util.function.Function;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public abstract class ARelationship {
protected final Function get;
protected final BiConsumer set;
protected final BiConsumer setRemote;
public L set(L local, F field) {
final F current = get.apply(local);
if (current != field) {
if (isInitialized(current)) throw new IllegalStateException("Cannot change relationship once initialized");
set.accept(local, field);
if (setRemote != null) setRemote(field, local);
}
return local;
}
protected abstract boolean isInitialized(F field);
protected abstract void setRemote(F field, L local);
}