return super.toString() + ":" + breedName + ",+" + offset;
}
@Override
public void perform(final Context context) throws LogoException {
AgentSet agentset = argEvalAgentSet(context, 0);
if (agentset.type() != Turtle.class) {
throw new ArgumentTypeException(
context, this, 0, Syntax.TurtlesetType(), agentset);
}
AgentSet breed = breedName == null ? world.links() : world.getLinkBreed(breedName);
mustNotBeDirected(breed, context);
checkForBreedCompatibility(breed, context);
if (breed == world.links()) {
breed.setDirected(false);
}
AgentSet edgeset = new org.nlogo.agent.ArrayAgentSet(Link.class, agentset.count(),
false, world);
Turtle src = (Turtle) context.agent;
// We have to shuffle here in order for who number assignment
// to be random! - ST 3/15/06
for (AgentSet.Iterator iter = agentset.shufflerator(context.job.random); iter.hasNext();) {
Turtle dest = (Turtle) iter.next();
if (world.linkManager.findLinkEitherWay(src, dest, breed, false) == null) {
if (src == dest) {
throw new EngineException
(context, this,
I18N.errorsJ().get("org.nlogo.prim.$common.turtleCantLinkToSelf"));
}
if (src.id != -1 && dest.id != -1) {
Link link;
if (src.id > dest.id) {
link = world.linkManager.createLink(dest, src, breed);
} else {
link = world.linkManager.createLink(src, dest, breed);
}
edgeset.add(link);
workspace.joinForeverButtons(link);
}
}
}
if (offset - context.ip > 2 && edgeset.count() > 0) {
context.runExclusiveJob(edgeset, next);
}
context.ip = offset;
}