PrototypesRegistry.java

mudlibs/tinylib/src/net/sourceforge/pain/tinylib/data/PrototypesRegistry.java · 1.5 KB

From the archive pain_0_45.tgz

Download the archive   « Back to the archive contents

package net.sourceforge.pain.tinylib.data;

import net.sourceforge.pain.data.role.*;
import net.sourceforge.pain.db.*;

import java.util.*;

/**
 * PAiN  Date: 14.06.2003  Time: 0:58:00
 */
public final class PrototypesRegistry extends DbObject {
    private static final int PROTOTYPES_MAP = 0;
    private static final int NFIELDS = 1;

    public PrototypesRegistry() {
    }

    public PrototypesRegistry(PainDB db) {
        super(db);
    }

    protected DbClassSchema provideSchema() {
        byte types[] = new byte[NFIELDS];
        String names[] = new String[NFIELDS];

        types[PROTOTYPES_MAP] = DbType.STRING_KEY_MAP;
        names[PROTOTYPES_MAP] = "prototypesMap";

        return new DbClassSchema(types, names);

    }

    public Map getPrototypesMap() {
        return getStringKeyMap(PROTOTYPES_MAP);
    }

    public boolean isVnumInUse(String vnum) {
        return getPrototypesMap().containsKey(vnum);
    }

    public void registerPrototype(Prototype p) {
        final Map map = getPrototypesMap();
        final String vnum = p.getVnum();
        if (map.get(vnum) != null) {
            throw new RuntimeException("vnum is already in use!:" + vnum);
        }
        map.put(vnum, p);
    }

    public PrototypeInfo getPrototypeByVnum(String vnum) {
        return (PrototypeInfo) getPrototypesMap().get(vnum);
    }

    public void unregisterPrototype(PrototypeInfo p) {
        getPrototypesMap().remove(p.getVnum());
    }
}

Site Stats

Snippets: 1791
Codebases: 571