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

com.g2forge.alexandria.data.relationship.ARelationship Maven / Gradle / Ivy

There is a newer version: 0.0.7
Show newest version
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);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy