2011-04-30 13:44:17 +02:00
|
|
|
package jrummikub.model;
|
|
|
|
|
2011-04-30 18:21:22 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Iterator;
|
2011-04-30 17:20:14 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2011-04-30 18:21:22 +02:00
|
|
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|
|
|
|
2011-04-30 15:45:11 +02:00
|
|
|
import jrummikub.util.Pair;
|
|
|
|
|
2011-04-30 14:47:42 +02:00
|
|
|
/** Class managing {@link Stone}s joined together to form sets */
|
2011-04-30 18:21:22 +02:00
|
|
|
public class StoneSet implements Iterable<Stone> {
|
2011-04-30 15:45:11 +02:00
|
|
|
private List<Stone> stones;
|
2011-04-30 13:44:17 +02:00
|
|
|
|
2011-04-30 17:20:14 +02:00
|
|
|
public StoneSet(Stone stone) {
|
2011-04-30 18:21:22 +02:00
|
|
|
stones = Collections.singletonList(stone);
|
2011-04-30 17:20:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public StoneSet(List<Stone> stones) {
|
2011-04-30 18:21:22 +02:00
|
|
|
this.stones = new ArrayList<Stone>(stones);
|
2011-04-30 17:20:14 +02:00
|
|
|
}
|
|
|
|
|
2011-04-30 14:47:42 +02:00
|
|
|
/** Test for rule conflict within the StoneSet */
|
2011-04-30 13:44:17 +02:00
|
|
|
public boolean isValid() {
|
2011-04-30 17:20:14 +02:00
|
|
|
return false;
|
2011-04-30 13:44:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-30 14:47:42 +02:00
|
|
|
/**
|
|
|
|
* Splits the StoneSet at a specified {@link Position} and returns two new
|
|
|
|
* Stone Sets
|
|
|
|
*
|
|
|
|
* @param position
|
|
|
|
* Splitting {@link Position}
|
|
|
|
*/
|
2011-04-30 15:45:11 +02:00
|
|
|
public Pair<StoneSet, StoneSet> splitAt(int position) {
|
2011-04-30 17:20:14 +02:00
|
|
|
//Exception falls falscher index
|
|
|
|
if (position==0||position==stones.size()){
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
2011-04-30 13:44:17 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-30 14:47:42 +02:00
|
|
|
/**
|
|
|
|
* Joins StoneSet to another StoneSet and returns the resulting new StoneSet
|
|
|
|
*
|
|
|
|
* @param other
|
|
|
|
* StoneSet to be joined to active StoneSet
|
|
|
|
*/
|
2011-04-30 13:44:17 +02:00
|
|
|
public StoneSet join(StoneSet other) {
|
2011-04-30 17:20:14 +02:00
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public int size() {
|
|
|
|
return stones.size();
|
|
|
|
}
|
2011-04-30 13:44:17 +02:00
|
|
|
|
2011-04-30 17:20:14 +02:00
|
|
|
public Stone get(int i) {
|
|
|
|
return stones.get(i);
|
2011-04-30 13:44:17 +02:00
|
|
|
}
|
|
|
|
|
2011-04-30 18:21:22 +02:00
|
|
|
@Override
|
|
|
|
public Iterator<Stone> iterator() {
|
|
|
|
final Iterator<Stone> it = stones.iterator();
|
|
|
|
|
|
|
|
return new Iterator<Stone>(){
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2011-04-30 13:44:17 +02:00
|
|
|
}
|