Class EntityZone<E extends Entity>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
net.demilich.metastone.game.entities.EntityZone<E>
Type Parameters:
E - The subclass of Entity that is stored. For example, Zones.BATTLEFIELD can only store Minion entities.
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<EntityZone<? extends Entity>>, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
Direct Known Subclasses:
CardZone

public class EntityZone<E extends Entity>
extends java.util.AbstractList<E>
implements java.util.List<E>, java.lang.Iterable<E>, java.lang.Cloneable, java.io.Serializable, java.lang.Comparable<EntityZone<? extends Entity>>
EntityZone is an abstract list that enforces that (1) supports gameplay-safe cloning and (2) enforces that an Entity object is only in one zone at any time.

Each zone has a corresponding Zones and owning Player ID.

See Also:
for an interface that adds additional features for lists of cards, like the and the ., Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.util.List<E> internal  
    protected java.util.Map<java.lang.Integer,​Entity> lookup  
    protected int player  
    protected Zones zone  

    Fields inherited from class java.util.AbstractList

    modCount
  • Constructor Summary

    Constructors 
    Constructor Description
    EntityZone​(int player, Zones zone, java.util.Map<java.lang.Integer,​Entity> lookup)  
  • Method Summary

    Modifier and Type Method Description
    void add​(int index, E element)  
    EntityZone<E> clone()  
    int compareTo​(@NotNull EntityZone<? extends Entity> o)  
    static EntityZone<Entity> empty​(Zones zone, int player)  
    protected void exchange​(E entity1, E entity2)  
    E get​(int index)  
    static @NotNull java.util.Comparator<Card> getManaCostComparator()  
    int getPlayer()  
    Zones getZone()  
    int indexOf​(java.lang.Object e)  
    void move​(int index, EntityZone destination, int destinationIndex)  
    void move​(Entity source, EntityZone destination)  
    E remove​(int index)  
    boolean remove​(java.lang.Object e)  
    E set​(int index, E element)  
    EntityZone<E> setLookup​(java.util.Map<java.lang.Integer,​Entity> lookup)  
    void setPlayer​(int playerIndex)  
    protected E setUnchecked​(int index, E element)  
    int size()  
    void sort​(java.util.Comparator<? super E> c)  
    static <E extends Entity>
    void
    swap​(E sourceEntity, E targetEntity, EntityZoneTable context)
    Swaps two entities with each other.
    protected void uncheckedAdd​(int index, E element)  

    Methods inherited from class java.util.AbstractList

    add, addAll, clear, equals, hashCode, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList

    Methods inherited from class java.util.AbstractCollection

    addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.List

    add, addAll, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, replaceAll, retainAll, spliterator, subList, toArray, toArray
  • Field Details

  • Constructor Details

    • EntityZone

      public EntityZone​(int player, Zones zone, java.util.Map<java.lang.Integer,​Entity> lookup)
  • Method Details

    • getManaCostComparator

      @NotNull public static @NotNull java.util.Comparator<Card> getManaCostComparator()
    • clone

      public EntityZone<E> clone()
      Overrides:
      clone in class java.lang.Object
    • get

      public E get​(int index)
      Specified by:
      get in interface java.util.List<E extends Entity>
      Specified by:
      get in class java.util.AbstractList<E extends Entity>
    • set

      public E set​(int index, E element)
      Specified by:
      set in interface java.util.List<E extends Entity>
      Overrides:
      set in class java.util.AbstractList<E extends Entity>
    • sort

      public void sort​(java.util.Comparator<? super E> c)
      Specified by:
      sort in interface java.util.List<E extends Entity>
    • setUnchecked

      protected E setUnchecked​(int index, E element)
    • add

      public void add​(int index, E element)
      Specified by:
      add in interface java.util.List<E extends Entity>
      Overrides:
      add in class java.util.AbstractList<E extends Entity>
    • uncheckedAdd

      protected void uncheckedAdd​(int index, E element)
    • remove

      public E remove​(int index)
      Specified by:
      remove in interface java.util.List<E extends Entity>
      Overrides:
      remove in class java.util.AbstractList<E extends Entity>
    • indexOf

      public int indexOf​(java.lang.Object e)
      Specified by:
      indexOf in interface java.util.List<E extends Entity>
      Overrides:
      indexOf in class java.util.AbstractList<E extends Entity>
    • remove

      public boolean remove​(java.lang.Object e)
      Specified by:
      remove in interface java.util.Collection<E extends Entity>
      Specified by:
      remove in interface java.util.List<E extends Entity>
      Overrides:
      remove in class java.util.AbstractCollection<E extends Entity>
    • move

      public void move​(int index, EntityZone destination, int destinationIndex)
    • move

      public void move​(Entity source, EntityZone destination)
    • exchange

      protected void exchange​(E entity1, E entity2)
    • size

      public int size()
      Specified by:
      size in interface java.util.Collection<E extends Entity>
      Specified by:
      size in interface java.util.List<E extends Entity>
      Specified by:
      size in class java.util.AbstractCollection<E extends Entity>
    • setPlayer

      public void setPlayer​(int playerIndex)
    • getZone

      public Zones getZone()
    • getPlayer

      public int getPlayer()
    • empty

      public static EntityZone<Entity> empty​(Zones zone, int player)
    • swap

      public static <E extends Entity> void swap​(E sourceEntity, E targetEntity, EntityZoneTable context)
      Swaps two entities with each other. They must be of the same type.
      Type Parameters:
      E - The type of the entity to swap (must be the same).
      Parameters:
      sourceEntity - One of the two entities to swap in location.
      targetEntity - One of the two entities to swap in location.
      context - An EntityZoneTable, typically a GameContext, to look up entities inside of.
    • compareTo

      public int compareTo​(@NotNull @NotNull EntityZone<? extends Entity> o)
      Specified by:
      compareTo in interface java.lang.Comparable<E extends Entity>
    • setLookup

      public EntityZone<E> setLookup​(java.util.Map<java.lang.Integer,​Entity> lookup)