Advertisement
Guest User

Untitled

a guest
May 25th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. boolean updateRequired = (currentValue == null && newValue != null);
  2. boolean deleteRequired = (currentValue != null && newValue == null);
  3.  
  4. if(updateRequired || deleteRequired) {
  5.  
  6. // ...
  7.  
  8. }
  9.  
  10. private static final boolean needToDoSomething(String currentValue, String newValue) {
  11. return currentValue == null && newValue != null || currentValue != null && newValue == null;
  12. }
  13.  
  14. if (needToDoSomething(currentValue, newValue)) {
  15. ....
  16. }
  17.  
  18. public enum EditState {
  19. ADDED, DELETED, MODIFIED, UNCHANGED;
  20.  
  21. public static getState(String currentValue, String newValue) {
  22. if (currentValue == newValue) {
  23. // this covers null == null too
  24. return UNCHANGED;
  25. }
  26. if (currentValue != null && newValue == null) {
  27. return DELETED;
  28. }
  29. if (newValue != null && currentValue == null) {
  30. return ADDED;
  31. }
  32. return currentValue.equals(newValue) ? UNCHANGED : MODIFIED;
  33. }
  34.  
  35.  
  36. public boolean isStateChanging() {
  37. return this != UNCHANGED;
  38. }
  39. }
  40.  
  41. EditState state = EditState.getState(currentValue, newValue);
  42.  
  43. switch (state) {
  44. case UNCHANGED :
  45. .....
  46. case DELETED :
  47. .....
  48. ....
  49. }
  50.  
  51. boolean updateRequired = (currentValue == null && newValue != null);
  52.  
  53. if( insertRequired ){
  54. //doSomething
  55. }
  56. else if( deleteRequired ){
  57. //doSomething else
  58. }
  59.  
  60. if ((currentValue == null) != (newValue == null)) {
  61. // ...
  62. }
  63.  
  64. boolean isNewValueAssigned = newvalue != null;
  65. boolean isCurrentValueAssigned = currentValue != null;
  66. if (isNewValueAssigned ^ isCurrentValueAssigned) {
  67. //Play more Galaga
  68. //do More Work
  69. }
  70.  
  71. boolean updateRequired = (newValue != null)
  72. boolean deleteRequired = (currentValue != null)
  73.  
  74. if (updateRequired || deleteRequired) {
  75. //play Galaga
  76. //do some stuff
  77. }
  78.  
  79. boolean needToDoSomething = currentValue == null ? newValue != null : newValue == null;
  80.  
  81. if(needToDoSomething) {
  82. // ...
  83. }
  84.  
  85. boolean updateRequired = (currentValue == null && newValue != null);
  86. boolean deleteRequired = (currentValue != null && newValue == null);
  87.  
  88. if (updateRequired) {
  89. object.Update();
  90. } else if (deleteRequired) {
  91. object.Delete();
  92. }
  93.  
  94. if (updateRequired) {
  95. object.Update();
  96. }
  97.  
  98. if (deleteRequired) {
  99. object.Delete();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement