Package org.nlogo.api

Examples of org.nlogo.api.LogoList


public final strictfp class _median
    extends Reporter
    implements org.nlogo.nvm.Pure {
  @Override
  public Object report(final Context context) throws LogoException {
    LogoList list = argEvalList(context, 0);
    int badElts = 0;
    List<Double> nums =
        new ArrayList<Double>(list.size());
    for (Object elt : list) {
      if (!(elt instanceof Double)) {
        ++badElts;
        continue;
      }
      nums.add((Double) elt);
    }
    int listSize = list.size();
    if (listSize == badElts) {
      throw new EngineException(context, this,
          I18N.errorsJ().getN("org.nlogo.prim.etc.median.cantFindMedianOfListWithNoNumbers", Dump.logoObject(list)));
    }
    Collections.sort(nums);
View Full Code Here


    implements Pure {
  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    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);
View Full Code Here

            Syntax.NumberType());
  }

  @Override
  public Object report(Context context) throws LogoException {
    LogoList list = argEvalList(context, 0);
    double winner = 0;
    Double boxedWinner = null;
    for (Object elt : list) {
      if (elt instanceof Double) {
        Double boxedValue = (Double) elt;
View Full Code Here

public final strictfp class _sublist
    extends Reporter
    implements org.nlogo.nvm.Pure {
  @Override
  public Object report(final org.nlogo.nvm.Context context) throws LogoException {
    LogoList list = argEvalList(context, 0);
    int start = argEvalIntValue(context, 1);
    int stop = argEvalIntValue(context, 2);
    int size = list.size();
    if (start < 0) {
      throw new EngineException
          (context, this, I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.startIsLessThanZero", start));
    } else if (stop < start) {
      throw new EngineException
          (context, this, I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.endIsLessThanStart", stop, start));

    } else if (stop > size) {
      throw new EngineException
          (context, this, I18N.errorsJ().getN("org.nlogo.prim.etc._sublist.endIsGreaterThanListSize", stop, size));
    }
    return list.logoSublist(start, stop);
  }
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.