Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.devnatan.inventoryframework;

import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.context.IFRenderContext;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand All @@ -20,14 +20,27 @@ public interface Ref<E> {
*
* @throws UnassignedReferenceException If reference wasn't assigned to any element.
* @return The value that this reference holds.
* @deprecated Use {@link #of(IFRenderContext)} instead.
*/
@NotNull
E value(@NotNull IFContext context);
@Deprecated
default E value(@NotNull IFRenderContext context) {
return of(context);
}

/**
* Returns the value hold by this reference.
*
* @throws UnassignedReferenceException If reference wasn't assigned to any element.
* @return The value that this reference holds.
*/
@NotNull
E of(@NotNull IFRenderContext context);

/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
void assign(Object value);
void assign(@NotNull IFRenderContext context, Object value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import java.util.ArrayList;
import java.util.List;
import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.context.IFRenderContext;
import org.jetbrains.annotations.NotNull;

final class MultiRefsImpl<E> implements Ref<List<E>> {

private final List<E> assignments = new ArrayList<>();

@Override
public @NotNull List<E> value(@NotNull IFContext context) {
public @NotNull List<E> of(@NotNull IFRenderContext context) {
return assignments;
}

@SuppressWarnings("unchecked")
@Override
public void assign(Object value) {
public void assign(@NotNull IFRenderContext context, Object value) {
synchronized (assignments) {
try {
assignments.add((E) value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.devnatan.inventoryframework;

import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.context.IFRenderContext;
import org.jetbrains.annotations.NotNull;

final class RefImpl<E> implements Ref<E> {
Expand All @@ -11,14 +11,14 @@ final class RefImpl<E> implements Ref<E> {

@SuppressWarnings("unchecked")
@Override
public @NotNull E value(@NotNull IFContext context) {
public @NotNull E of(@NotNull IFRenderContext context) {
if (assignment == UNASSIGNED_VALUE) throw new UnassignedReferenceException();

return (E) assignment;
}

@Override
public void assign(Object value) {
public void assign(@NotNull IFRenderContext context, Object value) {
if (assignment != UNASSIGNED_VALUE) throw new IllegalStateException("Reference cannot be reassigned");

this.assignment = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void intercept(PipelineContext<VirtualView> pipeline, VirtualView subject
private void registerComponents(IFRenderContext context) {
context.getComponentFactories().stream()
.map(ComponentFactory::create)
.peek(this::assignReference)
.peek(component -> assignReference(context, component))
.forEach(context::addComponent);
}

Expand All @@ -62,11 +62,11 @@ private void registerComponents(IFRenderContext context) {
*
* @param component The component to assign the reference.
*/
private void assignReference(Component component) {
private void assignReference(IFRenderContext context, Component component) {
final Ref<Component> ref = component.getReference();
if (ref == null) return;

ref.assign(component);
ref.assign(context, component);
debug("Reference assigned to %s", component.getClass().getSimpleName());
}

Expand Down
Loading