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

se.jbee.inject.Demand Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
/*
 *  Copyright (c) 2012, Jan Bernitt 
 *			
 *  Licensed under the Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
 */
package se.jbee.inject;

/**
 * A {@link Demand} is a {@link Dependency} resolved to a specific {@link Resource} in the context
 * of a specific {@link Injector} (the {@link Repository} within it).
 * 
 * @author Jan Bernitt ([email protected])
 * 
 * @param 
 *            Type of the value demanded
 */
public final class Demand
		implements Resourcing {

	public static  Demand demand( Resource resource, Dependency dependency,
			int serialNumber, int cardinality ) {
		return new Demand( resource, dependency, serialNumber, cardinality );
	}

	private final Resource resource;
	private final Dependency dependency;
	private final int serialNumber;
	private final int cardinality;

	private Demand( Resource resource, Dependency dependency, int serialNumber,
			int cardinality ) {
		super();
		this.resource = resource;
		this.dependency = dependency;
		this.serialNumber = serialNumber;
		this.cardinality = cardinality;
	}

	public Dependency getDependency() {
		return dependency;
	}

	@Override
	public Resource getResource() {
		return resource;
	}

	/**
	 * @return the number of the {@link Injectron} being injected.
	 */
	public final int envSerialNumber() {
		return serialNumber;
	}

	/**
	 * @return the total amount of {@link Injectron}s in the same environment ({@link Injector}).
	 */
	public final int envCardinality() {
		return cardinality;
	}

	public Demand from( Dependency dependency ) {
		return new Demand( resource, dependency, serialNumber, cardinality );
	}

	@Override
	public String toString() {
		return serialNumber + " " + dependency;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy