Martin Mucha has uploaded a new change for review.

Change subject: core: replaced 'unless' with 'when'
......................................................................

core: replaced 'unless' with 'when'

'unless' with lot of negations is almost not readable(don't do
something when something is not true). Simple 'when' is much clearer(do it 
when).

• replaced 'unless' with 'when'
• negated boolean expression passed to this function to preserve same meaning

Change-Id: I027709a58c35836a461362eb4e94313ffd66e79a
Signed-off-by: Martin Mucha <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentValidator.java
1 file changed, 13 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/69/36569/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentValidator.java
index a2a93c9..7187516 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkAttachmentValidator.java
@@ -57,17 +57,22 @@
 
     public ValidationResult ipConfiguredForStaticBootProtocol() {
         IpConfiguration ipConfiguration = attachment.getIpConfiguration();
+
+        boolean failWhen = ipConfiguration != null &&
+                ipConfiguration.getBootProtocol() == 
NetworkBootProtocol.STATIC_IP &&
+                (ipConfiguration.getAddress() == null || 
ipConfiguration.getNetmask() == null);
+
         return 
ValidationResult.failWith(VdcBllMessages.NETWORK_ADDR_MANDATORY_IN_STATIC_IP)
-                .unless(ipConfiguration == null
-                        || ipConfiguration.getBootProtocol() != 
NetworkBootProtocol.STATIC_IP
-                        || ipConfiguration.getAddress() != null && 
ipConfiguration.getNetmask() != null);
+                .when(failWhen);
     }
 
     public ValidationResult bootProtocolSetForDisplayNetwork() {
         IpConfiguration ipConfiguration = attachment.getIpConfiguration();
+        boolean failWhen = (getNetworkCluster().isDisplay() &&
+                (ipConfiguration == null || ipConfiguration.getBootProtocol() 
== NetworkBootProtocol.NONE));
+
         return 
ValidationResult.failWith(VdcBllMessages.ACTION_TYPE_FAILED_DISPLAY_NETWORK_HAS_NO_BOOT_PROTOCOL)
-                .unless(!getNetworkCluster().isDisplay()
-                        || ipConfiguration != null && 
ipConfiguration.getBootProtocol() != NetworkBootProtocol.NONE);
+                .when(failWhen);
     }
 
     public ValidationResult nicExists() {
@@ -98,9 +103,10 @@
     }
 
     public ValidationResult networkNotChanged(NetworkAttachment oldAttachment) 
{
+        boolean when = oldAttachment != null &&
+                !Objects.equals(oldAttachment.getNetworkId(), 
attachment.getNetworkId());
         return 
ValidationResult.failWith(VdcBllMessages.CANNOT_CHANGE_ATTACHED_NETWORK)
-                .unless(oldAttachment == null
-                        || Objects.equals(oldAttachment.getNetworkId(), 
attachment.getNetworkId()));
+                .when(when);
     }
 
     public ValidationResult validateGateway() {


-- 
To view, visit http://gerrit.ovirt.org/36569
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I027709a58c35836a461362eb4e94313ffd66e79a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Mucha <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to