@Test public void calculateHash() { JudgmentEnrichmentTags judgmentWithTags = new JudgmentEnrichmentTags(3L); judgmentWithTags.addEnrichmentTag(createEnrichmentTag(3L, "B_SOME_TAG_VALUE", "{key:'value1'}")); judgmentWithTags.addEnrichmentTag(createEnrichmentTag(3L, "A_SOME_TAG_VALUE", "{key:'value2'}")); judgmentWithTags.addEnrichmentTag(createEnrichmentTag(4L, "TAG_WITH_REFERENCE", "{judgmentId:3}")); judgmentWithTags.addEnrichmentTag(createEnrichmentTag(2L, "TAG_WITH_REFERENCE", "{judgmentId:3}")); String hash = judgmentEnrichmentTagsHashCalculator.calculateHash(judgmentWithTags); String expectedHash = DigestUtils.md5Hex( ("2:TAG_WITH_REFERENCE:{'judgmentId':3}" + "::3:A_SOME_TAG_VALUE:{'key':'value2'}" + "::3:B_SOME_TAG_VALUE:{'key':'value1'}" + "::4:TAG_WITH_REFERENCE:{'judgmentId':3}").replace('\'', '"')); assertEquals(expectedHash, hash); }
public String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags) { Preconditions.checkNotNull(judgmentEnrichmentTags); if (judgmentEnrichmentTags.getEnrichmentTags().size() == 0) { return null; } String value = judgmentEnrichmentTags.getEnrichmentTags().stream() .sorted(Comparator.comparing(EnrichmentTag::getJudgmentId).thenComparing(EnrichmentTag::getTagType)) .map(tag -> tag.getJudgmentId() + TAG_VALUES_SEPARATOR + tag.getTagType() + TAG_VALUES_SEPARATOR + tag.getValue()) .collect(Collectors.joining(TAG_SEPARATOR)); String hash = DigestUtils.md5Hex(value); return hash; }
JudgmentEnrichmentTagsHashCalculator { public String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags) { Preconditions.checkNotNull(judgmentEnrichmentTags); if (judgmentEnrichmentTags.getEnrichmentTags().size() == 0) { return null; } String value = judgmentEnrichmentTags.getEnrichmentTags().stream() .sorted(Comparator.comparing(EnrichmentTag::getJudgmentId).thenComparing(EnrichmentTag::getTagType)) .map(tag -> tag.getJudgmentId() + TAG_VALUES_SEPARATOR + tag.getTagType() + TAG_VALUES_SEPARATOR + tag.getValue()) .collect(Collectors.joining(TAG_SEPARATOR)); String hash = DigestUtils.md5Hex(value); return hash; } }
JudgmentEnrichmentTagsHashCalculator { public String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags) { Preconditions.checkNotNull(judgmentEnrichmentTags); if (judgmentEnrichmentTags.getEnrichmentTags().size() == 0) { return null; } String value = judgmentEnrichmentTags.getEnrichmentTags().stream() .sorted(Comparator.comparing(EnrichmentTag::getJudgmentId).thenComparing(EnrichmentTag::getTagType)) .map(tag -> tag.getJudgmentId() + TAG_VALUES_SEPARATOR + tag.getTagType() + TAG_VALUES_SEPARATOR + tag.getValue()) .collect(Collectors.joining(TAG_SEPARATOR)); String hash = DigestUtils.md5Hex(value); return hash; }  }
JudgmentEnrichmentTagsHashCalculator { public String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags) { Preconditions.checkNotNull(judgmentEnrichmentTags); if (judgmentEnrichmentTags.getEnrichmentTags().size() == 0) { return null; } String value = judgmentEnrichmentTags.getEnrichmentTags().stream() .sorted(Comparator.comparing(EnrichmentTag::getJudgmentId).thenComparing(EnrichmentTag::getTagType)) .map(tag -> tag.getJudgmentId() + TAG_VALUES_SEPARATOR + tag.getTagType() + TAG_VALUES_SEPARATOR + tag.getValue()) .collect(Collectors.joining(TAG_SEPARATOR)); String hash = DigestUtils.md5Hex(value); return hash; }  String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags); }
JudgmentEnrichmentTagsHashCalculator { public String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags) { Preconditions.checkNotNull(judgmentEnrichmentTags); if (judgmentEnrichmentTags.getEnrichmentTags().size() == 0) { return null; } String value = judgmentEnrichmentTags.getEnrichmentTags().stream() .sorted(Comparator.comparing(EnrichmentTag::getJudgmentId).thenComparing(EnrichmentTag::getTagType)) .map(tag -> tag.getJudgmentId() + TAG_VALUES_SEPARATOR + tag.getTagType() + TAG_VALUES_SEPARATOR + tag.getValue()) .collect(Collectors.joining(TAG_SEPARATOR)); String hash = DigestUtils.md5Hex(value); return hash; }  String calculateHash(JudgmentEnrichmentTags judgmentEnrichmentTags);  }