Package org.nlogo.api

Examples of org.nlogo.api.LogoList


    if (index < 0) {
      throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.prim.etc.$common.negativeIndex", index));
    }
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      if (index >= list.size()) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.indexExceedsListSize",
                index, Dump.logoObject(list), list.size()));
      }
      return list.get(index);
    } else if (obj instanceof String) {
      String string = (String) obj;
      if (index >= string.length()) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.indexExceedsListSize",
View Full Code Here


      throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.prim.etc.$common.firstInputCantBeNegative", displayName()));
    }
    Object obj = args[1].report(context);
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      if (n > list.size()) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.requestMoreItemsThanInList", n, list.size()));
      }
      if (n == list.size()) {
        return list;
      }
      return randomSubset(list, n, context.job.random);
    } else if (obj instanceof AgentSet) {
      AgentSet agents = (AgentSet) obj;
View Full Code Here

  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    Object value = args[0].report(context);
    Object obj = args[1].report(context);
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      LogoListBuilder listCopy = new LogoListBuilder();
      for (Iterator<Object> it = list.iterator(); it.hasNext();) {
        Object elt = it.next();
        if (!Equality.equals(value, elt)) {
          listCopy.add(elt);
        }
      }
View Full Code Here

    return report_1(context, args[0].report(context));
  }

  public LogoList report_1(Context context, Object obj) throws LogoException {
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      if (list.size() != 3) {
        throw new org.nlogo.nvm.EngineException
            (context, this, displayName() + " an rgb list must have 3 elements");
      }
      try {
        int argb = java.awt.Color.HSBtoRGB
            (StrictMath.max(0, StrictMath.min(255, ((Double) list.get(0)).intValue())) / 255,
                StrictMath.max(0, StrictMath.min(255, ((Double) list.get(1)).intValue())) / 255,
                StrictMath.max(0, StrictMath.min(255, ((Double) list.get(2)).intValue())) / 255);
        LogoListBuilder hsbList = new LogoListBuilder();
        hsbList.add(Double.valueOf((argb >> 16) & 0xff));
        hsbList.add(Double.valueOf((argb >> 8) & 0xff));
        hsbList.add(Double.valueOf(argb & 0xff));
        return hsbList.toLogoList();
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.butLast();
    } 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

    if (index < 0) {
      throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.prim.etc.$common.negativeIndex", index));
    }
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      if (index >= list.size()) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.indexExceedsListSize",
                index, Dump.logoObject(list), list.size()));
      }
      return list.removeItem(index);
    } else if (obj instanceof String) {
      String string = (String) obj;
      if (index >= string.length()) {
        throw new EngineException(context, this,
            I18N.errorsJ().getN("org.nlogo.prim.etc.$common.indexExceedsStringSize",
View Full Code Here

  }

  public Object report_1(final org.nlogo.nvm.Context context, Object obj)
      throws LogoException {
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      if (list.isEmpty()) {
        throw new EngineException(context, this, I18N.errorsJ().get("org.nlogo.prim.etc.$common.emptyList"));
      }
      return list.first();
    } else if (obj instanceof String) {
      String string = (String) obj;
      if (string.length() == 0) {
        throw new EngineException(context, this, I18N.errorsJ().get("org.nlogo.prim.etc.$common.emptyString"));
      }
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;
      int i = 0;
      for (Iterator<Object> it = list.iterator(); it.hasNext();) {
        if (Equality.equals(value, it.next())) {
          return Double.valueOf(i);
        }
        i++;
      }
View Full Code Here

    implements org.nlogo.nvm.Pure {
  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    Object obj = args[0].report(context);
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      return list.isEmpty() ? Boolean.TRUE : Boolean.FALSE;
    } else if (obj instanceof String) {
      String string = (String) obj;
      return (string.length() == 0) ? Boolean.TRUE : Boolean.FALSE;
    } else {
      throw new ArgumentTypeException(context, this, 0, Syntax.ListType() | Syntax.StringType(), obj);
View Full Code Here

  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    Object obj = args[0].report(context);
    if (obj instanceof LogoList) {
      LogoList list = (LogoList) obj;
      if (list.size() == 0) {
        throw new EngineException(context, this, I18N.errorsJ().get("org.nlogo.prim.etc.$common.emptyList"));
      }
      return list.get(list.size() - 1);
    } else if (obj instanceof String) {
      String string = (String) obj;
      if (string.length() == 0) {
        throw new EngineException(context, this, I18N.errorsJ().get("org.nlogo.prim.etc.$common.emptyString"));
      }
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.