se.jbee.inject.Demand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of silk-di Show documentation
Show all versions of silk-di Show documentation
Silk Java dependency injection framework
/*
* 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 super T> dependency,
int serialNumber, int cardinality ) {
return new Demand( resource, dependency, serialNumber, cardinality );
}
private final Resource resource;
private final Dependency super T> dependency;
private final int serialNumber;
private final int cardinality;
private Demand( Resource resource, Dependency super T> dependency, int serialNumber,
int cardinality ) {
super();
this.resource = resource;
this.dependency = dependency;
this.serialNumber = serialNumber;
this.cardinality = cardinality;
}
public Dependency super T> 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 super T> dependency ) {
return new Demand( resource, dependency, serialNumber, cardinality );
}
@Override
public String toString() {
return serialNumber + " " + dependency;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy