Enum Class Finder
- All Implemented Interfaces:
Serializable,Comparable<Finder>,Constable
For unit testing classes which depend on the Finder, set up the Finder first with a test factory (see TestHelpers in the uk.ac.gda.test.helpers bundle) and add any necessary Findables for the test to it. For example:
public void setUp() throws Exception {
// .. set up mocks first
Factory testFactory = TestHelpers.createTestFactory("test");
testFactory.addFindable(mockFindable);
Finder.addFactory(testFactory);
}
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFactory(Factory factory) Adds a factory to the list of searchable factories known by the Finder.static <T extends Findable>
TReturn a named object from any of the factories known to the finder.static <T extends Findable>
TfindLocalSingleton(Class<T> singletonClass) Returns the local singleton of specified type.findOptionalLocalSingleton(Class<T> singletonClass) Returns the local singleton of specified type.findOptionalOfType(String name, Class<T> findableType) Return a Optional named object from any of the factories known to the finder.findOptionalSingleton(Class<T> singletonClass) Returns the singleton of specified type.static <T extends Findable>
TfindSingleton(Class<T> singletonClass) Returns the singleton of specified type.getFindablesOfType(Class<T> clazz) Returns a map of allFindableobjects (local invalid input: '&' remote) of the given typegetLocalFindablesOfType(Class<T> clazz) Returns a map of all localFindableobjects of the given typeList all the interfaces available on the Finder.listFindablesOfType(Class<T> clazz) Returns a list of allFindableobjects (local invalid input: '&' remote) of the given typelistLocalFindablesOfType(Class<T> clazz) Returns a list of all localFindableobjects of the given typestatic voidstatic FinderReturns the enum constant of this class with the specified name.static Finder[]values()Returns an array containing the constants of this enum class, in the order they are declared.Generates a Jython module of Findable instances.
-
Enum Constant Details
-
INSTANCE
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
find
Return a named object from any of the factories known to the finder.- Type Parameters:
T- class of Object being returned- Parameters:
name- object to find.- Returns:
- the findable object or null if it cannot be found
-
findOptionalOfType
public static <T extends Findable> Optional<T> findOptionalOfType(String name, Class<T> findableType) Return a Optional named object from any of the factories known to the finder.- Type Parameters:
T- class of OptionalObject being returned - Parameters:
name- The object to findfindableType- The class or interface to match- Returns:
- the Optional
findable object
-
addFactory
Adds a factory to the list of searchable factories known by the Finder.- Parameters:
factory- the factory to add to the list.
-
removeAllFactories
public static void removeAllFactories() -
listAllInterfaces
List all the interfaces available on the Finder. This method is aimed at users of the scripting environment for searching for available hardware by using the 'list' command.- Returns:
- array of interface names
-
getFindablesOfType
Returns a map of allFindableobjects (local invalid input: '&' remote) of the given type- Type Parameters:
T-- Parameters:
clazz- the class or interface to match- Returns:
- a map of matching
Findables, with the object names as keys and the objects as values
-
getLocalFindablesOfType
Returns a map of all localFindableobjects of the given type- Parameters:
clazz- the class or interface to match- Returns:
- a map of matching
Findables, with the object names as keys and the objects as values
-
listFindablesOfType
Returns a list of allFindableobjects (local invalid input: '&' remote) of the given type- Parameters:
clazz- the class or interface to match- Returns:
- a list of matching
Findables
-
listLocalFindablesOfType
Returns a list of all localFindableobjects of the given type- Parameters:
clazz- the class or interface to match- Returns:
- a list of matching
Findables
-
findSingleton
Returns the singleton of specified type. This method removes the need for singletons to have a specific name.- Parameters:
singletonClass- the singleton type- Returns:
- the singleton
- Throws:
IllegalArgumentException- if multiple/no instances of specified type found
-
findLocalSingleton
Returns the local singleton of specified type. This method removes the need for singletons to have a specific name.- Parameters:
singletonClass- the singleton type- Returns:
- the singleton
- Throws:
IllegalArgumentException- if multiple/no instances of specified type found
-
findOptionalSingleton
Returns the singleton of specified type. This method removes the need for singletons to have a specific name.- Parameters:
singletonClass- the singleton type- Returns:
- the singleton
- Throws:
IllegalArgumentException- if multiple instances of specified type found
-
findOptionalLocalSingleton
Returns the local singleton of specified type. This method removes the need for singletons to have a specific name.- Parameters:
singletonClass- the singleton type- Returns:
- the singleton
- Throws:
IllegalArgumentException- if multiple instances of specified type found
-
writeFindablesJythonModule
Generates a Jython module of Findable instances.
GDA properties control whether the module generation is enabled (i.e. whether the module is generated and written at all) (default:
true), the name of the module (default:gdaserver), and where the module is written (default:${gda.config}/scripts). If the module is written to a non-default directory, the non-default directory should be specified in the list of script paths of the Jython server (i.e. thecommand_serverbean) so that the module can be found when referenced from the Jython terminal or by another script.Once written, other Jython modules can access Findable objects using, e.g.:
from gdaserver import gripper_x, gripper_grp as gripper_jaws
And in Eclipse, PyDev can provide type-inferred auto-completion on:
gripper_jaws.[Ctrl-1]
Documented further on Confluence.
- Throws:
FactoryException- if the file could not be written
-