Source:
public Optional<BayesNetHmmMultipleModelsPriors> getModelPriorsByAccountIdAndDate(final Long accountId,final DateTime dateLocalUTC) { final String dateString = DateTimeUtil.dateToYmdString(dateLocalUTC); final Map<Long, byte []> finalResult = new HashMap<>(); final List<BayesNetHmmSingleModelPrior> results = Lists.newArrayList(); final List<AttributeValue> attributeValueListForDateMatch = Lists.newArrayList(); attributeValueListForDateMatch.add(new AttributeValue().withS(dateString)); final List<AttributeValue> attributeValueListForCurrentMatch = Lists.newArrayList(); attributeValueListForCurrentMatch.add(new AttributeValue().withS(CURRENT_RANGE_KEY)); final QueryResult queryResult = doQuery(accountId,attributeValueListForDateMatch); Map<String,AttributeValue> item = null; if (queryResult.getCount() == 0) { final QueryResult queryResultForCurrent = doQuery(accountId,attributeValueListForCurrentMatch); if (queryResultForCurrent.getCount() == 0) { LOGGER.info("did not find current nor date prior for user on date {}", accountId, dateString); return Optional.absent(); } item = queryResultForCurrent.getItems().iterator().next(); } else { item = queryResult.getItems().iterator().next(); } if (item == null) { LOGGER.error("something impossible happened: item was null"); return Optional.absent(); } if (!item.keySet().containsAll(targetAttributeSet)) { LOGGER.error("Missing field in item {}", item); return Optional.absent(); } final String rangeKey = item.get(RANGE_KEY).getS(); final ByteBuffer byteBuffer = item.get(PAYLOAD_KEY).getB(); results.addAll(BayesNetHmmSingleModelPrior.createListFromProtbuf(byteBuffer.array())); return Optional.of(new BayesNetHmmMultipleModelsPriors(results,rangeKey)); }

Target:
public Optional<BayesNetHmmMultipleModelsPriors> getModelPriorsByAccountIdAndDate(final Long accountId,final DateTime dateLocalUTC) { final String dateString = DateTimeUtil.dateToYmdString(dateLocalUTC); final List<BayesNetHmmSingleModelPrior> results = Lists.newArrayList(); final List<AttributeValue> attributeValueListForDateMatch = Lists.newArrayList(); attributeValueListForDateMatch.add(new AttributeValue().withS(dateString)); final List<AttributeValue> attributeValueListForCurrentMatch = Lists.newArrayList(); attributeValueListForCurrentMatch.add(new AttributeValue().withS(CURRENT_RANGE_KEY)); final QueryResult queryResult = doQuery(accountId,attributeValueListForDateMatch); Map<String,AttributeValue> item; if (queryResult.getCount() == 0) { final QueryResult queryResultForCurrent = doQuery(accountId,attributeValueListForCurrentMatch); if (queryResultForCurrent.getCount() == 0) { LOGGER.info("did not find current nor date prior for user on date {}", accountId, dateString); return Optional.absent(); } item = queryResultForCurrent.getItems().iterator().next(); } else { item = queryResult.getItems().iterator().next(); } if (item == null) { LOGGER.error("something impossible happened: item was null"); return Optional.absent(); } if (!item.keySet().containsAll(targetAttributeSet)) { LOGGER.error("Missing field in item {}", item); return Optional.absent(); } final String rangeKey = item.get(RANGE_KEY).getS(); final ByteBuffer byteBuffer = item.get(PAYLOAD_KEY).getB(); results.addAll(BayesNetHmmSingleModelPrior.createListFromProtbuf(byteBuffer.array())); return Optional.of(new BayesNetHmmMultipleModelsPriors(results,rangeKey)); }