package net.davidvoid.thor.lightning.entity;

import static org.junit.Assert.fail;
import static org.springframework.util.Assert.isTrue;
import static org.springframework.util.Assert.notNull;

public abstract class Entity {
    Long id = null;

    /**
     * Every entity saved to DB will have a unique ID assigned, so if 
     * the entity has a valid id, then we can assumes this entity has already
     * been saved to DB.
     */
    public boolean has_valid_id() {
        return id != null;
    }

    public Object getId() {
        isTrue(has_valid_id());
        
        return id;
    }
    
    public void setId(long id) {
        this.id = (Long) id;
    }

    public void setId(Object id) {
        notNull(id);
        
        if (id instanceof Long) {
            this.id = (Long) id;
        } else if (id instanceof Integer) {
            this.id = ((Integer)id).longValue();
        } else {
            fail();
        }
    }

    public void setInvalidId() {
        id = null;
    }
    
    public static boolean is_valid_id(Object id) {
        return id != null && ((id instanceof Integer) || (id instanceof Long));
    }
}

@@ -45,46 +45,8 @@
 %0D%0A%0D%0A
-import static org.junit.Assert.fail;%0D%0A
 impo
@@ -901,15 +901,10 @@
    %7D
- else %7B
+%0D%0A
 %0D%0A  
@@ -913,30 +913,80 @@
     
-    fail();%0D%0A        %7D
+throw new IllegalArgumentException(%22id should only be Long or Integer%22);
 %0D%0A  

use IllegalArgumentException