From ac1cc19a88a9e01ee5c78357f20d77f9c35bcd6b Mon Sep 17 00:00:00 2001 From: peet Date: Sat, 15 Jun 2024 16:20:39 +0200 Subject: [PATCH] finished uebung09 --- bin/uebung09/chess/Board.class | Bin 3201 -> 3551 bytes bin/uebung09/iterator/SkipNullIterator.class | Bin 955 -> 1360 bytes src/uebung09/chess/Board.java | 16 ++++----- src/uebung09/iterator/SkipNullIterator.java | 34 ++++++++++++++----- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/bin/uebung09/chess/Board.class b/bin/uebung09/chess/Board.class index fe2a88c2555cd9fad422f0479cc0ef0bc7f81f2c..25ad31ee3af3bbf1076b87edaaada10b0d0413aa 100644 GIT binary patch delta 822 zcmZ{i*-sNu6vn^XWo9}MK^CFlGC*3j1qu<2fJihXNCZse!Qh&q9c!hQS~?ICu;PZI zh;qdR6?bq45>uiL#wQ+p^dIoi|3W-7)JGrYyJz{GbHAI+i1Sym{NvBpZvggUaZzrx zH;FjUP;f@=SAAhM67+S(W1&cJpB@Saw3vho4D6_kVU!wjDHE4*g+WlGQ7sZ+sNka( zS52C3kT6R4af6Id(8u6x`_JYE-fnN&ev6@0*Shscu&T}%ifb`7-W&6E_JpDxdN|yg zE{M3z$L(%u0+X3=fb*2Ss6@s%ri}C++26KyjUEq$egCHTPkW#67&9WC@B@OEJ>>(! zOv@t)FBtOGa7zy=xFaPUeg;amp^S;(P$3)Z8Iq8j9)1$lf$TB$Ce zZXxxY$VU-MPz*OVq5_++8=KKe`5`DcLY;16dQirf9b?SR_sh#J5AE_2U5+Z6s6{0j z;ln{x;{?@C!-I3!!95vMiCI|56HuSRa92)Z2_tQuB>Ww7*ii8WL5A-rZ1*sdd~WJXQ(v1pXX;zLCrT#b J13qB^&cF0!sptRz delta 526 zcmZ9GT}xC^6o#LzGw19%9zXIU8!g*rGdX@lMRgHbNWmZoL3b4d<2X?m%_vPIYSZ+g zW?Aaav@GqyA5anmML{=S_$T})(VC+d5}Uo&e%E@}v)6WWG3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&9Ug|1LAr^<$&5bTtG!_<+4xq}zfL4(d^ YXc*o2ZT9XOcI{5=4E7B5bxMD81sSl`p8x;= diff --git a/src/uebung09/chess/Board.java b/src/uebung09/chess/Board.java index b69232a..e50d7eb 100644 --- a/src/uebung09/chess/Board.java +++ b/src/uebung09/chess/Board.java @@ -3,6 +3,7 @@ package uebung09.chess; import java.util.Iterator; import uebung09.iterator.Array2dIterator; +import uebung09.iterator.SkipNullIterator; public class Board implements Iterable{ @@ -50,22 +51,21 @@ public class Board implements Iterable{ } public String toString() { - // StringBuilder s = new StringBuilder("["); + StringBuilder s = new StringBuilder("["); - // for(Piece p : this) { - // s.append(p.toString()); - // } + for(Piece p : this) { + s.append(p.toString()); + } - // s.append("]"); + s.append("]"); - // return s.toString(); - return ""; + return s.toString(); } @Override public Iterator iterator() { // TODO Auto-generated method stub - return new Array2dIterator<>(field); + return new SkipNullIterator<>(new Array2dIterator<>(field)); // throw new UnsupportedOperationException("Unimplemented method 'iterator'"); } } diff --git a/src/uebung09/iterator/SkipNullIterator.java b/src/uebung09/iterator/SkipNullIterator.java index 555ddef..ae2d656 100644 --- a/src/uebung09/iterator/SkipNullIterator.java +++ b/src/uebung09/iterator/SkipNullIterator.java @@ -1,26 +1,42 @@ package uebung09.iterator; import java.util.Iterator; -import java.util.List; +import java.util.NoSuchElementException; public class SkipNullIterator implements Iterator{ + private final Iterator iterator; + private T nextItem; + private boolean hasNext; - public SkipNullIterator(Iterator i){ + public SkipNullIterator(Iterator iterator) { + this.iterator = iterator; + advance(); + } + private void advance() { + hasNext = false; + nextItem = null; + while (iterator.hasNext()) { + nextItem = iterator.next(); + if (nextItem != null) { + hasNext = true; + break; + } + } } @Override public boolean hasNext() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'hasNext'"); + return hasNext; } @Override public T next() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'next'"); + if (!hasNext) { + throw new NoSuchElementException(); + } + T currentItem = nextItem; + advance(); + return currentItem; } - - - }