KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > ltl > graph > Label


1
2 //
3
// Copyright (C) 2005 United States Government as represented by the
4
// Administrator of the National Aeronautics and Space Administration
5
// (NASA). All Rights Reserved.
6
//
7
// This software is distributed under the NASA Open Source Agreement
8
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
9
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
10
// directory tree for the complete NOSA document.
11
//
12
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
13
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
14
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
15
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
16
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
17
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
18
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
19
//
20
package gov.nasa.ltl.graph;
21
22 import java.io.IOException JavaDoc;
23
24
25 /**
26  * DOCUMENT ME!
27  */

28 public class Label {
29   public static Graph label (Graph g) {
30     String JavaDoc type = g.getStringAttribute("type");
31     String JavaDoc ac = g.getStringAttribute("ac");
32
33     if (type.equals("gba")) {
34       if (ac.equals("nodes")) {
35         final int nsets = g.getIntAttribute("nsets");
36
37         g.forAllNodes(new EmptyVisitor() {
38           public void visitNode (Node n) {
39             n.forAllEdges(new EmptyVisitor() {
40               public void visitEdge (Edge e) {
41                 Node n1 = e.getSource();
42
43                 for (int i = 0; i < nsets; i++) {
44                   if (n1.getBooleanAttribute("acc" + i)) {
45                     e.setBooleanAttribute("acc" + i, true);
46                   }
47                 }
48               }
49             });
50
51             for (int i = 0; i < nsets; i++) {
52               n.setBooleanAttribute("acc" + i, false);
53             }
54           }
55         });
56       }
57
58       g.setStringAttribute("ac", "edges");
59     } else {
60       throw new RuntimeException JavaDoc("invalid graph type: " + type);
61     }
62
63     return g;
64   }
65
66   public static void main (String JavaDoc[] args) {
67     try {
68       Graph g = Graph.load(args[0]);
69       label(g);
70       g.save();
71     } catch (IOException JavaDoc e) {
72       System.err.println("Can't load file: " + args[0]);
73       System.exit(1);
74     }
75   }
76 }
Popular Tags