20 package net.sf.gridarta.model.archetypetype;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.HashMap;
26 import java.util.Iterator;
27 import java.util.LinkedHashMap;
28 import java.util.List;
30 import java.util.TreeMap;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
68 private final Map<String, ArchetypeTypeList>
listTable =
new HashMap<>();
75 private final Map<String, AttributeBitmask>
bitmaskTable =
new HashMap<>();
90 public int compare(@NotNull
final String o1, @NotNull
final String o2) {
91 final Integer index1 = attributeOrder.get(o1);
92 final Integer index2 = attributeOrder.get(o2);
95 return o1.compareTo(o2);
102 if (index1 < index2) {
105 if (index1 > index2) {
118 archetypeTypeList.add(archetypeType);
119 final String typeName = archetypeType.getTypeName();
120 archetypeTypeNames.put(typeName, archetypeType);
121 if (typeName.equals(
"Misc")) {
122 fallbackArchetypeType = archetypeType;
134 return archetypeTypeNames.get(typeName);
148 final ArchetypeType type = archetypeTypeNames.get(typeName.trim());
164 for (
final ArchetypeType archetypeType : archetypeTypeList) {
165 if (archetypeType.matches(baseObject)) {
166 return archetypeType;
176 return Collections.unmodifiableList(archetypeTypeList).iterator();
185 return archetypeTypeList.indexOf(archetypeType);
194 return archetypeTypeList.size();
213 listTable.put(attribute, list);
224 return listTable.
get(listName);
233 bitmaskTable.put(attribute, attributeBitmask);
243 return bitmaskTable.get(bitmaskName);
255 if (attributeOrder.containsKey(attributeName)) {
259 attributeOrder.put(attributeName, attributeOrder.size());
286 final StringBuilder sb =
new StringBuilder();
287 final Map<String, ArchetypeType> sortedArchetypeTypes =
new TreeMap<>(
archetypeTypeNames);
288 for (
final ArchetypeType archetypeType : sortedArchetypeTypes.values()) {
289 archetypeType.toString(sb);
291 return sb.toString();
Comparator< String > getAttributeOrderComparator()
Returns a Comparator that sorts attributes keys by the order defined by addAttributeOrder(String).
A set of ArchetypeAttributeDefinitions.
Manages ArchetypeType instances, list, and bitmask definitions.
final Map< String, ArchetypeTypeList > listTable
Table with List objects for lists (value) accessible by name (key).
String getDisplayName(@NotNull final Attributes baseObject)
Returns a description of this type.
ArchetypeType getArchetypeTypeByBaseObject(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns the ArchetypeType for the given BaseObject.
Contains the data of one Gridarta Object-Type.
final Map< String, ArchetypeType > archetypeTypeNames
Table with type archetype type name as keys (String), and ArchetypeType object as values (...
boolean isFallbackArchetypeType(@NotNull final ArchetypeType archetypeType)
Returns whether a given ArchetypeType is the fallback archetype type used for game objects not matchi...
int getArchetypeTypeIndex(@NotNull final ArchetypeType archetypeType)
Returns the index of an ArchetypeType instance.
AttributeBitmask getBitmask(@NotNull final String bitmaskName)
Returns a bitmask type by name.
void addArchetypeType(@NotNull final ArchetypeType archetypeType)
Adds an ArchetypeType instance.
void addList(@NotNull final String attribute, @NotNull final ArchetypeTypeList list)
Adds a list definition.
boolean addAttributeOrder(@NotNull final String attributeName)
Adds an attribute name for attribute ordering when saving.
Base package of all Gridarta classes.
This class manages bitmask values which appear in Gridarta archetype attributes.
final Map< String, AttributeBitmask > bitmaskTable
Table with AttributeBitmask objects (value) accessible by name (key).
void addBitmask(@NotNull final String attribute, @NotNull final AttributeBitmask attributeBitmask)
Adds a bitmask definition.
int getArchetypeTypeCount()
Returns the number of ArchetypeTypes in the list.
ArchetypeType fallbackArchetypeType
The default (fallback) ArchetypeType used for game objects not matching any defined type...
Pair< Integer, String > get(final int index)
Returns an entry by index.
Iterator< ArchetypeType > iterator()
final List< ArchetypeType > archetypeTypeList
Lists with all defined ArchetypeTypes.
ArchetypeType getArchetypeType(@NotNull final String typeName)
Returns an ArchetypeType by type name.
String getDisplayName(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Returns a description of this type.
ArchetypeTypeList getList(@NotNull final String listName)
Returns a list type definition.
final Map< String, Integer > attributeOrder
Attribute names in save order.
final Comparator< String > attributeOrderComparator
A Comparator that compares strings by attributeOrder.
ArchetypeType getArchetypeTypeByName(@NotNull final String typeName)
Finds and returns the type-structure (.