/* * Copyright (C) 2026 welterde * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package de.welterde.em; import de.welterde.em.io.EntityRecord; /** * * @author welterde */ public abstract class EntityBase implements Entity { protected EntityStorage ctx; protected int id; public EntityBase() { this.id = -1; this.ctx = null; } public EntityBase(EntityStorage ctx, int id) { this.id = id; this.ctx = ctx; } public EntityBase(EntityRecord r) { this.id = r.getID(); this.ctx = r.getContext(); } public int getEntityId() { if(this.id == -1) throw new IllegalStateException("Entity not initialized"); return this.id; } public void initEntity(EntityStorage ctx, int id) { if((this.id != -1) && (this.ctx != null)) throw new IllegalStateException("Entity already initialized"); if(id == -1) throw new IllegalArgumentException("Invalid ID -1"); if(ctx == null) throw new NullPointerException("Context is null"); this.id = id; this.ctx = ctx; } public boolean isEntityInitialized() { return this.id != -1; } }