/** * Method returns the state source(s) result(s) (contains state value(s)) of the input handleState. * * @param handleState The HandleState. * @return state source(s) result(s) of the input state. */ private List<RdfNodeObject> handleStateSources(final HandleState handleState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String handlePositionVal = "\"" + String.valueOf(handleState.getPosition()) + "\"^^xsd:double"; stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(handlePositionVal);}}, true)); return stateSources; }
public static String transform(final HandleState value) throws CouldNotTransformException { switch (value.getPosition()) { case 0: return "CLOSED"; case 90: return "OPEN"; case 180: return "TILTED"; default: throw new CouldNotTransformException("Could not transform " + HandleState.class.getName() + "[" + value + "] to " + String.class.getSimpleName() + "!"); } } }
@Override protected void updateDynamicComponents() { try { switch (getProviderService().getHandleState().getPosition()) { case 0: handleStateLabel.setForeground(Color.WHITE); handleStatePanel.setBackground(Color.BLUE); break; case 180: handleStateLabel.setForeground(Color.BLACK); handleStatePanel.setBackground(Color.CYAN); break; case 90: handleStateLabel.setForeground(Color.WHITE); handleStatePanel.setBackground(Color.GREEN); break; default: throw new InvalidStateException("State[" + getProviderService().getHandleState().getPosition() + "] is unknown."); } handleStateLabel.setText("Current HandleState = " + getProviderService().getHandleState().getPosition()); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger, LogLevel.ERROR); } } }
@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(); } }
public static String transform(final HandleState handleState) throws CouldNotTransformException { try { switch (handleState.getPosition()) { case 0: return "CLOSED"; case 90: return "OPEN"; case 180: return "TILTED"; default: throw new TypeNotSupportedException(handleState, String.class); } } catch (CouldNotPerformException ex) { throw new CouldNotTransformException("Could not transform " + HandleState.class.getName() + "!", ex); } } }