CountValues.java :  » Scripting » Kawa » gnu » kawa » functions » Java Open Source

Java Open Source » Scripting » Kawa 
Kawa » gnu » kawa » functions » CountValues.java
// Copyright (c) 2001  Per M.A. Bothner and Brainfood Inc.
// This is free software;  for terms and warranty disclaimer see ./COPYING.

package gnu.kawa.functions;
import gnu.mapping.*;
import gnu.lists.Consumer;

/** Return the number of values in the argument. */

public class CountValues extends Procedure1
{
  public static final CountValues countValues = new CountValues();

  public static int countValues(Object arg)
  {
    return arg instanceof Values ? ((Values) arg).size() : 1;
  }

  public Object apply1(Object arg)
  {
    return gnu.math.IntNum.make(countValues(arg));
  }

  public void apply (CallContext ctx)
  {
    Consumer consumer = ctx.consumer;
    Object arg = ctx.getNextArg();
    ctx.lastArg();
    consumer.writeInt(countValues(arg));
  }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.