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

xapi.inject.impl.LazyMerger Maven / Gradle / Ivy

Go to download

Everything needed to run a comprehensive dev environment. Just type X_ and pick a service from autocomplete; new dev modules will be added as they are built. The only dev service not included in the uber jar is xapi-dev-maven, as it includes all runtime dependencies of maven, adding ~4 seconds to build time, and 6 megabytes to the final output jar size (without xapi-dev-maven, it's ~1MB).

The newest version!
package xapi.inject.impl;

import xapi.util.api.MergesValues;

/**
 * A default object designed to convert two values into one value.
 * 
* The {@link #create(K1, K2)} method is provided to initializes the value. * If you use a constructor that accepts another {@link MergesValues}, * that delegate will only be called to create the value object. * If you override the create method, it will be called until it returns non null. *
* If you want to perform some initialization on every call to {@link #merge(K1, K2)}, * you should override the {@link #refresh(K1, K2, V)} method. *
* Care should be taken to only perform idempotent actions inside the refresh method, * as implementations are free to assume it is safe (and performant) to call refresh many times. * * @author "James X. Nelson ([email protected])" * * @param * @param * @param */ public class LazyMerger implements MergesValues { public LazyMerger() { } public LazyMerger(MergesValues merger) { this.delegate = merger; } public LazyMerger(MergesValues merger, V value) { this.delegate = merger; this.value = value; } public LazyMerger(V value) { this.value = value; } MergesValues delegate; V value; @Override public final V merge(K1 k1, K2 k2) { if (value == null) { value = create(k1, k2); if (value != null) { refresh(k1, k2, value); } } else { refresh(k1, k2, value); } return value; } /** * Default action is to do nothing. *
* This method is provided so you can fill in actions that should be taken * on the value result, (only called when the value is not null). */ protected void refresh(K1 k1, K2 k2, V value) { } protected V create(K1 k1, K2 k2) { return delegate == null ? null : delegate.merge(k1, k2); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy