com.flash3388.flashlib.io.devices.AbstractDeviceProvider 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 com.castle.reflect.exceptions.TypeException;
import com.flash3388.flashlib.util.logging.Logging;
import org.slf4j.Logger;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public abstract class AbstractDeviceProvider implements DeviceProvider {
protected static final Logger LOGGER = Logging.getMainLogger();
private final Map> mKnownTypes;
protected AbstractDeviceProvider() {
mKnownTypes = new HashMap<>();
}
@Override
public Class extends T> findDevice(int id, Class type) {
Class> storedType = mKnownTypes.get(id);
if (storedType == null) {
throw new NoSuchElementException(String.valueOf(id));
}
if (storedType.isAssignableFrom(type)) {
throw new TypeException("stored type is not assignable from wanted type");
}
//noinspection unchecked
return (Class extends T>) storedType;
}
protected void registerDevice(int id, Class> type) {
type = mKnownTypes.put(id, type);
if (type != null) {
LOGGER.warn("Device of id {} override", id);
}
}
protected void registerDevice(DeviceId id, Class type) {
registerDevice(id.id(), type);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy