protected Optional<String> getEntityId(T value) { if (value instanceof AbstractEntityAdjunct) { Entity entity = ((AbstractEntityAdjunct)value).getEntity(); return Optional.fromNullable(entity == null ? null : entity.getId()); } return Optional.absent(); } protected abstract T getInstanceFromId(Optional<Entity> entity, String id);
/** As {@link #highlightTriggers(String)} but convenience to generate a message given a list of sensors and list of sources (entity or string description) */ protected <T,U> void highlightTriggers(Iterable<? extends Sensor<? extends T>> sensors, Iterable<U> sources) { StringBuilder msg = new StringBuilder("Listening for "); if (sensors==null || Iterables.isEmpty(sensors)) { msg.append("<nothing>"); } else { String sensorsText = MutableSet.<Object>copyOf(sensors).stream() .filter(s -> s != null) .map(s -> (s instanceof Sensor ? ((Sensor<?>) s).getName() : s.toString())) .collect(Collectors.joining(", ")); msg.append(sensorsText); } if (sources!=null && !Iterables.isEmpty(sources)) { String sourcesText = MutableSet.<Object>copyOf(sources).stream() .filter(s -> s != null) .map(s -> (s.equals(getEntity()) ? "self" : s.toString())) .collect(Collectors.joining(", ")); if (!"self".equals(sourcesText)) { msg.append(" on ").append(sourcesText); } } highlightTriggers(msg.toString()); }