5 changed files with 0 additions and 198 deletions
@ -1,41 +0,0 @@ |
|||
package solution; |
|||
|
|||
import testat.SimpleActivity; |
|||
|
|||
public class SimpleActivityStack extends SimpleStack<SimpleActivity> { |
|||
|
|||
@Override |
|||
public int push(SimpleActivity activity) { |
|||
if (activity == null) { |
|||
return 0; |
|||
} |
|||
if (size() > 0) { |
|||
super.get(size() - 1).passivate(); |
|||
} |
|||
activity.activate(); |
|||
return super.push(activity); |
|||
} |
|||
|
|||
@Override |
|||
public SimpleActivity pop() { |
|||
SimpleActivity activity = super.pop(); |
|||
if (activity != null) { |
|||
activity.passivate(); |
|||
activity.destroy(); |
|||
if (size() > 0) { |
|||
super.get(size() - 1).activate(); |
|||
} |
|||
} |
|||
return activity; |
|||
} |
|||
|
|||
@Override |
|||
public SimpleActivity remove(int i) { |
|||
if (i == super.size() - 1) { |
|||
return this.pop(); |
|||
} |
|||
super.get(i).destroy(); |
|||
return super.remove(i); |
|||
} |
|||
|
|||
} |
@ -1,14 +0,0 @@ |
|||
package solution; |
|||
|
|||
import testat.ASimpleActivityStackTest; |
|||
import testat.ISimpleStack; |
|||
import testat.SimpleActivity; |
|||
|
|||
public class SimpleActivityStackTest extends ASimpleActivityStackTest { |
|||
|
|||
@Override |
|||
protected ISimpleStack<SimpleActivity> getInstance() { |
|||
return new SimpleActivityStack(); |
|||
} |
|||
|
|||
} |
@ -1,64 +0,0 @@ |
|||
package solution; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.List; |
|||
|
|||
import testat.IAction; |
|||
import testat.ISimpleStack; |
|||
|
|||
public class SimpleStack<T> implements ISimpleStack<T> { |
|||
|
|||
private List<T> list; |
|||
|
|||
public SimpleStack() { |
|||
super(); |
|||
list = new LinkedList<T>(); |
|||
} |
|||
|
|||
@Override |
|||
public int push(T t) { |
|||
if (t != null) { |
|||
if (list.contains(t)) { |
|||
list.remove(t); |
|||
} |
|||
list.add(t); |
|||
return list.size(); |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
@Override |
|||
public T pop() { |
|||
if (list.size() == 0) { |
|||
return null; |
|||
} |
|||
return list.remove(list.size() - 1); |
|||
} |
|||
|
|||
@Override |
|||
public T remove(int i) { |
|||
return list.remove(i); |
|||
} |
|||
|
|||
@Override |
|||
public int size() { |
|||
return list.size(); |
|||
} |
|||
|
|||
@Override |
|||
public boolean contains(Object o) { |
|||
return list.contains(o); |
|||
} |
|||
|
|||
@Override |
|||
public T get(int i) { |
|||
return list.get(i); |
|||
} |
|||
|
|||
@Override |
|||
public void forAll(IAction<T> action) { |
|||
if (action != null) { |
|||
list.forEach(t -> action.execute(t)); |
|||
} |
|||
} |
|||
} |
@ -1,13 +0,0 @@ |
|||
package solution; |
|||
|
|||
import testat.ASimpleStackTest; |
|||
import testat.ISimpleStack; |
|||
|
|||
public class SimpleStackTest extends ASimpleStackTest { |
|||
|
|||
@Override |
|||
protected ISimpleStack<String> getInstance() { |
|||
return new SimpleStack<>(); |
|||
} |
|||
|
|||
} |
@ -1,66 +0,0 @@ |
|||
package testat; |
|||
|
|||
/** |
|||
* |
|||
* @author cm |
|||
* not provided |
|||
* |
|||
* @param <T> |
|||
*/ |
|||
public interface ISimpleStack<T> { |
|||
|
|||
/** |
|||
* Nimmt ein Objekt auf, das nicht null ist und noch nicht im Stack enthalten |
|||
* ist. Rückgabe: Anzahl an Elemente im Stack nach der Aufnahme oder 0, falls t |
|||
* == null ist das Objekt bereits enthalten, wird es ganz oben auf den Stapel |
|||
* gelegt. Hinweis: Verwenden Sie entsprechende Operationen der Collection/des |
|||
* Array und nicht pop/push |
|||
* |
|||
* @param t |
|||
* @return |
|||
*/ |
|||
public int push(T t); |
|||
|
|||
/** |
|||
* Entfernt das oberste Objekt und gibt es zurück. Liefert null, falls der Stack |
|||
* leer ist |
|||
*/ |
|||
public T pop(); |
|||
|
|||
/** |
|||
* gibt einen Verweise auf das i-te Objekt zurück. Das Objekt bleibt im //
|
|||
* Stack. Falls i nicht existiert, führt dies zur IndexOutOfBoundsException. //
|
|||
* Das unterste Element hat Index 0, das oberste Index size()-1 |
|||
* |
|||
* @param i index |
|||
* @return |
|||
*/ |
|||
public T get(int i); |
|||
|
|||
/** |
|||
* Wie get(i), nur wird das Objekt aus dem Stack entfernt |
|||
* |
|||
* @param i |
|||
* @return |
|||
*/ |
|||
public T remove(int i); |
|||
|
|||
/** |
|||
* Anzahl an Objekte im Stack |
|||
* |
|||
*/ |
|||
public int size(); |
|||
|
|||
/** |
|||
* true, falls das Objekt im Stack enthalten ist |
|||
* |
|||
*/ |
|||
public boolean contains(Object o); |
|||
|
|||
/** |
|||
* Wendet action.execute auf alle Objekte im Stack an |
|||
* |
|||
* @param action |
|||
*/ |
|||
public void forAll(IAction<T> action); |
|||
} |
Loading…
Reference in new issue