From 0ad31dcca37df9891ed5d5b70f12a966fc821c6d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 3 Dec 2015 04:34:54 +0000 Subject: EiP - 07 --- ws2015/eip/blaetter/07/de/lmu/tcs/Zelle.java | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ws2015/eip/blaetter/07/de/lmu/tcs/Zelle.java (limited to 'ws2015/eip/blaetter/07/de/lmu/tcs/Zelle.java') diff --git a/ws2015/eip/blaetter/07/de/lmu/tcs/Zelle.java b/ws2015/eip/blaetter/07/de/lmu/tcs/Zelle.java new file mode 100644 index 0000000..a7c6ad6 --- /dev/null +++ b/ws2015/eip/blaetter/07/de/lmu/tcs/Zelle.java @@ -0,0 +1,47 @@ +package de.lmu.tcs; + +/** + * Model + * + * Immutable + * + * Created by jost on 24.11.15. + */ +public class Zelle { + + public final static int TOT=0; + public final static int LEBENDIG=1; + + private final Position position; + private final int zustand; + + public Zelle(Position position, int zustand) { + this.position = position; + this.zustand = zustand; + } + + public Zelle(Zelle old) { + this.position = old.position; + this.zustand = old.zustand; + } + + public Position getPosition() { + return position; + } + + public boolean istLebendig() { + return zustand>=LEBENDIG; + } + + public boolean istTot() { + return zustand==TOT; + } + + public Zelle nachkommen() { + return this.istTot() ? (new Zelle(this)) : (new Zelle(position, zustand + 1)); + } + + public int alter() { + return this.istTot() ? -1 : (this.zustand - 1); + } +} -- cgit v1.2.3