Compare commits
9 Commits
93fb940a8c
...
main
Author | SHA1 | Date | |
---|---|---|---|
5f15f03d92 | |||
9908656813 | |||
b439030fee | |||
7fea13b9b3 | |||
639da57def | |||
0c95c28bc4 | |||
ac1cc19a88 | |||
62da4a9ea5 | |||
dad5a33695 |
BIN
bin/test/uebung/uebung09/collection/SetTest.class
Normal file
BIN
bin/test/uebung/uebung09/collection/SetTest.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/uebung09/collection/BigSet$1.class
Normal file
BIN
bin/uebung09/collection/BigSet$1.class
Normal file
Binary file not shown.
BIN
bin/uebung09/collection/BigSet.class
Normal file
BIN
bin/uebung09/collection/BigSet.class
Normal file
Binary file not shown.
BIN
bin/uebung09/collection/EmptySet$1.class
Normal file
BIN
bin/uebung09/collection/EmptySet$1.class
Normal file
Binary file not shown.
BIN
bin/uebung09/collection/EmptySet.class
Normal file
BIN
bin/uebung09/collection/EmptySet.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/uebung09/collection/SingeltonSet$1.class
Normal file
BIN
bin/uebung09/collection/SingeltonSet$1.class
Normal file
Binary file not shown.
BIN
bin/uebung09/collection/SingeltonSet.class
Normal file
BIN
bin/uebung09/collection/SingeltonSet.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/uebung10/logo/BlackForest.class
Normal file
BIN
bin/uebung10/logo/BlackForest.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/uebung10/logo/Go.class
Normal file
BIN
bin/uebung10/logo/Go.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelFrame$1.class
Normal file
BIN
bin/uebung10/logo/HanselGretelFrame$1.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelTest.class
Normal file
BIN
bin/uebung10/logo/HanselGretelTest.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$1.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$1.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$2.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$2.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$3.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$3.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor$State.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor$State.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/HanselGretelVisitor.class
Normal file
BIN
bin/uebung10/logo/HanselGretelVisitor.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/PenDown.class
Normal file
BIN
bin/uebung10/logo/PenDown.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/PenUp.class
Normal file
BIN
bin/uebung10/logo/PenUp.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/Sequence.class
Normal file
BIN
bin/uebung10/logo/Sequence.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/Stmt.class
Normal file
BIN
bin/uebung10/logo/Stmt.class
Normal file
Binary file not shown.
BIN
bin/uebung10/logo/Turn.class
Normal file
BIN
bin/uebung10/logo/Turn.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/uebung10/logo/Visitor.class
Normal file
BIN
bin/uebung10/logo/Visitor.class
Normal file
Binary file not shown.
76
src/test/uebung/uebung09/collection/SetTest.java
Normal file
76
src/test/uebung/uebung09/collection/SetTest.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package test.uebung.uebung09.collection;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import uebung09.collection.Set;
|
||||||
|
import uebung09.collection.SetFactory;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class SetTest {
|
||||||
|
|
||||||
|
static String a = "test";
|
||||||
|
static String b = "test2";
|
||||||
|
static String c = "test3";
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void EmptySetTest(){
|
||||||
|
|
||||||
|
Set<String> test = SetFactory.create();
|
||||||
|
|
||||||
|
Iterator<String> i = test.iterator();
|
||||||
|
|
||||||
|
assertFalse(i.hasNext());
|
||||||
|
assertThrows(NoSuchElementException.class, i::next);
|
||||||
|
assertFalse(test.contains(a));
|
||||||
|
assertEquals(0,test.size());
|
||||||
|
assertTrue(test.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void SingeltonSetTest(){
|
||||||
|
|
||||||
|
Set<String> test = SetFactory.create(a);
|
||||||
|
|
||||||
|
Iterator<String> i = test.iterator();
|
||||||
|
|
||||||
|
assertTrue(i.hasNext());
|
||||||
|
assertTrue(a == i.next());
|
||||||
|
assertFalse(i.hasNext());
|
||||||
|
assertThrows(NoSuchElementException.class, i::next);
|
||||||
|
assertTrue(test.contains(a));
|
||||||
|
assertEquals(1,test.size());
|
||||||
|
assertFalse(test.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void BigSetTest() {
|
||||||
|
|
||||||
|
Set<String> test = SetFactory.create(a,b,c);
|
||||||
|
|
||||||
|
Iterator<String> i = test.iterator();
|
||||||
|
|
||||||
|
assertTrue(i.hasNext());
|
||||||
|
assertTrue(a == i.next());
|
||||||
|
assertTrue(i.hasNext());
|
||||||
|
assertTrue(a == i.next());
|
||||||
|
assertTrue(i.hasNext());
|
||||||
|
assertTrue(a == i.next());
|
||||||
|
assertFalse(i.hasNext());
|
||||||
|
assertThrows(NoSuchElementException.class, i::next);
|
||||||
|
assertTrue(test.contains(a));
|
||||||
|
assertEquals(1,test.size());
|
||||||
|
assertFalse(test.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
@@ -1,46 +0,0 @@
|
|||||||
package uebung07.quantities.plain;
|
|
||||||
|
|
||||||
import static uebung07.quantities.plain.LengthUnit.METER;
|
|
||||||
import static uebung07.quantities.plain.TimeUnit.SECOND;
|
|
||||||
import static uebung07.quantities.plain.VelocityUnit.METER_PER_SECOND;
|
|
||||||
|
|
||||||
public class Length extends Quantity {
|
|
||||||
private final LengthUnit unit;
|
|
||||||
|
|
||||||
public Length(double value, LengthUnit unit) {
|
|
||||||
super(value, unit);
|
|
||||||
this.unit = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Length plus(Length other) {
|
|
||||||
return new Length(value + other.getBaseValue() / unit.baseFactor, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Length minus(Length other) {
|
|
||||||
return new Length(value - other.getBaseValue() / unit.baseFactor, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Length mult(double f) {
|
|
||||||
return new Length(value * f, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Length div(double f) {
|
|
||||||
return new Length(value / f, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Length to(LengthUnit unit) {
|
|
||||||
return new Length(getBaseValue() / unit.baseFactor, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double div(Length other) {
|
|
||||||
return getBaseValue() / other.getBaseValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Velocity div(Time t) {
|
|
||||||
return new Velocity(this.value(METER) / t.value(SECOND), METER_PER_SECOND);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Time div(Velocity v) {
|
|
||||||
return new Time(this.value(METER) / v.value(METER_PER_SECOND), SECOND);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,14 +0,0 @@
|
|||||||
package uebung07.quantities.plain;
|
|
||||||
|
|
||||||
public class LengthUnit extends Unit {
|
|
||||||
public LengthUnit(String name, double baseFactor) {
|
|
||||||
super(name, baseFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final LengthUnit METER = new LengthUnit("m", 1);
|
|
||||||
public static final LengthUnit MILLIMETER = new LengthUnit("mm", 0.001);
|
|
||||||
public static final LengthUnit KILOMETER = new LengthUnit("km", 1000);
|
|
||||||
public static final LengthUnit MILE = new LengthUnit("mi", 1609.344);
|
|
||||||
public static final LengthUnit LIGHTYEAR = new LengthUnit("ly", 9460730472580800.0);
|
|
||||||
public static final LengthUnit PARSEC = new LengthUnit("pc", 3.0856776e16);
|
|
||||||
}
|
|
@@ -1,60 +0,0 @@
|
|||||||
package uebung07.quantities.plain;
|
|
||||||
|
|
||||||
import static uebung07.quantities.plain.LengthUnit.KILOMETER;
|
|
||||||
import static uebung07.quantities.plain.LengthUnit.MILE;
|
|
||||||
import static uebung07.quantities.plain.LengthUnit.MILLIMETER;
|
|
||||||
import static uebung07.quantities.plain.LengthUnit.PARSEC;
|
|
||||||
import static uebung07.quantities.plain.TimeUnit.HOUR;
|
|
||||||
import static uebung07.quantities.plain.TimeUnit.MINUTE;
|
|
||||||
import static uebung07.quantities.plain.TimeUnit.SECOND;
|
|
||||||
import static uebung07.quantities.plain.VelocityUnit.KMH;
|
|
||||||
import static uebung07.quantities.plain.VelocityUnit.METER_PER_SECOND;
|
|
||||||
import static uebung07.quantities.plain.VelocityUnit.MPH;
|
|
||||||
|
|
||||||
public class PlainQuantitiesDemo {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
final Length l1 = new Length(1, KILOMETER);
|
|
||||||
final Length l2 = new Length(1200, MILLIMETER);
|
|
||||||
final Length l3 = new Length(1, MILE);
|
|
||||||
|
|
||||||
System.out.println(l1);
|
|
||||||
System.out.println(l2);
|
|
||||||
System.out.println(l1 + " + " + l2 + " = " + l1.plus(l2));
|
|
||||||
System.out.println(l1 + " + " + l2 + " (in mm) = " + l1.plus(l2).to(MILLIMETER));
|
|
||||||
|
|
||||||
System.out.println(l3 + " / " + l1 + " = " + l3.div(l1));
|
|
||||||
|
|
||||||
final Time t1 = new Time(100, SECOND);
|
|
||||||
final Time t2 = new Time(5, HOUR);
|
|
||||||
|
|
||||||
System.out.println(t1);
|
|
||||||
System.out.println(t2);
|
|
||||||
System.out.println(t1.plus(t2));
|
|
||||||
System.out.println(t1.plus(t2).to(MINUTE));
|
|
||||||
|
|
||||||
final Velocity v1 = new Velocity(12, KMH);
|
|
||||||
final Velocity v2 = new Velocity(100, METER_PER_SECOND);
|
|
||||||
|
|
||||||
System.out.println(v1);
|
|
||||||
System.out.println(v2);
|
|
||||||
System.out.println(v2.to(KMH));
|
|
||||||
System.out.println(v1.plus(v2));
|
|
||||||
|
|
||||||
final Length l4 = new Length(300, KILOMETER).to(PARSEC);
|
|
||||||
final Time t3 = new Time(2, HOUR);
|
|
||||||
final Velocity v3 = l4.div(t3);
|
|
||||||
System.out.println(l4 + " / " + l3 + " = " + v3);
|
|
||||||
|
|
||||||
System.out.println(v1 + " * " + t1 + " = " + v1.mult(t1).to(KILOMETER));
|
|
||||||
|
|
||||||
final Length l5 = v3.mult(t1.to(HOUR));
|
|
||||||
System.out.println(v3 + " * " + t1 + " = " + l5);
|
|
||||||
|
|
||||||
final Time t5 = l4.div(v2);
|
|
||||||
System.out.println(l4 + " / " + v2 + " = " + t5.to(MINUTE));
|
|
||||||
|
|
||||||
Velocity v5 = new Velocity(55, MPH);
|
|
||||||
System.out.println(v5 + " = " + v5.format("%4.1f %s", KMH));
|
|
||||||
System.out.println((v5.mult(new Time(30, MINUTE)).to(MILE)));
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
package uebung07.quantities.plain;
|
|
||||||
|
|
||||||
public abstract class Quantity {
|
|
||||||
public final double value;
|
|
||||||
public final Unit unit;
|
|
||||||
|
|
||||||
protected Quantity(double value, Unit unit) {
|
|
||||||
this.value = value;
|
|
||||||
this.unit = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getBaseValue() {
|
|
||||||
return value * unit.baseFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double value(Unit unit) {
|
|
||||||
return getBaseValue() / unit.baseFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return value + " " + unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String format(String fmt, Unit unit) {
|
|
||||||
return String.format(fmt, value(unit), unit);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
package uebung07.quantities.plain;
|
|
||||||
|
|
||||||
import static uebung07.quantities.plain.LengthUnit.METER;
|
|
||||||
|
|
||||||
public class Time extends Quantity{
|
|
||||||
private final TimeUnit unit;
|
|
||||||
|
|
||||||
public Time(double value, TimeUnit unit) {
|
|
||||||
super(value, unit);
|
|
||||||
this.unit = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Time plus(Time other) {
|
|
||||||
return new Time( value + other.getBaseValue() / unit.baseFactor, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Time minus(Time other) {
|
|
||||||
return new Time( value - other.getBaseValue() / unit.baseFactor, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Time mult(double f) {
|
|
||||||
return new Time( value * f, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Time div(double f) {
|
|
||||||
return new Time( value / f, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Time to(TimeUnit unit) {
|
|
||||||
return new Time(getBaseValue() / unit.baseFactor, unit)
|
|
||||||
}
|
|
||||||
|
|
||||||
public double div(Time other) {
|
|
||||||
return getBaseValue() / other.getBaseValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Length mult(Velocity v) {
|
|
||||||
return new Length(this.value(METER), METER);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,16 +0,0 @@
|
|||||||
package uebung07.quantities.plain;
|
|
||||||
|
|
||||||
public abstract class Unit {
|
|
||||||
public final String name;
|
|
||||||
public final double baseFactor;
|
|
||||||
|
|
||||||
public Unit(String name, double baseFactor) {
|
|
||||||
this.name = name;
|
|
||||||
this.baseFactor = baseFactor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,15 +1,13 @@
|
|||||||
package uebung09.chess;
|
package uebung09.chess;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import uebung09.iterator.Array2dIterator;
|
import uebung09.iterator.Array2dIterator;
|
||||||
|
import uebung09.iterator.SkipNullIterator;
|
||||||
|
|
||||||
|
|
||||||
public class Board implements Iterable<Piece>{
|
public class Board implements Iterable<Piece>{
|
||||||
private final Piece[][] field = new Piece[8][8];
|
private final Piece[][] field = new Piece[8][8];
|
||||||
private final List<Piece> pieces = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
void add(Piece piece) {
|
void add(Piece piece) {
|
||||||
@@ -19,7 +17,6 @@ public class Board implements Iterable<Piece>{
|
|||||||
if (existing != null)
|
if (existing != null)
|
||||||
throw new IllegalArgumentException("already occupied by " + existing);
|
throw new IllegalArgumentException("already occupied by " + existing);
|
||||||
field[piece.getRow() - 1][piece.getCol() - 1] = piece;
|
field[piece.getRow() - 1][piece.getCol() - 1] = piece;
|
||||||
pieces.add(piece);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printBoard() {
|
public void printBoard() {
|
||||||
@@ -42,9 +39,9 @@ public class Board implements Iterable<Piece>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void check() {
|
public void check() {
|
||||||
for (Piece p1 : pieces) {
|
for (Piece p1 : this) {
|
||||||
System.out.println(p1.toString());
|
System.out.println(p1.toString());
|
||||||
for (Piece p2 : pieces)
|
for (Piece p2 : this)
|
||||||
if (p1 != p2)
|
if (p1 != p2)
|
||||||
if (p1.canCapture(p2))
|
if (p1.canCapture(p2))
|
||||||
System.out.println(" can capture " + p2.toString());
|
System.out.println(" can capture " + p2.toString());
|
||||||
@@ -54,13 +51,21 @@ public class Board implements Iterable<Piece>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return pieces.toString();
|
StringBuilder s = new StringBuilder("[");
|
||||||
|
|
||||||
|
for(Piece p : this) {
|
||||||
|
s.append(p.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
s.append("]");
|
||||||
|
|
||||||
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Piece> iterator() {
|
public Iterator<Piece> iterator() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return new Array2dIterator<>(null);
|
return new SkipNullIterator<>(new Array2dIterator<>(field));
|
||||||
//throw new UnsupportedOperationException("Unimplemented method 'iterator'");
|
// throw new UnsupportedOperationException("Unimplemented method 'iterator'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
94
src/uebung09/collection/BigSet.java
Normal file
94
src/uebung09/collection/BigSet.java
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package uebung09.collection;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
class BigSet<T> implements Set<T>{
|
||||||
|
|
||||||
|
private T item;
|
||||||
|
private Set<T> rest;
|
||||||
|
|
||||||
|
public BigSet(T item, Set<T> rest){
|
||||||
|
//TODO
|
||||||
|
this.item = item;
|
||||||
|
this.rest = rest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new Iterator<T>() {
|
||||||
|
|
||||||
|
private boolean returned = false;
|
||||||
|
|
||||||
|
private Iterator<T> restI = rest.iterator();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return restI.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
if (!returned) {
|
||||||
|
returned = true;
|
||||||
|
return item;
|
||||||
|
} else {
|
||||||
|
return restI.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
int count = 1;
|
||||||
|
count += rest.size();
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Object el) {
|
||||||
|
if(el == item) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return rest.contains(el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> union(Set<T> other) {
|
||||||
|
if (other == EmptySet.getInstance()) {
|
||||||
|
return this;
|
||||||
|
} else if (other instanceof SingeltonSet<T> && !contains(other.iterator().next())) {
|
||||||
|
return new BigSet<T>(other.iterator().next(), this);
|
||||||
|
} else {
|
||||||
|
return new BigSet<T>(item, rest.union(other));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> add(T element) {
|
||||||
|
if (contains(element)) {
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
return new BigSet<T>(element, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> intersection(Set<T> other) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'intersection'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean subsetOf(Set<?> other) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'subsetOf'");
|
||||||
|
}
|
||||||
|
}
|
71
src/uebung09/collection/EmptySet.java
Normal file
71
src/uebung09/collection/EmptySet.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package uebung09.collection;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
class EmptySet<T> implements Set<T> {
|
||||||
|
|
||||||
|
private static EmptySet<?> INSTANCE;
|
||||||
|
|
||||||
|
private EmptySet() {}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> EmptySet<T> getInstance() {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
INSTANCE = new EmptySet<>();
|
||||||
|
}
|
||||||
|
return (EmptySet<T>) INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new Iterator<T>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Object el) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> union(Set<T> other) {
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> add(T element) {
|
||||||
|
return new SingeltonSet<T>(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> intersection(Set<T> other) {
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean subsetOf(Set<?> other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -38,10 +38,10 @@ public interface Set<E> extends Iterable<E> {
|
|||||||
/**
|
/**
|
||||||
* returns the set resulting from adding the specified element to this set.
|
* returns the set resulting from adding the specified element to this set.
|
||||||
*
|
*
|
||||||
* @param element an element (must not be null)
|
* @param elem an element (must not be null)
|
||||||
* @return the set resulting from adding the specified element to this set.
|
* @return the set resulting from adding the specified element to this set.
|
||||||
*/
|
*/
|
||||||
Set<E> add(E element);
|
Set<E> add(E elem);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the intersection of this set and the specified set.
|
* Returns the intersection of this set and the specified set.
|
||||||
|
@@ -10,9 +10,8 @@ public class SetFactory {
|
|||||||
* @param <T> the element type of the returned set.
|
* @param <T> the element type of the returned set.
|
||||||
* @return the empty set.
|
* @return the empty set.
|
||||||
*/
|
*/
|
||||||
static <T> Set<T> create() {
|
public static <T> Set<T> create() {
|
||||||
// TODO implement
|
return EmptySet.getInstance();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,9 +21,8 @@ public class SetFactory {
|
|||||||
* @param <T> the element type of the returned set.
|
* @param <T> the element type of the returned set.
|
||||||
* @return the singleton set containing the specified element.
|
* @return the singleton set containing the specified element.
|
||||||
*/
|
*/
|
||||||
static <T> Set<T> create(T element) {
|
public static <T> Set<T> create(T element) {
|
||||||
// TODO implement
|
return new SingeltonSet<T>(element);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,8 +32,14 @@ public class SetFactory {
|
|||||||
* @param <T> the element type of the returned set.
|
* @param <T> the element type of the returned set.
|
||||||
* @return a set containing the specified elements.
|
* @return a set containing the specified elements.
|
||||||
*/
|
*/
|
||||||
static <T> Set<T> create(T... elems) {
|
public static <T> Set<T> create(T... elems) {
|
||||||
// TODO implement
|
// BigSet<T> rtn = new BigSet<T>(elems[1], new SingeltonSet<>(elems[1]));
|
||||||
return null;
|
Set<T> set = EmptySet.getInstance();
|
||||||
|
|
||||||
|
for(T elem : elems) {
|
||||||
|
set = set.add(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return set;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
77
src/uebung09/collection/SingeltonSet.java
Normal file
77
src/uebung09/collection/SingeltonSet.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package uebung09.collection;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
class SingeltonSet<T> implements Set<T> {
|
||||||
|
|
||||||
|
private T item;
|
||||||
|
|
||||||
|
public SingeltonSet(T item) {
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new Iterator<T>() {
|
||||||
|
|
||||||
|
boolean returned = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return !returned;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
if (!returned) {
|
||||||
|
returned = true;
|
||||||
|
return item;
|
||||||
|
} else {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(Object el) {
|
||||||
|
return el == item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> union(Set<T> other) {
|
||||||
|
//TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> add(T element) {
|
||||||
|
if (element == item) {
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
return new BigSet<T>(item, new SingeltonSet<T>(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<T> intersection(Set<T> other) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'intersection'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean subsetOf(Set<?> other) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,73 +1,49 @@
|
|||||||
package uebung09.iterator;
|
package uebung09.iterator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
public class Array2dIterator<T> implements Iterator<T>{
|
public class Array2dIterator<T> implements Iterator<T>{
|
||||||
|
|
||||||
private T[][] array;
|
private T[][] array;
|
||||||
private ArrayList<T> list;
|
private int row = 0;
|
||||||
private int index = 0;
|
private int col = 0;
|
||||||
|
|
||||||
public Array2dIterator(T[][] array) {
|
public Array2dIterator(T[][] array) {
|
||||||
this.array = array;
|
this.array = array;
|
||||||
list = flatten();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if the iteration has more elements.
|
||||||
|
* (In other words, returns {@code true} if {@link #next} would
|
||||||
|
* return an element rather than throwing an exception.)
|
||||||
|
*
|
||||||
|
* @return {@code true} if the iteration has more elements
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
// for (int i = 0; i < array.length; i++) {
|
|
||||||
// for (int j = 0; j < array[i].length; j++) {
|
|
||||||
// if (array[i][j+1] != null) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// if (array[i+1][j] != null) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
|
while(row < array.length && (array[row] == null || col >= array[row].length)) {
|
||||||
if (list.get(index)) {
|
row++;
|
||||||
return true;
|
col = 0;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return row < array.length;
|
||||||
|
|
||||||
// return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next element in the iteration.
|
||||||
|
*
|
||||||
|
* @return the next element in the iteration
|
||||||
|
* @throws NoSuchElementException if the iteration has no more elements
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
// for (int i = 0; i < array.length; i++) {
|
if (!hasNext()) {
|
||||||
// for (int j = 0; j < array[i].length; j++) {
|
throw new NoSuchElementException();
|
||||||
// if (array[i][j+1] != null) {
|
|
||||||
// return array[i][j+1];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// if (array[i+1][0] != null) {
|
|
||||||
// return array[i+1][0];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
|
|
||||||
|
|
||||||
return list.get(index++);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<T> flatten(){
|
|
||||||
ArrayList<T> list = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < array.length; i++) {
|
|
||||||
for (int j = 0; j < array[i].length; j++) {
|
|
||||||
list.add(array[i][j]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return array[row][col++];
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,26 +1,42 @@
|
|||||||
package uebung09.iterator;
|
package uebung09.iterator;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
public class SkipNullIterator<T> implements Iterator<T>{
|
public class SkipNullIterator<T> implements Iterator<T>{
|
||||||
|
private final Iterator<T> iterator;
|
||||||
|
private T nextItem;
|
||||||
|
private boolean hasNext;
|
||||||
|
|
||||||
public SkipNullIterator(Iterator i){
|
public SkipNullIterator(Iterator<T> 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
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
// TODO Auto-generated method stub
|
return hasNext;
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'hasNext'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T next() {
|
public T next() {
|
||||||
// TODO Auto-generated method stub
|
if (!hasNext) {
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'next'");
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
T currentItem = nextItem;
|
||||||
|
advance();
|
||||||
|
return currentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
src/uebung10/logo/BlackForest.java
Normal file
11
src/uebung10/logo/BlackForest.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class BlackForest implements DarkForest{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void breadCrumb(double x, double y) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'breadCrumb'");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package logo;
|
package uebung10.logo;
|
||||||
|
|
||||||
public interface DarkForest {
|
public interface DarkForest {
|
||||||
void breadCrumb(double x, double y);
|
void breadCrumb(double x, double y);
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package logo;
|
package uebung10.logo;
|
||||||
|
|
||||||
public class Demo {
|
public class Demo {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
18
src/uebung10/logo/Go.java
Normal file
18
src/uebung10/logo/Go.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class Go implements Stmt{
|
||||||
|
|
||||||
|
public final double dist;
|
||||||
|
|
||||||
|
public Go(double dist) {
|
||||||
|
if (dist < 0) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
this.dist = dist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package logo;
|
package uebung10.logo;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
30
src/uebung10/logo/HanselGretelTest.java
Normal file
30
src/uebung10/logo/HanselGretelTest.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
public class HanselGretelTest {
|
||||||
|
|
||||||
|
public static final double EPS = 1e-10;
|
||||||
|
public static final Stmt PROG = new Sequence(new PenDown(), new Go(50),
|
||||||
|
new Turn(120), new Go(50),
|
||||||
|
new Turn(120), new Go(50));
|
||||||
|
|
||||||
|
private Turtle turtle;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
turtle = new Turtle(2, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void TestTriangle() {
|
||||||
|
final Visitor<Void> visitor = new HanselGretelVisitor(10, turtle, new BlackForest()); //final ist egal
|
||||||
|
PROG.accept(visitor);
|
||||||
|
assertEquals(2, turtle.getX(), EPS);
|
||||||
|
assertEquals(1, turtle.getY(), EPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
131
src/uebung10/logo/HanselGretelVisitor.java
Normal file
131
src/uebung10/logo/HanselGretelVisitor.java
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class HanselGretelVisitor implements Visitor<Void> {
|
||||||
|
|
||||||
|
private double gap;
|
||||||
|
private double s;
|
||||||
|
private Turtle turtle;
|
||||||
|
private DarkForest forest;
|
||||||
|
private State state;
|
||||||
|
|
||||||
|
public HanselGretelVisitor(double s, Turtle turtle, DarkForest forest) {
|
||||||
|
this.s = s;
|
||||||
|
this.turtle = turtle;
|
||||||
|
this.forest = forest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(PenUp penUp) {
|
||||||
|
up();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(PenDown penDown) {
|
||||||
|
down();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(Turn turn) {
|
||||||
|
turtle.turn(turn.angle);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(Sequence sequence) {
|
||||||
|
for(Stmt elem :sequence.seq) {
|
||||||
|
elem.accept(this);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void visit(Go go) {
|
||||||
|
go(go.dist);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void breadCrumb() {
|
||||||
|
forest.breadCrumb(turtle.getX(), turtle.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void layTrail(double d) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'layTrail'");
|
||||||
|
}
|
||||||
|
|
||||||
|
private abstract class State {
|
||||||
|
abstract void go(double dist);
|
||||||
|
abstract void up();
|
||||||
|
abstract void down();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final State longUpState = new State(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void go(double d) {turtle.go(d);}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void down(){
|
||||||
|
breadCrumb();
|
||||||
|
state = downState;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void up() {}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
private final State downState = new State(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void go(double d){
|
||||||
|
layTrail(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void up(){state = shortUpState;}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void down() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final State shortUpState = new State() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void go(double dist) {
|
||||||
|
turtle.go(dist);
|
||||||
|
gap = gap + dist;
|
||||||
|
|
||||||
|
if (gap < s) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
gap = 0;
|
||||||
|
state = longUpState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void up() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void down() {
|
||||||
|
state = downState;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private void go(double d) {
|
||||||
|
state.go(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void down() {
|
||||||
|
state.down();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void up() {
|
||||||
|
state.up();
|
||||||
|
}
|
||||||
|
}
|
9
src/uebung10/logo/PenDown.java
Normal file
9
src/uebung10/logo/PenDown.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class PenDown implements Stmt{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
9
src/uebung10/logo/PenUp.java
Normal file
9
src/uebung10/logo/PenUp.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class PenUp implements Stmt {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
15
src/uebung10/logo/Sequence.java
Normal file
15
src/uebung10/logo/Sequence.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class Sequence implements Stmt {
|
||||||
|
|
||||||
|
public final Stmt[] seq;
|
||||||
|
|
||||||
|
public Sequence(Stmt... seq) {
|
||||||
|
this.seq = seq.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
7
src/uebung10/logo/Stmt.java
Normal file
7
src/uebung10/logo/Stmt.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public interface Stmt {
|
||||||
|
|
||||||
|
public <T> T accept(Visitor<T> visitor);
|
||||||
|
|
||||||
|
}
|
15
src/uebung10/logo/Turn.java
Normal file
15
src/uebung10/logo/Turn.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public class Turn implements Stmt{
|
||||||
|
|
||||||
|
public final double angle;
|
||||||
|
|
||||||
|
public Turn(double angle) {
|
||||||
|
this.angle = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T accept(Visitor<T> visitor) {
|
||||||
|
return visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package logo;
|
package uebung10.logo;
|
||||||
|
|
||||||
public class Turtle {
|
public class Turtle {
|
||||||
private double x;
|
private double x;
|
||||||
|
11
src/uebung10/logo/Visitor.java
Normal file
11
src/uebung10/logo/Visitor.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package uebung10.logo;
|
||||||
|
|
||||||
|
public interface Visitor<T> {
|
||||||
|
|
||||||
|
T visit(PenUp penUp);
|
||||||
|
T visit(PenDown penDown);
|
||||||
|
T visit(Turn turn);
|
||||||
|
T visit(Sequence sequence);
|
||||||
|
T visit(Go go);
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user