public abstract class Service extends Object
Additionally this class can be used as a base class for implementing services that are differentiated by a String key. An example implementation might be:
public abstract class StringConverter extends org.neo4j.commons.Service
{
protected StringConverter(String id)
{
super( id );
}
public abstract String convert( String input );
public static StringConverter load( String id )
{
return org.neo4j.commons.Service.load( StringConverter.class, id );
}
}
With for example these implementations:
public final class UppercaseConverter extends StringConverter
{
public UppercaseConverter()
{
super( "uppercase" );
}
public String convert( String input )
{
return input.toUpperCase();
}
}
public final class ReverseConverter extends StringConverter
{
public ReverseConverter()
{
super( "reverse" );
}
public String convert( String input )
{
char[] chars = input.toCharArray();
for ( int i = 0; i < chars.length/2; i++ )
{
char intermediate = chars[i];
chars[i] = chars[chars.length-1-i];
chars[chars.length-1-i] = chars[i];
}
return new String( chars );
}
}
This would then be used as:
String atad = StringConverter.load( "reverse" ).convert( "data" );
Modifier and Type | Class and Description |
---|---|
static interface |
Service.Implementation
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Iterable<String> |
getKeys() |
int |
hashCode() |
static <T> Iterable<T> |
load(Class<T> type)
Load all implementations of a Service.
|
static <T extends Service> |
load(Class<T> type,
String key)
Load the Service implementation with the specified key.
|
static <T extends Service> |
loadSilently(Class<T> type,
String key)
Load the Service implementation with the specified key.
|
boolean |
matches(String key) |
String |
toString() |
public static <T> Iterable<T> load(Class<T> type)
T
- the type of the Servicetype
- the type of the Service to loadpublic static <T extends Service> T loadSilently(Class<T> type, String key)
T
- the type of the Service to loadtype
- the type of the Service to loadkey
- the key that identifies the desired implementationpublic static <T extends Service> T load(Class<T> type, String key)
T
- the type of the Servicetype
- the type of the Service to loadkey
- the key that identifies the desired implementationNoSuchElementException
- if no service could be loaded with the given key.public boolean matches(String key)
Copyright © 2002–2018 The Neo4j Graph Database Project. All rights reserved.