package ch.usi.dag.dislreserver.shadow;

// TODO ShadowString should better handle if String data are not send
//      over network - throw a runtime exception ??
public class ShadowString extends ShadowObject {

    private String value;

    public ShadowString(long net_ref, String value, ShadowClass klass) {
        super(net_ref, klass);
        this.value = value;
    }

    // TODO warn user that it will return null when the ShadowString is not yet
    // sent.
    @Override
    public String toString() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public boolean equals(Object obj) {

        if (super.equals(obj)) {

            if (obj instanceof ShadowString) {

                if (value != null && value.equals(((ShadowString) obj).value)) {
                    return true;
                }
            }
        }

        return false;
    }

    @Override
    public int hashCode() {
        throw new UnsupportedOperationException("overriden equals, not overriden hashCode");
    }
}

@@ -543,23 +543,16 @@
  %7D%0A%0A    
-public 
 void set
@@ -648,16 +648,22 @@
  equals(
+final 
 Object o
@@ -664,24 +664,66 @@
 ject obj) %7B%0A
+        // FIXME LB: This needs a comment!
 %0A        if 
@@ -735,16 +735,17 @@
 r.equals
+ 
 (obj)) %7B
@@ -741,25 +741,24 @@
 ls (obj)) %7B%0A
-%0A
             
@@ -792,17 +792,16 @@
 ring) %7B%0A
-%0A
         
@@ -812,69 +812,92 @@
     
-if (value != null && value.equals(((ShadowString) obj).value)
+final ShadowString that = (ShadowString) obj;%0A                if (this.value != null
 ) %7B%0A
@@ -928,11 +928,37 @@
 rn t
-rue
+his.value.equals (that.value)
 ;%0A  
@@ -1081,89 +1081,463 @@
     
-throw new UnsupportedOperationException(%22overriden
+//%0A        // If two shadow strings are considered equal by the above equals()%0A        // method, then they certainly have the same hash code, because it%0A        // is derived from objectId (which in turn is derived from object tag,%0A        // a.k.a. net reference) that is ensured to be equal by the call to%0A        // super.equals().%0A        //%0A        // If they are not
  equal
-s
 , no
-t overriden 
+body cares about the hash code.%0A        //%0A        return super.
 hashCode
 %22);%0A
@@ -1536,9 +1536,10 @@
 Code
-%22
+ (
 );%0A 

use the ShadowObject implementation of hashcode() to go with the existing equals() implementation.