@Override public Object report(final org.nlogo.nvm.Context context) throws LogoException { Object obj = args[1].report(context); if (obj instanceof LogoList) { Object value = args[0].report(context); LogoList list = (LogoList) obj; for (Iterator<Object> it = list.iterator(); it.hasNext(); ) { if (Equality.equals(value, it.next())) { return Boolean.TRUE; } } return Boolean.FALSE; } else if (obj instanceof String) { return ((String) obj).indexOf(argEvalString(context, 0)) != -1 ? Boolean.TRUE : Boolean.FALSE; } else if (obj instanceof AgentSet) { Agent agent = argEvalAgent(context, 0); AgentSet agentset = (AgentSet) obj; if (agent instanceof Turtle) { if (agent.id == -1) { return Boolean.FALSE; } if (agentset.type() != Turtle.class) { return Boolean.FALSE; } if (agentset == world.turtles()) { return Boolean.TRUE; } if (world.isBreed(agentset)) { return agentset == ((Turtle) agent).getBreed() ? Boolean.TRUE : Boolean.FALSE; } } if (agent instanceof Link) { if (agent.id == -1) { return Boolean.FALSE; } if (agentset.type() != Link.class) { return Boolean.FALSE; } if (agentset == world.links()) { return Boolean.TRUE; } if (world.isBreed(agentset)) { return agentset == ((Link) agent).getBreed() ? Boolean.TRUE : Boolean.FALSE; } } else if (agent instanceof Patch) { if (agentset.type() != Patch.class) { return Boolean.FALSE; } if (agentset == world.patches()) { return Boolean.TRUE; } } return agentset.contains(agent) ? Boolean.TRUE : Boolean.FALSE; } else { throw new ArgumentTypeException( context, this, 1, Syntax.ListType() | Syntax.StringType() | Syntax.AgentsetType(), obj); } }
@Override public Object report(final org.nlogo.nvm.Context context) { LinkedHashMap<LogoHashObject, MutableInteger> counts = new LinkedHashMap<LogoHashObject, MutableInteger>(); LogoList list = argEvalList(context, 0); for (Iterator<Object> it = list.iterator(); it.hasNext(); ) { Object srcElt = it.next(); LogoHashObject logoElt = new LogoHashObject(srcElt); if (counts.containsKey(logoElt)) { MutableInteger i = counts.get(logoElt); i.value_$eq(i.value() + 1); } else { counts.put(logoElt, new MutableInteger(1)); } } Iterator<LogoHashObject> keys = counts.keySet().iterator(); int currMaxCount = 0; while (keys.hasNext()) { LogoHashObject currKey = keys.next(); int currVal = counts.get(currKey).value(); if (currVal > currMaxCount) { currMaxCount = currVal; } } keys = counts.keySet().iterator(); LogoListBuilder modes = new LogoListBuilder(); while (keys.hasNext()) { LogoHashObject currKey = keys.next(); int currVal = counts.get(currKey).value(); if (currVal == currMaxCount) { modes.add(currKey.sourceObject()); } } return modes.toLogoList(); }