public static HandleState transform(final String value) throws CouldNotTransformException { switch (StringProcessor.transformToUpperCase(value)) { case "CLOSED": return HandleState.newBuilder().setPosition(0).build(); case "OPEN": return HandleState.newBuilder().setPosition(90).build(); case "TILTED": return HandleState.newBuilder().setPosition(180).build(); default: throw new CouldNotTransformException("Could not transform " + String.class.getName() + "! " + String.class.getSimpleName() + "[" + value + "] is not a valid " + HandleState.class.getSimpleName() + "!"); } }
public static HandleState transform(final String stringType) throws CouldNotTransformException { switch (stringType) { case "CLOSED": return HandleState.newBuilder().setPosition(0).build(); case "OPEN": return HandleState.newBuilder().setPosition(90).build(); case "TILTED": return HandleState.newBuilder().setPosition(180).build(); default: throw new CouldNotTransformException("Could not transform " + String.class.getName() + "! " + String.class.getSimpleName() + "[" + stringType + "] is unknown!"); } }
@Override public HandleState getHandleState(final UnitType unitType) throws NotAvailableException { // TODO: rethink position in handle state int position = 0; //boolean tilted = false; Collection<HandleStateProviderService> handleStateProviderServices = getServices(unitType); int amount = handleStateProviderServices.size(); long timestamp = 0; for (HandleStateProviderService service : handleStateProviderServices) { if (!((UnitRemote) service).isDataAvailable()) { amount--; continue; } position += service.getHandleState().getPosition(); timestamp = Math.max(timestamp, service.getHandleState().getTimestamp().getTime()); } position /= amount; return TimestampProcessor.updateTimestamp(timestamp, HandleState.newBuilder().setPosition(position), TimeUnit.MICROSECONDS, logger).build(); } }
/** * Creates a new custom unit simulator. * * @param unitController the unit to simulate. */ public HandleStateServiceSimulator(UnitController unitController) { super(unitController, ServiceType.HANDLE_STATE_SERVICE); this.simulatedHandleState = HandleState.newBuilder(); this.simulatedHandleState.setPosition(MIN_HANDLE_POSITION); }