summaryrefslogtreecommitdiff
path: root/tool/src/org/antlr/v4/misc/Graph.java
diff options
context:
space:
mode:
Diffstat (limited to 'tool/src/org/antlr/v4/misc/Graph.java')
-rw-r--r--tool/src/org/antlr/v4/misc/Graph.java41
1 files changed, 10 insertions, 31 deletions
diff --git a/tool/src/org/antlr/v4/misc/Graph.java b/tool/src/org/antlr/v4/misc/Graph.java
index a7c63d5..ec4c147 100644
--- a/tool/src/org/antlr/v4/misc/Graph.java
+++ b/tool/src/org/antlr/v4/misc/Graph.java
@@ -1,37 +1,14 @@
/*
- * [The "BSD license"]
- * Copyright (c) 2012 Terence Parr
- * Copyright (c) 2012 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.misc;
import org.antlr.v4.runtime.misc.OrderedHashSet;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -44,13 +21,15 @@ import java.util.Set;
public class Graph<T> {
public static class Node<T> {
- T payload;
- List<Node<T>> edges; // points at which nodes?
+ public T payload;
+
+ @SuppressWarnings("unchecked")
+ public List<Node<T>> edges = Collections.EMPTY_LIST; // points at which nodes?
public Node(T payload) { this.payload = payload; }
public void addEdge(Node<T> n) {
- if ( edges==null ) edges = new ArrayList<Node<T>>();
+ if ( edges==Collections.EMPTY_LIST ) edges = new ArrayList<Node<T>>();
if ( !edges.contains(n) ) edges.add(n);
}
@@ -68,7 +47,7 @@ public class Graph<T> {
a_node.addEdge(b_node);
}
- protected Node<T> getNode(T a) {
+ public Node<T> getNode(T a) {
Node<T> existing = nodes.get(a);
if ( existing!=null ) return existing;
Node<T> n = new Node<T>(a);