All pastes #286285 Raw Edit

Stuff

public text v1 · immutable
#286285 ·published 2006-12-20 15:21 UTC
rendered paste body
package atd;

import java.util.HashSet;

import model.Diagram;
import model.MImage;

public class ATDFactory {
	
	public static <N extends ATDNode, I extends MImage> ATDNode createNew(ATDNode.NodeType nodeType, Diagram<N, I> diagram){
		HashSet<Integer> id = new HashSet<Integer>();
		int i;
		switch(nodeType){
		case ELEMENTARYACTORROLE:
			for(N shape: diagram.getShapes()){
				if(shape instanceof ElementaryActorRole)
					id.add(shape.getId());
			}
			i=0;
			while(id.contains(i)){
				i++;
			}
			return new ElementaryActorRole(i);
		case COMPOSITEACTORROLE:
			for(N shape: diagram.getShapes()){
				if(shape instanceof CompositeActorRole)
					id.add(shape.getId());
			}
			i=0;
			while(id.contains(i)){
				i++;
			}
			return new CompositeActorRole(i);		
		case TRANSACTIONTYPE:
			for(N shape: diagram.getShapes()){
				if(shape instanceof TransactionType)
					id.add(shape.getId());
			}
			i=0;
			while(id.contains(i)){
				i++;
			}
			return new TransactionType(i);
		}
		return null;
	}
}