From f9b396875add92f9cfc64ee74c82d3275e4d7dd6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 30 Apr 2011 18:21:22 +0200 Subject: Made StoneSet iterable git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@31 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneSet.java | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/jrummikub/model') diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index d949187..ba96625 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -1,19 +1,24 @@ package jrummikub.model; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; import java.util.List; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + import jrummikub.util.Pair; /** Class managing {@link Stone}s joined together to form sets */ -public class StoneSet { +public class StoneSet implements Iterable { private List stones; public StoneSet(Stone stone) { - + stones = Collections.singletonList(stone); } public StoneSet(List stones) { - + this.stones = new ArrayList(stones); } /** Test for rule conflict within the StoneSet */ @@ -60,4 +65,28 @@ public class StoneSet { return stones.get(i); } + @Override + public Iterator iterator() { + final Iterator it = stones.iterator(); + + return new Iterator(){ + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public Stone next() { + return it.next(); + } + + @Override + public void remove() { + // removing stones is impossible + + throw new NotImplementedException(); + }}; + } + } -- cgit v1.2.3