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

com.emc.mongoose.api.common.supply.async.AsyncPatternDefinedSupplier Maven / Gradle / Ivy

There is a newer version: 4.0.0-alpha5
Show newest version
package com.emc.mongoose.api.common.supply.async;

import com.emc.mongoose.api.common.exception.OmgDoesNotPerformException;
import com.emc.mongoose.api.common.exception.OmgShootMyFootException;
import com.emc.mongoose.api.common.supply.PatternDefinedSupplier;
import com.emc.mongoose.api.common.supply.RangePatternDefinedSupplier;

import com.github.akurilov.coroutines.CoroutinesProcessor;

public final class AsyncPatternDefinedSupplier
extends AsyncUpdatingValueSupplier
implements PatternDefinedSupplier {
	
	private final PatternDefinedSupplier wrappedSupplier;
	
	public AsyncPatternDefinedSupplier(
		final CoroutinesProcessor coroutinesProcessor, final String pattern
	) throws OmgShootMyFootException {
		this(
			coroutinesProcessor,
			new RangePatternDefinedSupplier(
				pattern, AsyncStringSupplierFactory.getInstance(coroutinesProcessor)
			)
		);
	}
	
	private AsyncPatternDefinedSupplier(
		final CoroutinesProcessor coroutinesProcessor, final PatternDefinedSupplier wrappedSupplier
	) throws OmgDoesNotPerformException {
		super(
			coroutinesProcessor,
			null,
			new InitializedCallableBase() {
				private final StringBuilder result = new StringBuilder();
				@Override
				public final String call()
				throws Exception {
					result.setLength(0);
					return wrappedSupplier.format(result);
				}
			}
		);
		this.wrappedSupplier = wrappedSupplier;
	}
	
	@Override
	public String getPattern() {
		return wrappedSupplier.getPattern();
	}

	@Override
	public String format(final StringBuilder result) {
		return wrappedSupplier.format(result);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy