Пример #1
0
  /**
   * Helper method to generate the signatures for binding the factory. Must account for the
   * inheritance relationships for any arguments that are classes. Ths, each argument can
   * potentially result in a range of values for type, and we have to handle the cross product of
   * all of these.
   */
  private static Vector makeFactoryNames(IXMLElement constructor) {
    String factoryName = XMLUtil.nameOf(constructor.getParent());
    Vector allPermutations = new Vector();
    for (Enumeration e = constructor.enumerateChildren(); e.hasMoreElements(); ) {
      IXMLElement element = (IXMLElement) e.nextElement();

      if (!element.getName().equals("arg")) {
        break;
      }

      String argType = XMLUtil.typeOf(element);
      Vector argTypeAlternates = new Vector();
      argTypeAlternates.add(argType);

      if (ModelAccessor.isClass(argType)) {
        List ancestors = ModelAccessor.getAncestors(argType);
        if (ancestors != null) argTypeAlternates.addAll(ancestors);
      }

      allPermutations.add(argTypeAlternates);
    }

    // Generate all the signatures
    Vector factoryNames = new Vector();
    makeFactoryNames(factoryName, allPermutations, 0, factoryNames);
    return factoryNames;
  }
 /** INTERNAL: Return all the fields */
 public Vector getFields() {
   if (isAttribute()) {
     Vector result = new Vector(1);
     DatabaseField field = getField();
     if (field != null) {
       result.addElement(field);
     }
     return result;
   } else {
     Vector result = new Vector();
     result.addAll(super.getFields());
     if (mapping.isCollectionMapping()) {
       List<DatabaseField> fields =
           mapping.getContainerPolicy().getAllFieldsForMapKey((CollectionMapping) mapping);
       if (fields != null) {
         result.addAll(fields);
       }
     }
     return result;
   }
 }
Пример #3
0
  public static void main(String[] args) throws Exception {
    int V, E, s, a, b, w;

    File f = new File("in_06.txt");
    Scanner sc = new Scanner(f);

    V = sc.nextInt();
    E = sc.nextInt();
    s = sc.nextInt();

    AdjList.clear();
    for (int i = 0; i < V; i++) {
      Vector<IntegerPair> Neighbor = new Vector<IntegerPair>();
      AdjList.add(Neighbor); // add neighbor list to Adjacency List
    }

    for (int i = 0; i < E; i++) {
      a = sc.nextInt();
      b = sc.nextInt();
      w = sc.nextInt();
      AdjList.get(a).add(new IntegerPair(b, w)); // first time using weight
    }

    // as an example, we start from this source (see Figure 1.15)
    Vector<Integer> dist = new Vector<Integer>();
    dist.addAll(Collections.nCopies(V, INF));
    dist.set(s, 0);

    // Bellman Ford routine
    for (int i = 0; i < V - 1; i++) // relax all E edges V-1 times, O(V)
    for (int u = 0; u < V; u++) { // these two loops = O(E)
        Iterator it = AdjList.get(u).iterator();
        while (it.hasNext()) { // relax these edges
          IntegerPair v = (IntegerPair) it.next();
          dist.set(v.first(), Math.min(dist.get(v.first()), dist.get(u) + v.second()));
        }
      }

    boolean negative_cycle_exist = false;
    for (int u = 0; u < V; u++) { // one more pass to check
      Iterator it = AdjList.get(u).iterator();
      while (it.hasNext()) { // relax these edges
        IntegerPair v = (IntegerPair) it.next();
        if (dist.get(v.first()) > dist.get(u) + v.second()) // should be false, but if possible
        negative_cycle_exist = true; // then negative cycle exists!
      }
    }
    System.out.printf("Negative Cycle Exist? %s\n", negative_cycle_exist ? "Yes" : "No");

    if (!negative_cycle_exist)
      for (int i = 0; i < V; i++) System.out.printf("SSSP(%d, %d) = %d\n", s, i, dist.get(i));
  }
  /**
   * get region
   *
   * @param lockRegionData the intial lock-region-data Node
   * @return region
   */
  public RegionInfo getLockRegion(LockRegionData lockRegionData) {
    JavaRegion javaRegion = lockRegionData.getJavaRegion();
    int regionBegin = javaRegion.getBeginOffset().intValue();
    int length = javaRegion.getLength().intValue();
    int regionEnd = regionBegin + length;
    CollabLineRegion[] cLineRegionList = getCollabLineRegion(lockRegionData);
    Vector cLineRegions = new Vector();
    cLineRegions.addAll(Arrays.asList(cLineRegionList));
    RegionInfo regionInfo =
        new RegionInfo(
            javaRegion.getRegionName(),
            getName(),
            getFileGroupName(),
            RegionInfo.CHAROFFSET_RANGE,
            regionBegin,
            regionEnd,
            0,
            cLineRegions);

    return regionInfo;
  }
Пример #5
0
  public static void main(String[] args) throws Exception {
    /*
    // Graph in Figure 4.3, format: list of unweighted edges
    // This example shows another form of reading graph input
    13 16
    0 1    1 2    2  3   0  4   1  5   2  6    3  7   5  6
    4 8    8 9    5 10   6 11   7 12   9 10   10 11  11 12
    */

    File f = new File("in_04.txt");
    Scanner sc = new Scanner(f);

    V = sc.nextInt();
    E = sc.nextInt();

    AdjList.clear();
    for (int i = 0; i < V; i++) {
      Vector<IntegerPair> Neighbor = new Vector<IntegerPair>();
      AdjList.add(Neighbor); // add neighbor list to Adjacency List
    }

    for (int i = 0; i < E; i++) {
      a = sc.nextInt();
      b = sc.nextInt();
      AdjList.get(a).add(new IntegerPair(b, 0));
      AdjList.get(b).add(new IntegerPair(a, 0));
    }

    // as an example, we start from this source, see Figure 4.3
    s = 5;

    // BFS routine
    // inside void main(String[] args) -- we do not use recursion, thus we do not need to create
    // separate function!
    Vector<Integer> dist = new Vector<Integer>();
    dist.addAll(Collections.nCopies(V, 1000000000));
    dist.set(s, 0); // start from source
    Queue<Integer> q = new LinkedList<Integer>();
    q.offer(s);
    p.clear();
    p.addAll(
        Collections.nCopies(V, -1)); // to store parent information (p must be a global variable!)
    int layer = -1; // for our output printing purpose
    Boolean isBipartite = true;

    while (!q.isEmpty()) {
      int u = q.poll(); // queue: layer by layer!
      if (dist.get(u) != layer) System.out.printf("\nLayer %d:", dist.get(u));
      layer = dist.get(u);
      System.out.printf(", visit %d", u);
      Iterator it = AdjList.get(u).iterator();
      while (it.hasNext()) { // for each neighbours of u
        IntegerPair v = (IntegerPair) it.next();
        if (dist.get(v.first()) == 1000000000) { // if v not visited before
          dist.set(v.first(), dist.get(u) + 1); // then v is reachable from u
          q.offer(v.first()); // enqueue v for next steps
          p.set(v.first(), u); // parent of v is u
        } else if ((dist.get(v.first()) % 2) == (dist.get(u) % 2)) // same parity
        isBipartite = false;
      }
    }

    System.out.printf("\nShortest path: ");
    printpath(7);
    System.out.printf("\n");
    System.out.printf("isBipartite? %d\n", isBipartite ? 1 : 0);
  }
Пример #6
0
  /**
   * Create the array of arguments to pass to rhino engine. It looks something like this: -modules
   * <jsdoc.home>/node_modules -modules <jsdoc.home>/rhino_modules \ -modules <jsdoc.home>
   * <jsdoc.home>/jsdoc.js --dirname=<jsdoc.home> \ <options> <sourcefiles|sourcedirs>
   *
   * @return a string[] of commands to pass to the rhino engine
   */
  private String[] createArguments() throws BuildException {
    Vector<String> arguments = new Vector<String>();

    // return if certain attributes are not present
    if ((jsDocHome == null)) {
      throw new BuildException("jsdochome must be specified");
    }

    // add the modules folders
    arguments.add("-modules");
    arguments.add(jsDocHome + "/node_modules");
    arguments.add("-modules");

    if (new File(jsDocHome + "/rhino").exists()) {
      arguments.add(jsDocHome + "/rhino");
    } else {
      arguments.add(jsDocHome + "/rhino_modules");
    }

    arguments.add("-modules");
    arguments.add(jsDocHome + "/lib");
    arguments.add("-modules");
    arguments.add(jsDocHome);

    // add the main jsodc js
    arguments.add(jsDocHome + "/jsdoc.js");

    // add the dirname
    arguments.add("--dirname=" + jsDocHome);

    addOptionalArgument(arguments, template, "-t"); // add the template
    addOptionalArgument(arguments, toDir, "-d"); // add the output dir
    addOptionalArgument(arguments, encoding, "-e"); // the encoding to use
    addOptionalArgument(arguments, config, "-c"); // the config file to use
    addOptionalArgument(arguments, tutorials, "-u"); // the tutorials dir
    addOptionalBooleanArgument(arguments, isIncludingPrivate, "-p");
    addOptionalBooleanArgument(arguments, isRecursive, "-r");

    if (inputFile != null) {
      arguments.add(inputFile);
    } else if (inputDir != null) {
      arguments.add(inputDir);
    } else if (fileSets.size() != 0 || fileLists.size() != 0) {
      // Loop through fileSets
      for (int i = 0, l = fileSets.size(); i < l; i++) {
        FileSet fs = fileSets.elementAt(i);
        // Ummm....?
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        // Get base directory from fileset
        File dir = ds.getBasedir();
        // Get included files from fileset
        String[] srcs = ds.getIncludedFiles();
        // Loop through files
        for (int j = 0; j < srcs.length; j++) {
          // Make file object from base directory and filename
          File temp = new File(dir, srcs[j]);
          // Call the JSMin class with this file
          arguments.add(temp.getAbsolutePath());
        }
      }
      // Loop through fileLists
      for (int i = 0; i < fileLists.size(); i++) {
        FileList fs = fileLists.elementAt(i);
        // Get included files from filelist
        String[] srcs = fs.getFiles(getProject());
        // Get base directory from filelist
        File dir = fs.getDir(getProject());
        // Loop through files
        for (int j = 0; j < srcs.length; j++) {
          // Make file object from base directory and filename
          File temp = new File(dir, srcs[j]);
          // Call the JSMin class with this file
          arguments.add(temp.getAbsolutePath());
        }
      }
    } else {
      throw new BuildException(
          "No inputs specified.  Task requires 'file' attribute OR 'dir' attribute OR nested filesets");
    }
    if (args.size() != 0) {
      for (int i = 0, l = args.size(); i < l; i++) {
        arguments.addAll(Arrays.asList(args.elementAt(i).getParts()));
      }
    }
    return arguments.toArray(new String[0]);
  }