Cases.java :  » Algebra » symja » org » matheclipse » core » reflection » system » Java Open Source

Java Open Source » Algebra » symja 
symja » org » matheclipse » core » reflection » system » Cases.java
package org.matheclipse.core.reflection.system;

import org.matheclipse.core.eval.interfaces.IFunctionEvaluator;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.core.interfaces.ISymbol;
import org.matheclipse.core.patternmatching.PatternMatcher;

public class Cases implements IFunctionEvaluator {

  public Cases() {
  }

  public IExpr evaluate(final IAST functionList) {
    if ((functionList.size() == 3) && (functionList.get(1) instanceof IAST)) {
      return cases((IAST) functionList.get(1), functionList.get(2));
    }
    return null;
  }

  public static IAST cases(final IAST list, final IExpr pattern) {
    final PatternMatcher matcher = new PatternMatcher(pattern);
    return list.filter(list.copyHead(), matcher);
  }

  public IExpr numericEval(final IAST functionList) {
    return evaluate(functionList);
  }

  public void setUp(final ISymbol symbol) {
  }

}
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.