com.softicar.platform.common.code.reference.point.SourceCodeReferencePointRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.code.reference.point;
import com.softicar.platform.common.core.java.classes.name.JavaClassName;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* Holds all existing {@link ISourceCodeReferencePoint} instances.
*
* @author Oliver Richers
*/
class SourceCodeReferencePointRegistry {
private static final SourceCodeReferencePointRegistry INSTANCE = new SourceCodeReferencePointRegistry();
private final Map referencePoints;
public static SourceCodeReferencePointRegistry getInstance() {
return INSTANCE;
}
public SourceCodeReferencePointRegistry() {
this.referencePoints = new SourceCodeReferencePointsLoader().loadAll();
}
/**
* Returns the matching {@link ISourceCodeReferencePoint} for the given
* {@link UUID}.
*
* @param uuid
* the {@link UUID} (never null)
* @return the {@link ISourceCodeReferencePoint} as {@link Optional}
*/
public Optional getReferencePoint(UUID uuid) {
return Optional.ofNullable(referencePoints.get(uuid));
}
/**
* Returns all instances of {@link ISourceCodeReferencePoint},
* implementing the given class.
*
* @param
* the type of class to filter for
* @param targetClass
* the class to filter for
* @return all matching instances of {@link ISourceCodeReferencePoint}
* (never null)
*/
public Collection getReferencePoints(Class targetClass) {
// TODO implement query cache to improve performance (a query cache must be thread-safe)
return referencePoints//
.values()
.stream()
.filter(targetClass::isInstance)
.map(targetClass::cast)
.sorted(Comparator.comparing(referencePoint -> new JavaClassName(referencePoint.getClass())))
.collect(Collectors.toList());
}
}