Guest User

Untitled

a guest
Dec 12th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. public class OmegaEggValidator {
  2. public ValidationResults create() {
  3. Map<Integer, ValidationFailure> badEggFailureBucketMap = new HashMap<>();
  4. int eggIndex = 0;
  5. for (Iterator iterator = eggList.iterator(); iterator.hasNext(); eggIndex++) {
  6. OmegaEgg eggTobeValidated = iterator.next();
  7. if (!isValid1(eggTobeValidated)) {
  8. iterator.remove(); // Mutation
  9. // How do you cleanly map validation-failure to which validation-method failed?
  10. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_1);
  11. continue;
  12. }
  13. try {
  14. if (!isValid2(eggTobeValidated)) {
  15. iterator.remove();
  16. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_2);
  17. }
  18. } catch (Exception e) { // Repetition of same logic for exception handling
  19. iterator.remove();
  20. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_WITH_EXCEPTION_2 + e.getMessage());
  21. }
  22. try { // Inter-dependent validations
  23. if (isValid31(eggTobeValidated)) {
  24. Yellow yellowTobeValidated = extractYellow(eggTobeValidated);
  25. if (yellowTobeValidated != null) { // Nested-if for null checking nested objects
  26. try {
  27. if (!isValid32(yellowTobeValidated)) {
  28. iterator.remove();
  29. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_32);
  30. }
  31. } catch (Exception exceptionalOmegaEgg) {
  32. iterator.remove();
  33. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_WITH_EXCEPTION_32 + e.getMessage());
  34. }
  35. }
  36. } else {
  37. iterator.remove();
  38. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_2);
  39. }
  40. } catch (Exception e) {
  41. iterator.remove();
  42. badEggFailureBucketMap.put(eggIndex, VALIDATION_FAILURE_WITH_EXCEPTION + e.getMessage());
  43. }
  44. }
  45. // This algorithm is tightly coupled with One-type 'Omega',
  46. // We need to repeat the entire algo for another type.
  47. }
  48. }
Add Comment
Please, Sign In to add comment