Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. private List<NprDto> getUniqueAccountList(List<NprDto> nonUniqueAccountList) throws Exception {
  2.  
  3. Map<Long,NprDto> uniqueAccountsMapList = new HashMap<Long,NprDto>();
  4. List<NprDto> uniqueAccountsList = null;
  5.  
  6. if(nonUniqueAccountList != null && !nonUniqueAccountList.isEmpty()) {
  7. for(NprDto nprDto : nonUniqueAccountList) {
  8. uniqueAccountsMapList.put(Long.valueOf(nprDto.getAccountId()), nprDto);
  9. }
  10. }
  11.  
  12. uniqueAccountsList = new ArrayList<NprDto>(uniqueAccountsMapList.values());
  13.  
  14. return uniqueAccountsList;
  15.  
  16. }
  17.  
  18. class NprDto{
  19. Long accountId;
  20. .......
  21.  
  22. @Override
  23. public boolean equals(Object obj) {
  24. NproDto other=(NproDto) obj;
  25. return this.accountId==other.accountId;
  26. }
  27.  
  28. @Override
  29. public int hashCode() {
  30. return accountId.hashCode();
  31. }
  32. }
  33.  
  34. private Set<NprDto> getUniqueAccountSet(){
  35. Map<Long,NprDto> uniqueAccountsMapList = new HashMap<Long,NprDto>();
  36. Set<NprDto> uniqueAccounts = new HashSet<NprDto>(uniqueAccountsMapList.values());
  37. return uniqueAccounts;
  38.  
  39. }
  40.  
  41. private List<NprDto> getUniqueAccountList(List<NprDto> nonUniqueAccountList) {
  42. return new ArrayList<NprDto>(new LinkedHashSet<NprDto>(nonUniqueAccountList));
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement