certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] jcerti/src/certi/rti/impl CertiLogicalTime.java


From: CERTI CVS commits
Subject: [certi-cvs] jcerti/src/certi/rti/impl CertiLogicalTime.java
Date: Thu, 15 May 2014 09:05:27 +0000

CVSROOT:        /sources/certi
Module name:    jcerti
Changes by:     Eric NOULARD <erk>      14/05/15 09:05:27

Modified files:
        src/certi/rti/impl: CertiLogicalTime.java 

Log message:
        It's better (and safer w.r.t. Liskov substitution principle)
        to sue instanceof operator than comparing class name equality.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/jcerti/src/certi/rti/impl/CertiLogicalTime.java?cvsroot=certi&r1=1.3&r2=1.4

Patches:
Index: CertiLogicalTime.java
===================================================================
RCS file: /sources/certi/jcerti/src/certi/rti/impl/CertiLogicalTime.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CertiLogicalTime.java       19 May 2010 14:11:04 -0000      1.3
+++ CertiLogicalTime.java       15 May 2014 09:05:27 -0000      1.4
@@ -53,11 +53,11 @@
      * @throws IllegalTimeArithmetic
      */
     public void decreaseBy(LogicalTimeInterval subtrahend) throws 
IllegalTimeArithmetic {
-        if (getClass() != subtrahend.getClass()) {
+        if (subtrahend instanceof CertiLogicalTimeInterval) {
+               time -= ((CertiLogicalTimeInterval) subtrahend).getInterval();  
+        } else {
             throw new IllegalTimeArithmetic("Different implementation of 
logical time supplied");
         }
-
-        time -= ((CertiLogicalTimeInterval) subtrahend).getInterval();
     }
 
     /**
@@ -83,11 +83,11 @@
      * @throws IllegalTimeArithmetic
      */
     public void increaseBy(LogicalTimeInterval addend) throws 
IllegalTimeArithmetic {
-        if (getClass() != addend.getClass()) {
+        if (addend instanceof CertiLogicalTimeInterval) {
+               time += ((CertiLogicalTimeInterval) addend).getInterval();   
+        } else {
             throw new IllegalTimeArithmetic("Different implementation of 
logical time supplied");
         }
-
-        time += ((CertiLogicalTimeInterval) addend).getInterval();
     }
 
     /**
@@ -170,11 +170,11 @@
      * @param value
      */
     public void setTo(LogicalTime value) {
-        if (getClass() != value.getClass()) {
+       if (value instanceof CertiLogicalTime) {
+               this.time = ((CertiLogicalTime) value).getTime();    
+       } else {
             throw new IllegalArgumentException("Different implementation of 
logical time supplied");
         }
-
-        this.time = ((CertiLogicalTime) value).getTime();
     }
 
     /**
@@ -183,11 +183,11 @@
      * @return
      */
     public LogicalTimeInterval subtract(LogicalTime subtrahend) {
-        if (getClass() != subtrahend.getClass()) {
+        if (subtrahend instanceof CertiLogicalTime) {
+               return new CertiLogicalTimeInterval(time - ((CertiLogicalTime) 
subtrahend).getTime());
+        } else {
             throw new IllegalArgumentException("Different implementation of 
logical time supplied");
         }
-
-        return new CertiLogicalTimeInterval(time - ((CertiLogicalTime) 
subtrahend).getTime());
     }
 
     /**
@@ -206,6 +206,7 @@
         if (getClass() != obj.getClass()) {
             return false;
         }
+        
         final CertiLogicalTime other = (CertiLogicalTime) obj;
         return this.time == other.time;
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]