private List<CredentialEntity> getCredentialEntities(UserEntity userEntity, String credType) { List<CredentialEntity> credentialEntities = new ArrayList<CredentialEntity>(); for (CredentialEntity entity : userEntity.getCredentials()) { if (entity.getType().equals(credType)) { credentialEntities.add(entity); } } // Avoiding direct use of credSecond.getCreatedDate() - credFirst.getCreatedDate() to prevent // Integer Overflow // Orders from most recent to least recent Collections.sort( credentialEntities, new Comparator<CredentialEntity>() { public int compare(CredentialEntity credFirst, CredentialEntity credSecond) { if (credFirst.getCreatedDate() > credSecond.getCreatedDate()) { return -1; } else if (credFirst.getCreatedDate() < credSecond.getCreatedDate()) { return 1; } else { return 0; } } }); return credentialEntities; }
private CredentialEntity getCredentialEntity(UserEntity userEntity, String credType) { for (CredentialEntity entity : userEntity.getCredentials()) { if (entity.getType().equals(credType)) { return entity; } } return null; }
@Override public List<UserCredentialValueModel> getCredentialsDirectly() { List<CredentialEntity> credentials = new ArrayList<CredentialEntity>(user.getCredentials()); List<UserCredentialValueModel> result = new ArrayList<UserCredentialValueModel>(); for (CredentialEntity credEntity : credentials) { UserCredentialValueModel credModel = new UserCredentialValueModel(); credModel.setType(credEntity.getType()); credModel.setDevice(credEntity.getDevice()); credModel.setCreatedDate(credEntity.getCreatedDate()); credModel.setValue(credEntity.getValue()); credModel.setSalt(credEntity.getSalt()); credModel.setHashIterations(credEntity.getHashIterations()); result.add(credModel); } return result; }