@Test public void testUUIDFromFieldsDifferentNumberOfFields() { Map<String, Object> fieldKeyMap1 = new HashMap<>(); fieldKeyMap1.put("one-field", "1"); Map<String, Object> fieldKeyMap2 = new HashMap<>(); fieldKeyMap2.put("one-field", "1"); fieldKeyMap2.put("two-field", "2"); List<String> fields = new ArrayList<>(); fields.add("one-field"); fields.add("two-field"); String uuid1 = IdGeneratorHelper.generateUUID(fieldKeyMap1, fields); String uuid2 = IdGeneratorHelper.generateUUID(fieldKeyMap2, fields); assertFalse(uuid1.equals(uuid2)); }
public static String generateUUID(Map<String, Object> data, List<String> idFields) { String uuid = null; if (CollectionUtils.isNotEmpty(idFields)) { final StringBuilder sb = new StringBuilder(); for (String idField : idFields) { if (data.containsKey(idField)) { sb.append(data.get(idField).toString()); } } String concatId = sb.toString(); if (StringUtils.isNotEmpty(concatId)) { uuid = UUID.nameUUIDFromBytes(concatId.getBytes()).toString(); } else { uuid = UUID.randomUUID().toString(); } } else { uuid = UUID.randomUUID().toString(); } return uuid; }
IdGeneratorHelper { public static String generateUUID(Map<String, Object> data, List<String> idFields) { String uuid = null; if (CollectionUtils.isNotEmpty(idFields)) { final StringBuilder sb = new StringBuilder(); for (String idField : idFields) { if (data.containsKey(idField)) { sb.append(data.get(idField).toString()); } } String concatId = sb.toString(); if (StringUtils.isNotEmpty(concatId)) { uuid = UUID.nameUUIDFromBytes(concatId.getBytes()).toString(); } else { uuid = UUID.randomUUID().toString(); } } else { uuid = UUID.randomUUID().toString(); } return uuid; } }
IdGeneratorHelper { public static String generateUUID(Map<String, Object> data, List<String> idFields) { String uuid = null; if (CollectionUtils.isNotEmpty(idFields)) { final StringBuilder sb = new StringBuilder(); for (String idField : idFields) { if (data.containsKey(idField)) { sb.append(data.get(idField).toString()); } } String concatId = sb.toString(); if (StringUtils.isNotEmpty(concatId)) { uuid = UUID.nameUUIDFromBytes(concatId.getBytes()).toString(); } else { uuid = UUID.randomUUID().toString(); } } else { uuid = UUID.randomUUID().toString(); } return uuid; } private  IdGeneratorHelper(); }
IdGeneratorHelper { public static String generateUUID(Map<String, Object> data, List<String> idFields) { String uuid = null; if (CollectionUtils.isNotEmpty(idFields)) { final StringBuilder sb = new StringBuilder(); for (String idField : idFields) { if (data.containsKey(idField)) { sb.append(data.get(idField).toString()); } } String concatId = sb.toString(); if (StringUtils.isNotEmpty(concatId)) { uuid = UUID.nameUUIDFromBytes(concatId.getBytes()).toString(); } else { uuid = UUID.randomUUID().toString(); } } else { uuid = UUID.randomUUID().toString(); } return uuid; } private  IdGeneratorHelper(); static String generateUUID(Map<String, Object> data, List<String> idFields); }
IdGeneratorHelper { public static String generateUUID(Map<String, Object> data, List<String> idFields) { String uuid = null; if (CollectionUtils.isNotEmpty(idFields)) { final StringBuilder sb = new StringBuilder(); for (String idField : idFields) { if (data.containsKey(idField)) { sb.append(data.get(idField).toString()); } } String concatId = sb.toString(); if (StringUtils.isNotEmpty(concatId)) { uuid = UUID.nameUUIDFromBytes(concatId.getBytes()).toString(); } else { uuid = UUID.randomUUID().toString(); } } else { uuid = UUID.randomUUID().toString(); } return uuid; } private  IdGeneratorHelper(); static String generateUUID(Map<String, Object> data, List<String> idFields);  }