package edu.neu.ccs.demeter.dj;

import edu.neu.ccs.demeter.aplib.*;

import java.io.*;
import java.util.*;

/**
 * A strategy determining a set of paths through a class graph or a
 * slice of an object graph.
 */
public class Strategy extends edu.neu.ccs.demeter.aplib.sg.Strategy {
  /** Parse a strategy expression from a char stream. */
  public Strategy(Reader in)
    throws StrategyParseException
  {
    this(in, new HashMap());
  }
  /** Parse a strategy expression from a string. */
  public Strategy(String s)
    throws StrategyParseException
  {
    this(s, new HashMap());
  }
  /**
   * Parse a strategy expression from a char stream.
   * Strategy references are resolved by looking them up in the
   * provided environent.
   */
  public Strategy(Reader in, Map env)
    throws StrategyParseException
  {
    try {
      strategy = readFrom(in, env);
    } catch (edu.neu.ccs.demeter.aplib.sg.ParseException e) {
      throw new StrategyParseException(e.getMessage());
    }
  }
  /**
   * Parse a strategy expression from a string.
   * Strategy references are resolved by looking them up in the
   * provided environent.
   */
  public Strategy(String s, Map env)
    throws StrategyParseException
  {
    try {
      strategy = fromString(s, env);
    } catch (RuntimeException e) {
      throw new StrategyParseException(e.getMessage());
    }
  }

  /** The DJ version string. */
  public static String getVersion() { return ClassGraph.getVersion(); }

  edu.neu.ccs.demeter.aplib.sg.Strategy strategy;
  public boolean isSimpleStrategy() {
    return strategy.isSimpleStrategy();
  }
  public SimpleStrategyI toSimpleStrategy() {
    return strategy.toSimpleStrategy();
  }
  public boolean isStrategyCombination() {
    return strategy.isStrategyCombination();
  }
  public StrategyCombinationI toStrategyCombination() {
    return strategy.toStrategyCombination();
  }

  /**
   * An unmodifiable set of symbolic names that the source nodes in
   * the strategy graph map to, or null if the strategy can start at
   * any class graph node.
   */
  public Set getSourceNames() {
    return strategy.getSourceNames();
  }
  /**
   * An unmodifiable set of symbolic names that the target nodes in
   * the strategy graph map to, or null if the strategy can finish at
   * any class graph node.
   */
  public Set getTargetNames() {
    return strategy.getTargetNames();
  }

  public String toString() {
    return strategy.toString();
  }
}
