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

application.common.BindingStore Maven / Gradle / Ivy

package application.common;

import java.util.ArrayList;
import java.util.List;

import javafx.beans.value.ObservableValue;

/**
 * Provides a way to keep bindings from being garbage collected without declaring lots of instance variables.
 * Use {@link #add(ObservableValue)} to store the binding while adding it to the bound object.
 * Use {@link #clear()} to remove all expired bindings before adding new ones. For example:
 *  
 * 
{@code
 * 
 *  BindingStore bindings = new BindingStore();
 *  ...
 *  bindings.clear();
 *  variable.bind(bindings.add(a.and(b)));
 * 
 * }
* @author Joel Håkansson */ public class BindingStore { private final List> bindings; public BindingStore() { this.bindings = new ArrayList<>(); } /** * Adds the observable to the store. * @param v the observable * @return the observable */ public > T add(T v) { bindings.add(v); return v; } /** * Removes all stored elements. */ public void clear() { bindings.clear(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy