// Path: src/main/java/de/dwslab/risk/gui/exception/RoCAException.java
// public class RoCAException extends RuntimeException {
// 
//     /** */
//     private static final long serialVersionUID = -6069816604710951328L;
// 
//     public RoCAException(String message) {
//         super(message);
//     }
// 
//     public RoCAException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
// }


import java.util.concurrent.atomic.AtomicInteger;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import de.dwslab.risk.gui.exception.RoCAException;

package de.dwslab.risk.gui.model;




public class Entity implements UserObject {

    private static final long serialVersionUID = -566950411586680045L;

    private static final AtomicInteger NEXT_ID = new AtomicInteger();
    private static final Cache<Integer, Entity> BY_ID = CacheBuilder.newBuilder().weakValues()
            .build();
    private static final Cache<String, Entity> BY_NAME = CacheBuilder.newBuilder().weakValues()
            .build();
    private final int id = NEXT_ID.getAndIncrement();

    private String name;
    private Boolean offline;
    private Type type;

    protected Entity(String name, Type type) {
        this(name, type, null);
    }

    private Entity(String name, Type type, Boolean offline) {
        this.name = name;
        this.type = type;
        this.offline = offline;
    }

    public static Entity get(int id) {
        Entity entity = BY_ID.getIfPresent(id);
        if (entity == null) {
            throw new RoCAException("Entity not found: ID " + id);
        }
        return entity;
    }

    /**
     * Get the entity with the specified name if it exists, throw an exception otherwise. Beware
     * that this method returns the last created entity with that name. There might be additional
     * entities with the same name but a different ID.
     *
     * @param name
     * @return
     * @throws RoCAException
     */

// Path: src/main/java/de/dwslab/risk/gui/exception/RoCAException.java
// public class RoCAException extends RuntimeException {
// 
//     /** */
//     private static final long serialVersionUID = -6069816604710951328L;
// 
//     public RoCAException(String message) {
//         super(message);
//     }
// 
//     public RoCAException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
// }


// Path: src/main/java/de/dwslab/risk/gui/model/Entity.java
import java.util.concurrent.atomic.AtomicInteger;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import de.dwslab.risk.gui.exception.RoCAException;

package de.dwslab.risk.gui.model;




public class Entity implements UserObject {

    private static final long serialVersionUID = -566950411586680045L;

    private static final AtomicInteger NEXT_ID = new AtomicInteger();
    private static final Cache<Integer, Entity> BY_ID = CacheBuilder.newBuilder().weakValues()
            .build();
    private static final Cache<String, Entity> BY_NAME = CacheBuilder.newBuilder().weakValues()
            .build();
    private final int id = NEXT_ID.getAndIncrement();

    private String name;
    private Boolean offline;
    private Type type;

    protected Entity(String name, Type type) {
        this(name, type, null);
    }

    private Entity(String name, Type type, Boolean offline) {
        this.name = name;
        this.type = type;
        this.offline = offline;
    }

    public static Entity get(int id) {
        Entity entity = BY_ID.getIfPresent(id);
        if (entity == null) {
            throw new RoCAException("Entity not found: ID " + id);
        }
        return entity;
    }

    /**
     * Get the entity with the specified name if it exists, throw an exception otherwise. Beware
     * that this method returns the last created entity with that name. There might be additional
     * entities with the same name but a different ID.
     *
     * @param name
     * @return
     * @throws RoCAException
     */

    public static Entity get(String name) throws RoCAException {
