Source:
public void applyTo(TaskAttribute taskAttribute) { Assert.isNotNull(taskAttribute); TaskData taskData = taskAttribute.getTaskData(); TaskAttributeMapper mapper = taskData.getAttributeMapper(); taskAttribute.getMetaData().defaults().setType("BuildResult"); Function<BuildResult, String> groupFunction = new Function<BuildResult, String>() { @Override public String apply(BuildResult source) { return source.getJobName(); } }; final Multimap<String, BuildResult> buildsByJobName = Multimaps.index(this.buildResults, groupFunction); int i = 0; for (Entry<String, Collection<BuildResult>> jobEntry : buildsByJobName.asMap().entrySet()) { BuildResult result = Collections.max(jobEntry.getValue(), new Comparator<BuildResult>() { @Override public int compare(BuildResult o1, BuildResult o2) { return Integer.compare(o1.getBuildNumber(), o2.getBuildNumber()); } }); TaskAttribute buildAttribute = taskAttribute.createAttribute(BUILD_RESULT_SCHEMA + i); buildAttribute.getMetaData().defaults().setType("BuildResult"); if (result.getBuildUrl() != null) { TaskAttribute child = buildAttribute.createAttribute(URL_ATTRIBUTE_KEY); child.getMetaData().defaults().setType("BuildResult"); mapper.setValue(child, result.getBuildUrl()); } if (result.getBuildStatus() != null) { TaskAttribute child = buildAttribute.createAttribute(STATUS_ATTRIBUTE_KEY); child.getMetaData().defaults().setType("BuildResult"); mapper.setValue(child, result.getBuildStatus().toString()); } if (result.getBuildNumber() > -1) { TaskAttribute child = buildAttribute.createAttribute(BUILD_NUMBER_ATTRIBUTE_KEY); child.getMetaData().defaults().setType("BuildResult"); mapper.setValue(child, String.valueOf(result.getBuildNumber())); } if (result.getJobName() != null) { TaskAttribute child = buildAttribute.createAttribute(JOB_NAME_ATTRIBUTE_KEY); child.getMetaData().defaults().setType("BuildResult"); mapper.setValue(child, result.getJobName()); } i++; } }

Target:
public void applyTo(TaskAttribute taskAttribute) { Assert.isNotNull(taskAttribute); TaskData taskData = taskAttribute.getTaskData(); TaskAttributeMapper mapper = taskData.getAttributeMapper(); taskAttribute.getMetaData().defaults().setType(BUILD_RESULT_TYPE); Function<BuildResult, String> groupFunction = new Function<BuildResult, String>() { @Override public String apply(BuildResult source) { return source.getJobName(); } }; final Multimap<String, BuildResult> buildsByJobName = Multimaps.index(this.buildResults, groupFunction); int i = 0; for (Entry<String, Collection<BuildResult>> jobEntry : buildsByJobName.asMap().entrySet()) { BuildResult result = Collections.max(jobEntry.getValue(), new Comparator<BuildResult>() { @Override public int compare(BuildResult o1, BuildResult o2) { return Integer.compare(o1.getBuildNumber(), o2.getBuildNumber()); } }); TaskAttribute buildAttribute = taskAttribute.createAttribute(BUILD_RESULT_SCHEMA + i); buildAttribute.getMetaData().defaults().setType(BUILD_RESULT_TYPE); if (result.getBuildUrl() != null) { TaskAttribute child = buildAttribute.createAttribute(URL_ATTRIBUTE_KEY); child.getMetaData().defaults().setType(BUILD_RESULT_TYPE); mapper.setValue(child, result.getBuildUrl()); } if (result.getBuildStatus() != null) { TaskAttribute child = buildAttribute.createAttribute(STATUS_ATTRIBUTE_KEY); child.getMetaData().defaults().setType(BUILD_RESULT_TYPE); mapper.setValue(child, result.getBuildStatus().toString()); } if (result.getBuildNumber() > -1) { TaskAttribute child = buildAttribute.createAttribute(BUILD_NUMBER_ATTRIBUTE_KEY); child.getMetaData().defaults().setType(BUILD_RESULT_TYPE); mapper.setValue(child, String.valueOf(result.getBuildNumber())); } if (result.getJobName() != null) { TaskAttribute child = buildAttribute.createAttribute(JOB_NAME_ATTRIBUTE_KEY); child.getMetaData().defaults().setType(BUILD_RESULT_TYPE); mapper.setValue(child, result.getJobName()); } i++; } }