예제 #1
0
파일: _item.java 프로젝트: smbillah/NetLogo
 @Override
 public Object report(final org.nlogo.nvm.Context context) throws LogoException {
   int index = argEvalIntValue(context, 0);
   Object obj = args[1].report(context);
   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",
                   index,
                   Dump.logoObject(string),
                   string.length()));
     }
     return string.substring(index, index + 1);
   } else {
     throw new ArgumentTypeException(
         context, this, 1, Syntax.ListType() | Syntax.StringType(), obj);
   }
 }
예제 #2
0
 public double report_1(Context context, AgentSet sourceSet, Reporter block) throws LogoException {
   block.checkAgentSetClass(sourceSet, context);
   Context freshContext = new Context(context, sourceSet);
   int result = 0;
   for (AgentSet.Iterator iter = sourceSet.iterator(); iter.hasNext(); ) {
     Agent tester = iter.next();
     Object value = freshContext.evaluateReporter(tester, block);
     if (!(value instanceof Boolean)) {
       throw new EngineException(
           context,
           this,
           I18N.errorsJ()
               .getN(
                   "org.nlogo.prim.$common.expectedBooleanValue",
                   displayName(),
                   Dump.logoObject(tester),
                   Dump.logoObject(value)));
     }
     if (((Boolean) value).booleanValue()) {
       result++;
     }
   }
   return result;
 }
예제 #3
0
파일: _max.java 프로젝트: hnoble64/NetLogo
 @Override
 public Object report(Context context) {
   LogoList list = argEvalList(context, 0);
   double winner = 0;
   Double boxedWinner = null;
   for (Object elt : list) {
     if (elt instanceof Double) {
       Double boxedValue = (Double) elt;
       double value = boxedValue.doubleValue();
       if (boxedWinner == null || value > winner) {
         winner = value;
         boxedWinner = boxedValue;
       }
     }
   }
   if (boxedWinner == null) {
     throw new EngineException(
         context,
         this,
         I18N.errorsJ()
             .getN("org.nlogo.prim._max.cantFindMaxOfListWithNoNumbers", Dump.logoObject(list)));
   }
   return boxedWinner;
 }