Package org.nlogo.api

Examples of org.nlogo.api.LogoList


  public Object report_1(final Context context, Object obj)
      throws LogoException {
    if (obj instanceof AgentSet) {
      return ((AgentSet) obj).toLogoList();
    } else if (obj instanceof LogoList) {
      LogoList input = (LogoList) obj;
      ArrayList<Double> numbers = new ArrayList<Double>();
      ArrayList<String> strings = new ArrayList<String>();
      ArrayList<Agent> agents = new ArrayList<Agent>();
      for (Iterator<Object> it = input.iterator(); it.hasNext();) {
        Object elt = it.next();
        if (elt instanceof Double) {
          numbers.add((Double) elt);
        } else if (elt instanceof String) {
          strings.add((String) elt);
View Full Code Here


  @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;
View Full Code Here

    extends Reporter {
  @Override
  public Object report(final Context context) throws LogoException {
    Object obj = args[0].report(context);
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      int size = list.size();
      if (size == 0) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.emptyListInput", displayName()));
      }
      return list.get(context.job.random.nextInt(size));
    } else if (obj instanceof AgentSet) {
      AgentSet agents = (AgentSet) obj;
      int count = agents.count();
      if (count == 0) {
        return org.nlogo.api.Nobody$.MODULE$;
View Full Code Here

    return list.get(context.job.random.nextInt(size));
  }

  public Object report_3(Context context, Object obj) throws LogoException {
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      int size = list.size();
      if (size == 0) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.emptyListInput", displayName()));
      }
      return list.get(context.job.random.nextInt(size));
    } else if (obj instanceof AgentSet) {
      AgentSet agents = (AgentSet) obj;
      int count = agents.count();
      if (count == 0) {
        return org.nlogo.api.Nobody$.MODULE$;
View Full Code Here

    return Syntax.reporterSyntax(right, ret);
  }

  @Override
  public Object report(Context context) throws LogoException {
    LogoList list = argEvalList(context, 0);
    LogoListBuilder result = new LogoListBuilder();
    HashSet<Object> seenHash = new HashSet<Object>();
    for (Iterator<Object> it = list.iterator(); it.hasNext();) {
      Object srcElt = it.next();
      LogoHashObject logoElt = new LogoHashObject(srcElt);
      if (!seenHash.contains(logoElt)) {
        seenHash.add(logoElt);
        result.add(srcElt);
View Full Code Here

  }

  public void choicesWrapper(String choicesString) {
    try {
      Object oldValue = value();
      LogoList newChoices = (LogoList) compiler.readFromString
          ("[ " + choicesString + " ]");

      constraint.acceptedValues(newChoices);

      int newIndex = constraint.indexForValue(oldValue);
View Full Code Here

  }

  public Object report_1(final org.nlogo.nvm.Context context, Object arg0)
      throws LogoException {
    if (arg0 instanceof LogoList) {
      LogoList list = (LogoList) arg0;
      if (list.isEmpty()) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.emptyListInput", displayName()));
      }
      return list.butFirst();
    } else if (arg0 instanceof String) {
      String string = (String) arg0;
      if (string.length() == 0) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.emptyStringInput", token().name()));
View Full Code Here

  @Override
  public Object report(final Context context) throws LogoException {
    // part 1: get arguments, context.checked validity
    AgentSet sourceSet = argEvalAgentSet(context, 0);
    List<Agent> result = new ArrayList<Agent>();
    LogoList points = argEvalList(context, 1);
    for (Iterator<Object> it = points.iterator(); it.hasNext();) {
      if (!validateListEntry(it.next())) {
        throw new EngineException(context, this, I18N.errorsJ().getN(
            "org.nlogo.prim.etc._atpoints.invalidListOfPoints", Dump.logoObject(points)));
      }
    }
View Full Code Here

            world);
  }

  private boolean validateListEntry(Object entry) {
    if (entry instanceof LogoList) {
      LogoList entryList = (LogoList) entry;
      if (entryList.size() == 2 ||
          ((world.program().is3D())
              && (entryList.size() == 3))) {
        for (Iterator<Object> iter = entryList.iterator(); iter.hasNext();) {
          if (!(iter.next() instanceof Double)) {
            return false;
          }
        }
        return true;
View Full Code Here

    // predictable ordering so runs are reproducible - ST 8/13/03
    LinkedHashSet<Patch> result =
        new LinkedHashSet<Patch>();
    boolean is3D = world.program().is3D();
    for (Iterator<Object> it = points.iterator(); it.hasNext();) {
      LogoList entry = (LogoList) it.next();
      Double x = null;
      Double y = null;
      Double z = org.nlogo.agent.World.ZERO;
      int j = 0;
      for (Iterator<Object> it2 = entry.iterator(); it2.hasNext();) {
        switch (j) {
          case 0:
            x = (Double) it2.next();
            break;
          case 1:
View Full Code Here

TOP

Related Classes of org.nlogo.api.LogoList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.