com.flash3388.flashlib.io.devices.GroupBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flashlib.core.io Show documentation
Show all versions of flashlib.core.io Show documentation
Robotics development framework (flashlib.core.io)
The newest version!
package com.flash3388.flashlib.io.devices;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
public class GroupBuilder> {
private final DeviceInterface mDeviceInterface;
private final Function, T> mCreator;
private final List mParts;
private final Class mElementType;
GroupBuilder(DeviceInterface deviceInterface, Function, T> creator, Class elementType) {
mDeviceInterface = deviceInterface;
mCreator = creator;
mElementType = elementType;
mParts = new ArrayList<>();
}
public GroupBuilder add(E e) {
mParts.add(e);
return this;
}
/**
* Finds a registered implementation for the given ID which matches the wanted type.
* Once the implementation is found, a constructor is matched to the given arguments
* count and an instance is created.
*
* @param id implementation identifier
* @param type type which the implementation must support (usually interface)
* @param namedArgs arguments to the constructor
* @return this
* @param type which the implementation must support
*
* @see DeviceInterface#newDevice(int, Class, Map)
*/
public GroupBuilder addNewDevice(int id, Class type, Map namedArgs) {
E2 device = mDeviceInterface.newDevice(id, type, namedArgs);
return add(device);
}
/**
* Finds a registered implementation for the given ID which matches the wanted type.
* Once the implementation is found, a constructor is matched to the given arguments
* count and an instance is created.
*
* @param id implementation identifier
* @param namedArgs arguments to the constructor
* @return this
*
* @see DeviceInterface#newDevice(int, Class, Map)
*/
public GroupBuilder addNewDevice(int id, Map namedArgs) {
return addNewDevice(id, mElementType, namedArgs);
}
/**
* Finds a registered implementation for the given ID which matches the wanted type.
* Once the implementation is found, a constructor is matched to the given arguments
* count and an instance is created.
*
* @param id implementation identifier
* @param namedArgs arguments to the constructor
* @return this
*
* @see DeviceInterface#newDevice(int, Class, Map)
*/
public GroupBuilder addNewDevice(DeviceId id, Map namedArgs) {
return addNewDevice(id.id(), mElementType, namedArgs);
}
public T build() {
return mCreator.apply(mParts);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy