001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/
004    
005    package graphlab.library.event;
006    
007    import graphlab.library.BaseEdge;
008    import graphlab.library.BaseGraph;
009    import graphlab.library.BaseVertex;
010    
011    /**
012     * Happens when a vertex's color changes or a new vertex
013     * is added to the graph or ...
014     *
015     * @author Omid Aladini
016     */
017    
018    //I know, I know, some might say, EdgeType is not needed here. 
019    //It's just for future vertex events dependent on edge type.
020    
021    public class VertexEvent<VertexType extends BaseVertex, EdgeType extends BaseEdge<VertexType>>
022            implements Event {
023        public final VertexType vertex;
024        public final BaseGraph<VertexType, EdgeType> graph;
025        public final EventType eventType;
026    
027        public static enum EventType {
028            COLOR_CHANGE,
029            NEW_VERTEX,
030            MARK
031        }
032    
033        /**
034         * Constructs an event that means an event is occured on a specified vertex.
035         *
036         * @param vertex The vertex which the event occurs on it.
037         * @param et     Type of the event occured on the first parameter <code>vertex</code>;
038         * @throws NullPointerException if <code>vertex</code> is null.
039         */
040        public VertexEvent(BaseGraph<VertexType, EdgeType> graph, VertexType vertex, EventType et) {
041            if (vertex == null || et == null || graph == null)
042                throw new NullPointerException("Null argument supplied.");
043    
044            this.vertex = vertex;
045            eventType = et;
046            this.graph = graph;
047        }
048    
049        /**
050         * Constructs an event that means a new vertex is added.
051         *
052         * @param vertex The vertex which the event occurs on it.
053         * @throws NullPointerException if <code>vertex</code> is null.
054         */
055        public VertexEvent(BaseGraph<VertexType, EdgeType> graph, VertexType vertex) {
056            this(graph, vertex, EventType.NEW_VERTEX);
057        }
058    
059        public String getID() {
060            return "VertexEvent";
061        }
062    
063        public String getDescription() {
064            return "VertexEvent occurred.";
065        }
066    
067        private String message;
068    
069        public String getMessage() {
070            return message;
071        }
072    
073        public void setMessage(String message) {
074            this.message = message;
075        }
076    }