public Map<String, Object> asMap() { Map<String, Object> result = Maps.newLinkedHashMap(); for (Map.Entry<Collection<String>, Object> entry : values.entrySet()) { String sensorName = Joiner.on('.').join(entry.getKey()); Object val = (isNull(entry.getValue())) ? null : entry.getValue(); result.put(sensorName, val); } return result; }
/** * Gets the value * * @param path the path of the value to get * @return the value * @throws IllegalArgumentException path is null or empty. */ public Object getValue(Collection<String> path) { // TODO previously this would return a map of the sub-tree if the path matched a prefix of a group of sensors, // or the leaf value if only one value. Arguably that is not required - what is/was the use-case? // checkPath(path); Object result = values.get(path); return (isNull(result)) ? null : result; }
/** * Updates the value. * * @param path the path to the value. * @param newValue the new value * @return the old value. * @throws IllegalArgumentException if path is null or empty */ // TODO path must be ordered(and legal to contain duplicates like "a.b.a"; list would be better public <T> T update(Collection<String> path, T newValue) { checkPath(path); if (newValue == null) { newValue = typedNull(); } if (log.isTraceEnabled()) { log.trace("setting sensor {}={} for {}", new Object[] {path, newValue, entity}); } T oldValue = (T) values.put(path, newValue); return (isNull(oldValue)) ? null : oldValue; }
public <T> T updateWithoutPublishing(AttributeSensor<T> attribute, T newValue) { if (log.isTraceEnabled()) { Object oldValue = getValue(attribute); if (!Objects.equal(oldValue, newValue != null)) { log.trace("setting attribute {} to {} (was {}) on {}", new Object[] {attribute.getName(), newValue, oldValue, entity}); } else { log.trace("setting attribute {} to {} (unchanged) on {}", new Object[] {attribute.getName(), newValue, this}); } } T oldValue = (T) update(attribute.getNameParts(), newValue); return (isNull(oldValue)) ? null : oldValue; }