aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/uk/ac/ox/cs/pagoda/summary/Node.java
blob: 6fca4bb813b0631268a83fab9e5aca6fa91dae18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package uk.ac.ox.cs.pagoda.summary;

import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;

public class Node {

	String name; 
	Collection<String> concepts = new TreeSet<String>();
	private String label; 
	
	public Node(String nodeName) {
		name = nodeName; 
	}
	
	public String getName() { return name; }
	
	public void addConcept(String className) {
		concepts.add(className);
		label = null; 
	}
	
	public String getLabel() {
		if (label == null) {
			StringBuilder sb = null; 
			for (Iterator<String> it = concepts.iterator(); it.hasNext(); ) {
				if (sb == null)	sb = new StringBuilder(); 
				else sb.append("^");
				sb.append(it.next()); 				
			}
			label = sb == null ? "" : sb.toString(); 
		}
		return label; 
	}
	
	//TODO to be removed (just used for debug) ... 
	String simplifiedLabel = null;
	
	public String toString() {
		if (simplifiedLabel == null)
			simplifiedLabel = getLabel(); 
		return name  + "@" + simplifiedLabel; 
	}

	public boolean isSubConceptOf(Node v) {
		String s, t = ""; 
		for (Iterator<String> uIter = concepts.iterator(), vIter = v.concepts.iterator(); uIter.hasNext(); ) {
			s = uIter.next();
			if (!vIter.hasNext()) return false; 
			while (vIter.hasNext() && !s.equals(t = vIter.next()));
			if (!s.equals(t)) return false; 
		}
		return true;
	}

	public Collection<String> getConcepts() {
		return concepts; 
	}

}