20 package net.sf.gridarta.model.autojoin;
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.IdentityHashMap;
26 import java.util.List;
31 import org.apache.log4j.Category;
32 import org.apache.log4j.Logger;
33 import org.jetbrains.annotations.NotNull;
55 public static final int SIZE = 16;
59 public static final int NORTH = 1;
61 public static final int EAST = 2;
63 public static final int SOUTH = 4;
65 public static final int WEST = 8;
93 final ArrayList<List<R>> newArchetypes =
new ArrayList<>();
95 for (
final List<R> archetypeList : archetypes) {
96 newArchetypes.add(
validate(archetypeList));
99 if (newArchetypes.size() >
SIZE) {
101 }
else if (newArchetypes.size() <
SIZE) {
105 newArchetypes.trimToSize();
106 this.archetypes = newArchetypes;
118 final ArrayList<R> result =
new ArrayList<>();
119 final Map<R, R> tmp =
new IdentityHashMap<>();
120 for (
final R archetype : archetypeList) {
121 if (archetype == null) {
122 throw new IllegalArgumentException();
125 if (tmp.put(archetype, archetype) != null) {
129 result.add(archetype);
131 if (result.isEmpty()) {
144 for (
int i = 0; i <
SIZE; i++) {
145 if (archetypes.get(i).contains(archetype)) {
150 LOG.warn(
"Error in AutojoinList.get_index: index not found");
161 for (
int i = 0; i <
SIZE; i++) {
162 if (archetypes.get(i).get(0) == archetype) {
177 for (
int i = 0; i <
SIZE; i++) {
178 final List<R> tmp = archetypes.get(i);
179 if (tmp.get(0) != archetype && tmp.contains(archetype)) {
192 return archetypes.get(index).get(0);
202 return Collections.unmodifiableCollection(archetypes.get(index));
R getArchetype(final int index)
TypeMayBeWeakened
static final Category LOG
The Logger for printing log messages.
final List< List< R > > archetypes
Maps index to list of archetypes representing autojoin-able archetypes for this direction.
static< R extends Archetype<?, ?, R > List< R > validate(@NotNull final Iterable< R > archetypeList)
Validates a list of archetypes: no entry must be.
AutojoinList(@NotNull final Iterable< List< R >> archetypes)
Create an AutojoinList.
Contains a list of (typically wall-)arches which do autojoining.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
boolean isMainIndex(@NotNull final R archetype)
Returns the index of an Archetype if it is a main archetype for any direction.
GameObjects are the objects based on Archetypes found on maps.
Exception thrown if an AutojoinList is invalid.
int getAlternativeIndex(@NotNull final R archetype)
Returns the index of an Archetype if it is an alternative archetype for any direction.
int getIndex(@NotNull final R archetype)
Looks up the given node in the archetype array of this class.
Iterable< R > getArchetypes(final int index)
Returns all archetypes for an index.
static final int SIZE
The number of archetypes in an autojoin list.
static final long serialVersionUID
The serial version UID.
Interface for MapArchObjects.