Source:
public String getTraitValue(ResourceContainer container, String traitName) { Integer traitScheduleId = null; Set<MeasurementScheduleRequest> schedules = container.getMeasurementSchedule(); for (MeasurementScheduleRequest schedule : schedules) { if (schedule.getName().equals(traitName)) { if (schedule.getDataType() != DataType.TRAIT) { throw new IllegalArgumentException("Measurement named [" + traitName + "] for resource [" + container.getResource().getName() + "] is not a trait, it is of type [" + schedule.getDataType() + "]"); } traitScheduleId = schedule.getScheduleId(); } } if (traitScheduleId == null) { throw new IllegalArgumentException("There is no trait [" + traitName + "] for resource [" + container.getResource().getName() + "]"); } String traitValue = getCachedTraitValue(traitScheduleId); if (traitValue == null) { Set<MeasurementScheduleRequest> requests = new HashSet<MeasurementScheduleRequest>(); requests.add(new MeasurementScheduleRequest(MeasurementScheduleRequest.NO_SCHEDULE_ID, traitName, 0, true, DataType.TRAIT)); Set<MeasurementData> dataset = getRealTimeMeasurementValue(container.getResource().getId(), requests); if (dataset.size() == 1) { Object value = dataset.iterator().next().getValue(); if (value != null) { traitValue = value.toString(); } } else if (dataset.isEmpty()) { MeasurementDataTrait value = configuration.getServerServices().getMeasurementServerService() .getLastKnownTraitValue(traitScheduleId); if (value != null) { traitValue = value.getValue(); traitCache.put(traitScheduleId, traitValue); } } else { throw new IllegalStateException( "Asked for value of trait " + traitName + " on resource " + container.getResource() + " but got more than one value back. This is unexpected."); } } return traitValue; }

Target:
public String getTraitValue(ResourceContainer container, String traitName) { Integer traitScheduleId = null; Set<MeasurementScheduleRequest> schedules = container.getMeasurementSchedule(); for (MeasurementScheduleRequest schedule : schedules) { if (schedule.getName().equals(traitName)) { if (schedule.getDataType() != DataType.TRAIT) { throw new IllegalArgumentException("Measurement named [" + traitName + "] for resource [" + container.getResource().getName() + "] is not a trait, it is of type [" + schedule.getDataType() + "]"); } traitScheduleId = schedule.getScheduleId(); } } if (traitScheduleId == null) { throw new IllegalArgumentException("There is no trait [" + traitName + "] for resource [" + container.getResource().getName() + "]"); } String traitValue = getCachedTraitValue(traitScheduleId); if (traitValue == null) { Set<MeasurementScheduleRequest> requests = new HashSet<MeasurementScheduleRequest>(); requests.add(new MeasurementScheduleRequest(MeasurementScheduleRequest.NO_SCHEDULE_ID, traitName, 0, true, DataType.TRAIT)); Set<MeasurementData> dataset = getRealTimeMeasurementValue(container.getResource().getId(), requests); if (dataset.size() == 1) { Object value = dataset.iterator().next().getValue(); if (value != null) { traitValue = value.toString(); } } else if (dataset.isEmpty()) { MeasurementDataTrait value = configuration.getServerServices().getMeasurementServerService() .getLastKnownTraitValue(traitScheduleId); if (value != null) { traitValue = value.getValue(); } } else { throw new IllegalStateException( "Asked for value of trait " + traitName + " on resource " + container.getResource() + " but got more than one value back. This is unexpected."); } } return traitValue; }