20 package net.sf.gridarta.model.archetypeset;
22 import java.lang.ref.WeakReference;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.LinkedHashMap;
37 import org.jetbrains.annotations.NotNull;
38 import org.jetbrains.annotations.Nullable;
109 return archetypeMap.size();
115 final R archetype = archetypeMap.get(archetypeName);
116 if (archetype == null) {
130 final WeakReference<R> existingUndefinedArchetypeRef = undefinedArchetypes.get(archetypeName);
131 if (existingUndefinedArchetypeRef != null) {
132 final R existingUndefinedArchetype = existingUndefinedArchetypeRef.get();
133 if (existingUndefinedArchetype != null) {
134 return existingUndefinedArchetype;
139 undefinedArchetypes.put(archetypeName,
new WeakReference<>(newArchetype));
147 final String name = archetype.getArchetypeName();
148 if (archetypeMap.containsKey(name)) {
152 archetypeMap.put(name, archetype);
157 if (this.loadedFromArchive == loadedFromArchive) {
168 return Collections.unmodifiableCollection(archetypeMap.values());
177 listenerList.
add(listener);
182 listenerList.
remove(listener);
190 listener.loadedFromArchiveChanged();
197 archetype.setObjectFace();
void setLoadedFromArchive(final boolean loadedFromArchive)
void addArchetype(@NotNull final R archetype)
final String imageSet
The image set to use.
Interface for listeners listening to ArchetypeSet changes.
T [] getListeners()
Returns an array of all the listeners.
final ArchetypeFactory< G, A, R > archetypeFactory
The archetype factory to use.
boolean isLoadedFromArchive()
Base implementation of ArchetypeSet.
A factory for creating Archetype instances.
Base package of all Gridarta classes.
boolean loadedFromArchive
Whether Archetypes were loaded form an archive.
final EventListenerList2< ArchetypeSetListener< G, A, R > > listenerList
The ArchetypeSetListeners to inform of changes.
R getOrCreateArchetype(@NotNull final String archetypeName)
Reflects a game object (object on a map).
final Map< String, WeakReference< R > > undefinedArchetypes
The archetypes used for game objects which reference undefined archetypes.
void remove(@NotNull final T listener)
Removes a listener.
An Exception indicating that an Archetype name is not unique.
GameObjects are the objects based on Archetypes found on maps.
void add(@NotNull final T listener)
Adds a listener.
void addArchetypeSetListener(@NotNull final ArchetypeSetListener< G, A, R > listener)
Register an ArchetypeSetListener.
Collection< R > getArchetypes()
void fireLoadedFromArchiveChangedEvent()
Notifies all listeners that isLoadedFromArchive() has changed.
Exception thrown if an Archetype does not exist.
DefaultArchetypeSet(@NotNull final ArchetypeFactory< G, A, R > archetypeFactory, @Nullable final String imageSet)
Create an DefaultArchetypeSet.
final Map< String, R > archetypeMap
The defined Archetypes mapped by name.
Type-safe version of EventListenerList.
R getArchetype(@NotNull final String archetypeName)
Interface that captures similarities between different ArchetypeSet implementations.
void removeArchetypeSetListener(@NotNull final ArchetypeSetListener< G, A, R > listener)
R newUndefinedArchetype(@NotNull String archetypeName)
Creates a new undefined archetype instance.
Interface for MapArchObjects.