AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
AbstractEdge.java
Go to the documentation of this file.
1package aud.graph;
2
5
11public abstract class AbstractEdge
12 implements Comparable<AbstractEdge>, GraphvizDecorable {
13
15 AbstractNode src_ = null;
16 AbstractNode dst_ = null;
17
23 public abstract AbstractEdge create();
24
27 return graph_;
28 }
35 public AbstractNode source() { return src_; }
39 public AbstractNode destination() { return dst_; }
40
42 public boolean hasWeight() { return !Double.isNaN(getWeight()); }
47 public double getWeight() { return Double.NaN; }
52 public void setWeight(double w) {
53 throw new UnsupportedOperationException("'setWeight' undefined");
54 }
55
57 public String getLabel() {
58 if (hasWeight()) {
59 double w=getWeight();
60 if (w==Math.floor(w)) // missing proper sprintf, Java's formatting sucks!
61 return ""+((int) getWeight());
62 else
63 return ""+w;
64 }
65 else
66 return null;
67
68 //return hasWeight() ? ""+getWeight() : (String) null;
69 }
70
71 @Override public GraphvizDecorator getDecorator() {
72 return graph_.getDecorator();
73 }
74
75 @Override public String toString() {
76 String text=getLabel();
77 return src_.toString()+
78 (graph_.isDirected() ? " ->" : " --")+
79 (text!=null ? "["+text+"] " : " ")+
80 dst_.toString();
81 }
82
83 @Override public int compareTo(AbstractEdge other) {
84 if (graph_!=other.graph_)
85 throw new UnsupportedOperationException();
86 int c=src_.compareTo(other.src_);
87 return c!=0 ? c : dst_.compareTo(other.dst_);
88 }
89 @Override public boolean equals(Object other) {
90 return compareTo((AbstractEdge) other)==0;
91 }
92}
Interface to edges of a graph.
AbstractNode source()
Get source node.
GraphvizDecorator getDecorator()
get decoration or null
String getLabel()
get text description or null if there is none
abstract AbstractEdge create()
Create new edge instance.
void setWeight(double w)
set weight
boolean hasWeight()
determine if edge weight is defined
int compareTo(AbstractEdge other)
AbstractGraph<? extends AbstractNode,? extends AbstractEdge > graph()
get graph
AbstractNode destination()
get destination node
double getWeight()
set edge weight
boolean equals(Object other)
Interface to a graph.
GraphvizDecorator getDecorator()
get decoration or null
abstract boolean isDirected()
Is graph directed?
Interface to nodes of a graph.
int compareTo(AbstractNode other)
Decorator for items of Graphvizable objects.
Interface for decorating items of Graphvizable objects.
utilities (not related to AuD lecture)
Definition: Colormap.java:1
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1