com.jwebmp.guicedinjection.interfaces.IDefaultService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-injection Show documentation
Show all versions of guiced-injection Show documentation
Guice Injection allows you to access multiple Guice Binders and Modules across separate archives.
Allowing you to configure your applications with injection from multiple dependancies. Servlets, EJB's, and
Stand-Alone is supported. Requires JDK 8 or 10.
The newest version!
package com.jwebmp.guicedinjection.interfaces;
import com.jwebmp.guicedinjection.GuiceContext;
import javax.validation.constraints.NotNull;
import java.util.*;
/**
* Supplies standard set changer and comparable's for services
*
* @param
*/
public interface IDefaultService>
extends Comparable, Comparator
{
/**
* Method loaderToSet, converts a ServiceLoader into a TreeSet
*
* @param loader
* of type ServiceLoader
*
* @return Set
*/
@SuppressWarnings("unchecked")
@NotNull
static Set loaderToSet(ServiceLoader loader)
{
Set output = new TreeSet<>();
for (T newInstance : loader)
{
output.add((T) GuiceContext.get(newInstance.getClass()));
}
return output;
}
/**
* Method loaderToSet, converts a ServiceLoader into a TreeSet
*
* @param loader
* of type ServiceLoader
*
* @return Set
*/
@SuppressWarnings("unchecked")
@NotNull
static Set loaderToSetNoInjection(ServiceLoader loader)
{
Set output = new LinkedHashSet<>();
for (T newInstance : loader)
{
output.add(newInstance);
}
return output;
}
/**
* Method compare ...
*
* @param o1
* of type J
* @param o2
* of type J
*
* @return int
*/
@Override
default int compare(J o1, J o2)
{
if (o1 == null || o2 == null)
{
return -1;
}
return o1.sortOrder()
.compareTo(o2.sortOrder());
}
/**
* Default Sort Order 100
*
* @return 100
*/
default Integer sortOrder()
{
return 100;
}
/**
* Method compareTo ...
*
* @param o
* of type J
*
* @return int
*/
@Override
default int compareTo(@NotNull J o)
{
int sort = sortOrder().compareTo(o.sortOrder());
if (sort == 0)
{
return -1;
}
return sort;
}
}