001package squidpony.squidgrid.zone; 002 003import squidpony.squidgrid.zone.Zone.Skeleton; 004import squidpony.squidmath.Coord; 005 006import java.util.ArrayList; 007import java.util.Collection; 008import java.util.Collections; 009import java.util.List; 010 011/** 012 * A zone defined by a {@link List}. 013 * 014 * @author smelC 015 */ 016public class ListZone extends Skeleton { 017 018 protected final List<Coord> coords; 019 020 private static final long serialVersionUID = 1166468942544595692L; 021 022 public ListZone(List<Coord> coords) { 023 this.coords = coords; 024 } 025 026 public ListZone(Coord[] coords) { 027 this.coords = new ArrayList<Coord>(coords.length); 028 Collections.addAll(this.coords, coords); 029 } 030 031 public ListZone(Collection<Coord> coordCollection) 032 { 033 this.coords = new ArrayList<>(coordCollection); 034 } 035 @Override 036 public boolean isEmpty() { 037 return coords.isEmpty(); 038 } 039 040 @Override 041 public int size() { 042 return coords.size(); 043 } 044 045 @Override 046 public boolean contains(Coord c) { 047 return coords.contains(c); 048 } 049 050 @Override 051 public boolean contains(int x, int y) { 052 return coords.contains(Coord.get(x, y)); 053 } 054 055 @Override 056 public List<Coord> getAll() { 057 return coords; 058 } 059 060 /** 061 * @return The list that backs up {@code this}. Use at your own risks. 062 */ 063 public List<Coord> getState() { 064 return coords; 065 } 066 067 @Override 068 public String toString() { 069 return coords.toString(); 070 } 071}