Commit e754a6ee authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Reformatted code in DbXRefResourceRegistry

parent d854e355
......@@ -46,21 +46,21 @@ public class DbXRefResourceRegistry implements DbXRefService {
private static DbXRefResourceRegistry instance;
public static DbXRefResourceRegistry getDefault() {
if (instance == null) {
instance = new DbXRefResourceRegistry();
}
return instance;
if (instance == null) {
instance = new DbXRefResourceRegistry();
}
return instance;
}
Iterable<? extends DbXRefResolver> getResolvers() {
// service provider lookup von resolvern
Iterator<DbXRefResolver> it = ServiceLoader.load(DbXRefResolver.class, this.getClass().getClassLoader()).iterator();
List<DbXRefResolver> l = new LinkedList<>();
while (it.hasNext()) {
l.add(it.next());
}
return l;
// service provider lookup von resolvern
Iterator<DbXRefResolver> it = ServiceLoader.load(DbXRefResolver.class, this.getClass().getClassLoader()).iterator();
List<DbXRefResolver> l = new LinkedList<>();
while (it.hasNext()) {
l.add(it.next());
}
return l;
}
/**
......@@ -70,14 +70,14 @@ public class DbXRefResourceRegistry implements DbXRefService {
* @return
*/
List<? extends DbXRefResolver> getResolversFor(DbXRef ref) {
List<DbXRefResolver> result = new LinkedList<>();
for (DbXRefResolver dbXRefResolver : getResolvers()) {
if (dbXRefResolver.canHandle(ref)) {
result.add(dbXRefResolver);
}
}
return result;
List<DbXRefResolver> result = new LinkedList<>();
for (DbXRefResolver dbXRefResolver : getResolvers()) {
if (dbXRefResolver.canHandle(ref)) {
result.add(dbXRefResolver);
}
}
return result;
}
/**
......@@ -87,7 +87,7 @@ public class DbXRefResourceRegistry implements DbXRefService {
* @return
*/
public boolean hasResolverFor(DbXRef ref) {
return !getResolversFor(ref).isEmpty();
return !getResolversFor(ref).isEmpty();
}
/**
......@@ -97,62 +97,63 @@ public class DbXRefResourceRegistry implements DbXRefService {
*/
@Override
public Collection<? extends Resource> resolve(DbXRef ref) {
List<Resource> result = new LinkedList<>();
List<Resource> result = new LinkedList<>();
if (!hasResolverFor(ref)) {
throw new DbXrefResourceException("No handler found for database '" + ref.getDatabase() + "'. Supported databases: " + getSupportedDatabases());
}
if (!hasResolverFor(ref)) {
throw new DbXrefResourceException("No handler found for database '" + ref.getDatabase() + "'. Supported databases: " + getSupportedDatabases());
}
for (DbXRefResolver dbXResource : getResolversFor(ref)) {
result.addAll(dbXResource.resolve(ref));
}
return result;
for (DbXRefResolver dbXResource : getResolversFor(ref)) {
result.addAll(dbXResource.resolve(ref));
}
return result;
}
/**
* {@inheritDoc}
*
* @throws DbXrefResourceException If no handler could be found.
* @throws DbXrefResourceException If no handler can be found.
*/
@Override
public <T extends Resource> Collection<? extends T> resolve(DbXRef ref, Class<T> targetClass) {
Set<T> result = new HashSet<>();
Set<T> result = new HashSet<>();
if (!hasResolverFor(ref)) {
throw new DbXrefResourceException("No handler found for database '" + ref.getDatabase() + "'. Supported databases: " + getSupportedDatabases());
}
if (!hasResolverFor(ref)) {
throw new DbXrefResourceException("No handler found for database '" + ref.getDatabase() + "'. Supported databases: " + getSupportedDatabases());
}
for (DbXRefResolver dbXResource : getResolversFor(ref)) {
result.addAll(filter(dbXResource.resolve(ref), targetClass));
}
for (DbXRefResolver dbXResource : getResolversFor(ref)) {
result.addAll(filter(dbXResource.resolve(ref), targetClass));
}
return result;
return result;
}
public <T extends Resource> Collection<? extends T> filter(Iterable<? extends Resource> iterable, Class<T> targetClass) {
List<T> filtered = new LinkedList<>();
for (Resource r : iterable) {
if (targetClass.isInstance(r)) {
filtered.add(targetClass.cast(r));
}
}
return filtered;
List<T> filtered = new LinkedList<>();
for (Resource r : iterable) {
if (targetClass.isInstance(r)) {
filtered.add(targetClass.cast(r));
}
}
return filtered;
}
private Set<String> getSupportedDatabases() {
Set<String> set = new LinkedHashSet<>();
for (DbXRefResolver dbXRefResolver : getResolvers()) {
Iterables.addAll(set, dbXRefResolver.getDatabasePrefixes());
}
return set;
Set<String> set = new LinkedHashSet<>();
for (DbXRefResolver dbXRefResolver : getResolvers()) {
Iterables.addAll(set, dbXRefResolver.getDatabasePrefixes());
}
return set;
}
@Override
public DbXRef create(CharSequence database, CharSequence identifier) {
return new SimpleDbXRef(database.toString(), identifier.toString());
return new SimpleDbXRef(database.toString(), identifier.toString());
}
@Override
public DbXRef create(CharSequence dbxref) {
return new DbXrefParser().parse(dbxref.toString());
return new DbXrefParser().parse(dbxref.toString());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment